From c396ba8ae9a046428e86fad283ba2d97ad7433c6 Mon Sep 17 00:00:00 2001 From: Kharec Date: Fri, 19 Dec 2025 12:51:25 +0100 Subject: [PATCH] feat: create repost undoing module --- skywipe/reposts.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 skywipe/reposts.py diff --git a/skywipe/reposts.py b/skywipe/reposts.py new file mode 100644 index 0000000..e4e1727 --- /dev/null +++ b/skywipe/reposts.py @@ -0,0 +1,69 @@ +"""Repost undoing module for Skywipe""" + +import time +from atproto import models +from .auth import Auth +from .configure import Configuration + + +REPOST_COLLECTION = "app.bsky.feed.repost" + + +def undo_reposts(): + auth = Auth() + client = auth.login() + config = Configuration() + config_data = config.load() + + batch_size = config_data.get("batch_size", 10) + delay = config_data.get("delay", 1) + verbose = config_data.get("verbose", False) + + if verbose: + print( + f"Starting repost deletion with batch_size={batch_size}, delay={delay}s") + + did = client.me.did + cursor = None + total_undone = 0 + + while True: + list_params = models.ComAtprotoRepoListRecords.Params( + repo=did, + collection=REPOST_COLLECTION, + limit=batch_size, + cursor=cursor + ) + + response = client.com.atproto.repo.list_records(params=list_params) + + records = response.records + if not records: + break + + for record in records: + try: + record_uri = record.uri + rkey = record_uri.rsplit("/", 1)[-1] + delete_data = { + "repo": did, + "collection": REPOST_COLLECTION, + "rkey": rkey + } + client.com.atproto.repo.delete_record(data=delete_data) + total_undone += 1 + if verbose: + print(f"Undone repost: {record_uri}") + except Exception as e: + record_uri = getattr(record, "uri", "unknown") + if verbose: + print(f"Error undoing repost {record_uri}: {e}") + + cursor = response.cursor + if not cursor: + break + + if delay > 0: + time.sleep(delay) + + print(f"Undone {total_undone} reposts.")