From c2aab71955c76c4014be78403e59d2b2fcbeee44 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sat, 20 Dec 2025 20:56:22 +0100 Subject: [PATCH] refactor: add basestrategy and make all class inherits to get rid of get_cursor() --- skywipe/operations.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/skywipe/operations.py b/skywipe/operations.py index 5768e42..113b589 100644 --- a/skywipe/operations.py +++ b/skywipe/operations.py @@ -21,7 +21,12 @@ class OperationContext: self.did = self.client.me.did -class RecordDeletionStrategy: +class BaseStrategy: + def get_cursor(self, response): + return response.cursor + + +class RecordDeletionStrategy(BaseStrategy): def __init__(self, collection: str): self.collection = collection @@ -37,9 +42,6 @@ class RecordDeletionStrategy: def extract_items(self, response): return response.records - def get_cursor(self, response): - return response.cursor - def process_item(self, record, context: OperationContext): record_uri = record.uri rkey = record_uri.rsplit("/", 1)[-1] @@ -52,7 +54,7 @@ class RecordDeletionStrategy: context.logger.debug(f"Deleted: {record_uri}") -class FeedStrategy: +class FeedStrategy(BaseStrategy): def fetch(self, context: OperationContext, cursor: Optional[str] = None): if cursor: return context.client.get_author_feed( @@ -63,16 +65,13 @@ class FeedStrategy: def extract_items(self, response): return response.feed - def get_cursor(self, response): - return response.cursor - def process_item(self, post, context: OperationContext): uri = post.post.uri context.client.delete_post(uri) context.logger.debug(f"Deleted post: {uri}") -class BookmarkStrategy: +class BookmarkStrategy(BaseStrategy): def fetch(self, context: OperationContext, cursor: Optional[str] = None): get_params = models.AppBskyBookmarkGetBookmarks.Params( limit=context.batch_size, @@ -83,9 +82,6 @@ class BookmarkStrategy: def extract_items(self, response): return response.bookmarks - def get_cursor(self, response): - return response.cursor - def process_item(self, bookmark, context: OperationContext): bookmark_uri = self._extract_bookmark_uri(bookmark) if not bookmark_uri: