Compare commits
60 Commits
3eac53346f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 590cc03ba4 | |||
| c493a99860 | |||
| 3f9ef6527f | |||
| f53e5bb527 | |||
| f2854a0df5 | |||
| defd991006 | |||
| f922e3cf9d | |||
| 06d70edaf1 | |||
| 58ab6cfafa | |||
| dba06e642a | |||
| 5868c1649b | |||
| a14184cddc | |||
| 6587f8c39c | |||
| ae6663572c | |||
| 3eb456e999 | |||
| cfa5773e62 | |||
| ddee2a6029 | |||
| 5e2b4f3408 | |||
| c238278df6 | |||
| a9c25c8c10 | |||
| 5ff25b3eb6 | |||
| c396ba8ae9 | |||
| d12f14a994 | |||
| a4b622bfd3 | |||
| 005c76119f | |||
| b1e2b266f4 | |||
| 6475a117e7 | |||
| 28a193078a | |||
| 07bbe88784 | |||
| 59554f6f17 | |||
| 02f609d829 | |||
| c8df3d0460 | |||
| 5afee97259 | |||
| ebbcbeeaa7 | |||
| 044ec67aa3 | |||
| e871d19a9f | |||
| 0ec562e0d2 | |||
| 276d177c4d | |||
| ed0076a34e | |||
| e99defc533 | |||
| 50288e9130 | |||
| c7ef63cc05 | |||
| 2395f60d11 | |||
| edba17e9a3 | |||
| e3da6c4f12 | |||
| debf55577d | |||
| 2efe83650b | |||
| 1c7a903131 | |||
| 472b828f72 | |||
| 8090a3432c | |||
| 8b406f5d4e | |||
| 053bb8696f | |||
| a31df05bb8 | |||
| e402e844c9 | |||
| 75d29a2c0d | |||
| 11f0bce116 | |||
| 6c424c6135 | |||
| 1b8eb4abd4 | |||
| 4d530a5a65 | |||
| ac21ad39b1 |
71
README.md
71
README.md
@@ -1,16 +1,16 @@
|
|||||||
# Skywipe
|
# Skywipe
|
||||||
|
|
||||||
Skywipe is a work-in-progress Python 3.13+ CLI that helps you wipe data from your Bluesky account using the AT Protocol.
|
Skywipe is a work-in-progress Python 3.13+ CLI that helps you wipe data from your Bluesky account using the AT Protocol SDK.
|
||||||
|
|
||||||
## Warning
|
**Warning:** This tool performs _**destructive operations**_.
|
||||||
|
|
||||||
This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account.
|
Only use it if you intend to permanently erase data from your Bluesky account.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
We're using [`uv`](https://github.com/astral-sh/uv) for dependency and virtual environment management.
|
Check [pyproject.toml](pyproject.toml).
|
||||||
|
|
||||||
You can setup the project (aka create a virtual environment and install dependencies) with :
|
You can use `uv` to install dependencies:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.kharec.info/Kharec/skywipe.git
|
git clone https://git.kharec.info/Kharec/skywipe.git
|
||||||
@@ -20,37 +20,31 @@ uv sync
|
|||||||
|
|
||||||
## How to run
|
## How to run
|
||||||
|
|
||||||
When installation will be worked out, you'll be able to :
|
|
||||||
|
|
||||||
```bash
|
|
||||||
skywipe all # target everything
|
|
||||||
skywipe configure # create configuration
|
|
||||||
skywipe posts # only posts
|
|
||||||
skywipe medias # only posts with medias
|
|
||||||
skywipe likes # only likes
|
|
||||||
skywipe reposts # only reposts
|
|
||||||
skywipe follows # only follows
|
|
||||||
```
|
|
||||||
|
|
||||||
While it's being developed, you can use the tool using `uv` :
|
While it's being developed, you can use the tool using `uv` :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
uv run main.py all # target everything
|
uv run python -m skywipe.cli all # target everything
|
||||||
uv run main.py configure # create configuration
|
uv run python -m skywipe.cli configure # create configuration
|
||||||
uv run main.py posts # only posts
|
uv run python -m skywipe.cli posts # delete posts
|
||||||
uv run main.py medias # only posts with medias
|
uv run python -m skywipe.cli medias # delete posts with medias
|
||||||
uv run main.py likes # only likes
|
uv run python -m skywipe.cli likes # undo likes
|
||||||
uv run main.py reposts # only reposts
|
uv run python -m skywipe.cli reposts # undo reposts
|
||||||
uv run main.py follows # only follows
|
uv run python -m skywipe.cli quotes # delete quotes
|
||||||
|
uv run python -m skywipe.cli follows # unfollow all
|
||||||
|
uv run python -m skywipe.cli bookmarks # delete bookmarks
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configuration
|
Use the `--yes` flag to skip the confirmation prompt and proceed with the operation.
|
||||||
|
|
||||||
|
A log of the operations will be saved in `~/.cache/skywipe/skywipe.log`.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
If you run the tool for the first time, it will prompt you to use `skywipe configure` to create the configuration file, which is located in `~/.config/skywipe/config.yml` :
|
If you run the tool for the first time, it will prompt you to use `skywipe configure` to create the configuration file, which is located in `~/.config/skywipe/config.yml` :
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
handle: your_handle
|
handle: your_handle
|
||||||
password: your_password_encrypted
|
password: your_password
|
||||||
batch_size: 10
|
batch_size: 10
|
||||||
delay: 1
|
delay: 1
|
||||||
verbose: true
|
verbose: true
|
||||||
@@ -60,17 +54,20 @@ BE SURE TO USE A [BLUESKY APP PASSWORD](https://blueskyfeeds.com/faq-app-passwor
|
|||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- [ ] build cli parameter management
|
- [x] build cli parameter management
|
||||||
- [ ] handle configuration logic
|
- [x] handle configuration logic
|
||||||
- [ ] sign in to at protocol
|
- [x] sign in to at protocol
|
||||||
- [ ] delete posts in groups
|
- [x] delete posts in batch
|
||||||
- [ ] only delete posts with media
|
- [x] only delete posts with media
|
||||||
- [ ] remove likes
|
- [x] undo likes
|
||||||
- [ ] remove reposts
|
- [x] undo reposts
|
||||||
- [ ] unfollow accounts
|
- [x] delete quotes
|
||||||
- [ ] make `all` run the other commands
|
- [x] unfollow accounts
|
||||||
- [ ] add simple progress and logging
|
- [x] remove bookmarks
|
||||||
- [ ] add safeguards like confirmations and clear dry-run info
|
- [x] make `all` run the other commands
|
||||||
|
- [x] add simple progress and logging
|
||||||
|
- [x] add safeguards (confirmation, dry-run flag)
|
||||||
|
- [ ] decent code architecture
|
||||||
- [ ] installation and run process
|
- [ ] installation and run process
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
66
main.py
66
main.py
@@ -1,66 +0,0 @@
|
|||||||
"""Main entry point for Skywipe"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from skywipe.commands import run_configure
|
|
||||||
from skywipe.configure import Configuration
|
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
|
||||||
"all": "target everything",
|
|
||||||
"configure": "create configuration",
|
|
||||||
"posts": "only posts",
|
|
||||||
"medias": "only posts with medias",
|
|
||||||
"likes": "only likes",
|
|
||||||
"reposts": "only reposts",
|
|
||||||
"follows": "only follows",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _create_parser():
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description="Clean your bluesky account with style.",
|
|
||||||
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
|
||||||
)
|
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(
|
|
||||||
dest="command",
|
|
||||||
help="Command to execute",
|
|
||||||
metavar="COMMAND",
|
|
||||||
required=True
|
|
||||||
)
|
|
||||||
|
|
||||||
for cmd, help_text in COMMANDS.items():
|
|
||||||
subparsers.add_parser(cmd, help=help_text)
|
|
||||||
|
|
||||||
return parser
|
|
||||||
|
|
||||||
|
|
||||||
def _check_config_required(command: str) -> bool:
|
|
||||||
return command != "configure"
|
|
||||||
|
|
||||||
|
|
||||||
def _require_config():
|
|
||||||
config = Configuration()
|
|
||||||
if not config.exists():
|
|
||||||
print("Error: Configuration file not found.")
|
|
||||||
print("You must run 'skywipe configure' first.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = _create_parser()
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if _check_config_required(args.command):
|
|
||||||
_require_config()
|
|
||||||
|
|
||||||
if args.command == "configure":
|
|
||||||
run_configure()
|
|
||||||
else:
|
|
||||||
print(f"Command '{args.command}' is not yet implemented.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "skywipe"
|
name = "skywipe"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Clean your bluesky account with style"
|
description = "Clean your bluesky account"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.13"
|
requires-python = ">=3.13"
|
||||||
dependencies = [
|
dependencies = ["atproto>=0.0.65", "pyyaml>=6.0"]
|
||||||
"atproto>=0.0.65",
|
|
||||||
"pyyaml>=6.0",
|
[project.scripts]
|
||||||
"cryptography>=42.0.0",
|
skywipe = "skywipe.cli:main"
|
||||||
]
|
|
||||||
|
|||||||
28
skywipe/auth.py
Normal file
28
skywipe/auth.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
"""Authentication module for Skywipe"""
|
||||||
|
|
||||||
|
from atproto import Client
|
||||||
|
from .configure import Configuration
|
||||||
|
|
||||||
|
|
||||||
|
class Auth:
|
||||||
|
def __init__(self):
|
||||||
|
self.config = Configuration()
|
||||||
|
self.client = None
|
||||||
|
|
||||||
|
def login(self) -> Client:
|
||||||
|
config_data = self.config.load()
|
||||||
|
|
||||||
|
handle = config_data.get("handle")
|
||||||
|
password = config_data.get("password")
|
||||||
|
|
||||||
|
if not handle or not password:
|
||||||
|
raise ValueError(
|
||||||
|
"handle and password must be set in configuration")
|
||||||
|
|
||||||
|
self.client = Client()
|
||||||
|
self.client.login(handle, password)
|
||||||
|
|
||||||
|
return self.client
|
||||||
|
|
||||||
|
def is_logged(self) -> bool:
|
||||||
|
return bool(getattr(self.client, "me", None))
|
||||||
78
skywipe/bookmarks.py
Normal file
78
skywipe/bookmarks.py
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
"""Bookmark deletion module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from atproto import models
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
def delete_bookmarks():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting bookmark deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
cursor = None
|
||||||
|
total_deleted = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Deleting bookmarks")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
get_params = models.AppBskyBookmarkGetBookmarks.Params(
|
||||||
|
limit=batch_size,
|
||||||
|
cursor=cursor
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.app.bsky.bookmark.get_bookmarks(params=get_params)
|
||||||
|
|
||||||
|
bookmarks = response.bookmarks
|
||||||
|
if not bookmarks:
|
||||||
|
break
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(bookmarks))
|
||||||
|
|
||||||
|
for bookmark in bookmarks:
|
||||||
|
try:
|
||||||
|
bookmark_uri = None
|
||||||
|
if hasattr(bookmark, "uri"):
|
||||||
|
bookmark_uri = bookmark.uri
|
||||||
|
else:
|
||||||
|
for attr_name in ("subject", "record", "post", "item"):
|
||||||
|
if hasattr(bookmark, attr_name):
|
||||||
|
nested = getattr(bookmark, attr_name)
|
||||||
|
if hasattr(nested, "uri"):
|
||||||
|
bookmark_uri = nested.uri
|
||||||
|
break
|
||||||
|
|
||||||
|
if not bookmark_uri:
|
||||||
|
logger.debug("Skipping bookmark: unable to find uri")
|
||||||
|
continue
|
||||||
|
|
||||||
|
delete_data = models.AppBskyBookmarkDeleteBookmark.Data(
|
||||||
|
uri=bookmark_uri
|
||||||
|
)
|
||||||
|
client.app.bsky.bookmark.delete_bookmark(data=delete_data)
|
||||||
|
total_deleted += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Deleted bookmark: {bookmark_uri}")
|
||||||
|
except Exception as e:
|
||||||
|
bookmark_uri = getattr(bookmark, "uri", "unknown")
|
||||||
|
logger.error(f"Error deleting bookmark {bookmark_uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Deleted {total_deleted} bookmarks.")
|
||||||
76
skywipe/cli.py
Normal file
76
skywipe/cli.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
"""Main entry point for Skywipe"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from .commands import registry
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import setup_logger
|
||||||
|
|
||||||
|
|
||||||
|
def create_parser():
|
||||||
|
commands = registry.get_all_commands()
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Clean your bluesky account with style.",
|
||||||
|
epilog="WARNING: This tool performs destructive operations. Only use it if you intend to erase data from your Bluesky account."
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--yes",
|
||||||
|
action="store_true",
|
||||||
|
help="Skip confirmation prompt and proceed with destructive operations"
|
||||||
|
)
|
||||||
|
|
||||||
|
subparsers = parser.add_subparsers(
|
||||||
|
dest="command",
|
||||||
|
help="Command to execute",
|
||||||
|
metavar="COMMAND",
|
||||||
|
required=True
|
||||||
|
)
|
||||||
|
|
||||||
|
for cmd, help_text in commands.items():
|
||||||
|
subparsers.add_parser(cmd, help=help_text)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def require_config():
|
||||||
|
config = Configuration()
|
||||||
|
if not config.exists():
|
||||||
|
logger = setup_logger(verbose=False)
|
||||||
|
logger.error("Configuration file not found.")
|
||||||
|
logger.error("You must run 'skywipe configure' first.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = create_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if registry.requires_config(args.command):
|
||||||
|
require_config()
|
||||||
|
config = Configuration()
|
||||||
|
config_data = config.load()
|
||||||
|
verbose = config_data.get("verbose", False)
|
||||||
|
log_file = Path.home() / ".cache" / "skywipe" / "skywipe.log"
|
||||||
|
setup_logger(verbose=verbose, log_file=log_file)
|
||||||
|
else:
|
||||||
|
setup_logger(verbose=False)
|
||||||
|
|
||||||
|
try:
|
||||||
|
registry.execute(
|
||||||
|
args.command, skip_confirmation=getattr(args, "yes", False))
|
||||||
|
except ValueError as e:
|
||||||
|
logger = setup_logger(verbose=False)
|
||||||
|
logger.error(f"{e}")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
logger = setup_logger(verbose=False)
|
||||||
|
logger.error(f"Unexpected error: {e}", exc_info=True)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,8 +1,130 @@
|
|||||||
"""Command implementations for Skywipe CLI."""
|
"""Command implementations for Skywipe"""
|
||||||
|
|
||||||
from skywipe.configure import Configuration
|
from typing import Callable, Dict, Optional
|
||||||
|
from .configure import Configuration
|
||||||
|
from .posts import delete_all_posts
|
||||||
|
from .medias import delete_posts_with_medias
|
||||||
|
from .likes import undo_likes
|
||||||
|
from .reposts import undo_reposts
|
||||||
|
from .quotes import delete_quotes_posts
|
||||||
|
from .follows import unfollow_all
|
||||||
|
from .bookmarks import delete_bookmarks
|
||||||
|
from .logger import get_logger
|
||||||
|
from .safeguard import require_confirmation
|
||||||
|
|
||||||
|
|
||||||
|
CommandHandler = Callable[..., None]
|
||||||
|
|
||||||
|
|
||||||
|
class CommandRegistry:
|
||||||
|
def __init__(self):
|
||||||
|
self._commands = {}
|
||||||
|
self._help_texts = {}
|
||||||
|
self._requires_config = {}
|
||||||
|
|
||||||
|
def register(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
handler: CommandHandler,
|
||||||
|
help_text: str,
|
||||||
|
requires_config: bool = True
|
||||||
|
):
|
||||||
|
self._commands[name] = handler
|
||||||
|
self._help_texts[name] = help_text
|
||||||
|
self._requires_config[name] = requires_config
|
||||||
|
|
||||||
|
def get_handler(self, name: str) -> Optional[CommandHandler]:
|
||||||
|
return self._commands.get(name)
|
||||||
|
|
||||||
|
def get_help_text(self, name: str) -> Optional[str]:
|
||||||
|
return self._help_texts.get(name)
|
||||||
|
|
||||||
|
def requires_config(self, name: str) -> bool:
|
||||||
|
return self._requires_config.get(name, True)
|
||||||
|
|
||||||
|
def get_all_commands(self) -> Dict[str, str]:
|
||||||
|
return self._help_texts.copy()
|
||||||
|
|
||||||
|
def execute(self, name: str, skip_confirmation: bool = False):
|
||||||
|
handler = self.get_handler(name)
|
||||||
|
if handler:
|
||||||
|
if name == "configure":
|
||||||
|
handler()
|
||||||
|
else:
|
||||||
|
handler(skip_confirmation)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknown command: {name}")
|
||||||
|
|
||||||
|
|
||||||
|
registry = CommandRegistry()
|
||||||
|
|
||||||
|
|
||||||
def run_configure():
|
def run_configure():
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
config.create()
|
config.create()
|
||||||
|
|
||||||
|
|
||||||
|
def run_posts(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all posts", skip_confirmation)
|
||||||
|
delete_all_posts()
|
||||||
|
|
||||||
|
|
||||||
|
def run_medias(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all posts with media", skip_confirmation)
|
||||||
|
delete_posts_with_medias()
|
||||||
|
|
||||||
|
|
||||||
|
def run_likes(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("undo all likes", skip_confirmation)
|
||||||
|
undo_likes()
|
||||||
|
|
||||||
|
|
||||||
|
def run_reposts(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("undo all reposts", skip_confirmation)
|
||||||
|
undo_reposts()
|
||||||
|
|
||||||
|
|
||||||
|
def run_quotes(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all quote posts", skip_confirmation)
|
||||||
|
delete_quotes_posts()
|
||||||
|
|
||||||
|
|
||||||
|
def run_follows(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("unfollow all accounts", skip_confirmation)
|
||||||
|
unfollow_all()
|
||||||
|
|
||||||
|
|
||||||
|
def run_bookmarks(skip_confirmation: bool = False):
|
||||||
|
require_confirmation("delete all bookmarks", skip_confirmation)
|
||||||
|
delete_bookmarks()
|
||||||
|
|
||||||
|
|
||||||
|
def run_all(skip_confirmation: bool = False):
|
||||||
|
logger = get_logger()
|
||||||
|
require_confirmation(
|
||||||
|
"run all cleanup commands (posts, likes, reposts, follows, bookmarks)", skip_confirmation)
|
||||||
|
|
||||||
|
commands = ["posts", "likes", "reposts", "follows", "bookmarks"]
|
||||||
|
|
||||||
|
logger.info("Running all cleanup commands...")
|
||||||
|
for cmd in commands:
|
||||||
|
try:
|
||||||
|
logger.info(f"Starting command: {cmd}")
|
||||||
|
registry.execute(cmd, skip_confirmation=True)
|
||||||
|
logger.info(f"Completed command: {cmd}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error running '{cmd}': {e}", exc_info=True)
|
||||||
|
continue
|
||||||
|
logger.info("All commands completed.")
|
||||||
|
|
||||||
|
|
||||||
|
registry.register("configure", run_configure,
|
||||||
|
"create configuration", requires_config=False)
|
||||||
|
registry.register("posts", run_posts, "only posts")
|
||||||
|
registry.register("medias", run_medias, "only posts with medias")
|
||||||
|
registry.register("likes", run_likes, "only likes")
|
||||||
|
registry.register("reposts", run_reposts, "only reposts")
|
||||||
|
registry.register("quotes", run_quotes, "only quotes")
|
||||||
|
registry.register("follows", run_follows, "only follows")
|
||||||
|
registry.register("bookmarks", run_bookmarks, "only bookmarks")
|
||||||
|
registry.register("all", run_all, "target everything")
|
||||||
|
|||||||
@@ -1,53 +1,25 @@
|
|||||||
"""Core configuration handling class and related logic."""
|
"""Core configuration module for Skywipe"""
|
||||||
|
|
||||||
import os
|
|
||||||
import getpass
|
import getpass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
import yaml
|
||||||
from cryptography.fernet import Fernet
|
from .logger import setup_logger, get_logger
|
||||||
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config_file = Path.home() / ".config" / "skywipe" / "config.yml"
|
self.config_file = Path.home() / ".config" / "skywipe" / "config.yml"
|
||||||
self.key_file = Path.home() / ".config" / "skywipe" / ".key"
|
|
||||||
self._fernet = None
|
|
||||||
|
|
||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.config_file.exists()
|
return self.config_file.exists()
|
||||||
|
|
||||||
def _get_or_create_key(self) -> bytes:
|
|
||||||
if self.key_file.exists():
|
|
||||||
return self.key_file.read_bytes()
|
|
||||||
|
|
||||||
key = Fernet.generate_key()
|
|
||||||
config_dir = self.key_file.parent
|
|
||||||
config_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
self.key_file.write_bytes(key)
|
|
||||||
os.chmod(self.key_file, 0o600)
|
|
||||||
return key
|
|
||||||
|
|
||||||
def _get_fernet(self) -> Fernet:
|
|
||||||
if self._fernet is None:
|
|
||||||
key = self._get_or_create_key()
|
|
||||||
self._fernet = Fernet(key)
|
|
||||||
return self._fernet
|
|
||||||
|
|
||||||
def encrypt_password(self, password: str) -> str:
|
|
||||||
fernet = self._get_fernet()
|
|
||||||
encrypted = fernet.encrypt(password.encode())
|
|
||||||
return encrypted.decode()
|
|
||||||
|
|
||||||
def decrypt_password(self, encrypted_password: str) -> str:
|
|
||||||
fernet = self._get_fernet()
|
|
||||||
decrypted = fernet.decrypt(encrypted_password.encode())
|
|
||||||
return decrypted.decode()
|
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
logger = setup_logger(verbose=False)
|
||||||
if self.exists():
|
if self.exists():
|
||||||
overwrite = input(
|
overwrite = input(
|
||||||
"Configuration already exists. Overwrite? (y/N): ").strip().lower()
|
"Configuration already exists. Overwrite? (y/N): ").strip().lower()
|
||||||
if overwrite not in ("y", "yes"):
|
if overwrite not in ("y", "yes"):
|
||||||
|
logger.info("Configuration creation cancelled.")
|
||||||
return
|
return
|
||||||
|
|
||||||
config_dir = self.config_file.parent
|
config_dir = self.config_file.parent
|
||||||
@@ -68,14 +40,12 @@ class Configuration:
|
|||||||
batch_size = int(batch_size)
|
batch_size = int(batch_size)
|
||||||
delay = int(delay)
|
delay = int(delay)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Error: batch_size and delay must be integers")
|
logger.error("batch_size and delay must be integers")
|
||||||
return
|
return
|
||||||
|
|
||||||
encrypted_password = self.encrypt_password(password)
|
|
||||||
|
|
||||||
config_data = {
|
config_data = {
|
||||||
"handle": handle,
|
"handle": handle,
|
||||||
"password": encrypted_password,
|
"password": password,
|
||||||
"batch_size": batch_size,
|
"batch_size": batch_size,
|
||||||
"delay": delay,
|
"delay": delay,
|
||||||
"verbose": verbose
|
"verbose": verbose
|
||||||
@@ -84,4 +54,11 @@ class Configuration:
|
|||||||
with open(self.config_file, "w") as f:
|
with open(self.config_file, "w") as f:
|
||||||
yaml.dump(config_data, f, default_flow_style=False)
|
yaml.dump(config_data, f, default_flow_style=False)
|
||||||
|
|
||||||
print(f"\nConfiguration saved to {self.config_file}")
|
logger.info(f"Configuration saved to {self.config_file}")
|
||||||
|
|
||||||
|
def load(self) -> dict:
|
||||||
|
if not self.exists():
|
||||||
|
raise FileNotFoundError(
|
||||||
|
f"Configuration file not found: {self.config_file}")
|
||||||
|
with open(self.config_file, "r") as f:
|
||||||
|
return yaml.safe_load(f)
|
||||||
|
|||||||
73
skywipe/follows.py
Normal file
73
skywipe/follows.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"""Follow undoing module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from atproto import models
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
FOLLOW_COLLECTION = "app.bsky.graph.follow"
|
||||||
|
|
||||||
|
|
||||||
|
def unfollow_all():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting unfollow operation with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_unfollowed = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Unfollowing accounts")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
list_params = models.ComAtprotoRepoListRecords.Params(
|
||||||
|
repo=did,
|
||||||
|
collection=FOLLOW_COLLECTION,
|
||||||
|
limit=batch_size,
|
||||||
|
cursor=cursor
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.com.atproto.repo.list_records(params=list_params)
|
||||||
|
|
||||||
|
records = response.records
|
||||||
|
if not records:
|
||||||
|
break
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(records))
|
||||||
|
|
||||||
|
for record in records:
|
||||||
|
try:
|
||||||
|
record_uri = record.uri
|
||||||
|
rkey = record_uri.rsplit("/", 1)[-1]
|
||||||
|
delete_data = {
|
||||||
|
"repo": did,
|
||||||
|
"collection": FOLLOW_COLLECTION,
|
||||||
|
"rkey": rkey
|
||||||
|
}
|
||||||
|
client.com.atproto.repo.delete_record(data=delete_data)
|
||||||
|
total_unfollowed += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Unfollowed: {record_uri}")
|
||||||
|
except Exception as e:
|
||||||
|
record_uri = getattr(record, "uri", "unknown")
|
||||||
|
logger.error(f"Error unfollowing {record_uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Unfollowed {total_unfollowed} accounts.")
|
||||||
73
skywipe/likes.py
Normal file
73
skywipe/likes.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"""Like undoing module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from atproto import models
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
LIKE_COLLECTION = "app.bsky.feed.like"
|
||||||
|
|
||||||
|
|
||||||
|
def undo_likes():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting like deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_undone = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Undoing likes")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
list_params = models.ComAtprotoRepoListRecords.Params(
|
||||||
|
repo=did,
|
||||||
|
collection=LIKE_COLLECTION,
|
||||||
|
limit=batch_size,
|
||||||
|
cursor=cursor
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.com.atproto.repo.list_records(params=list_params)
|
||||||
|
|
||||||
|
records = response.records
|
||||||
|
if not records:
|
||||||
|
break
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(records))
|
||||||
|
|
||||||
|
for record in records:
|
||||||
|
try:
|
||||||
|
record_uri = record.uri
|
||||||
|
rkey = record_uri.rsplit("/", 1)[-1]
|
||||||
|
delete_data = {
|
||||||
|
"repo": did,
|
||||||
|
"collection": LIKE_COLLECTION,
|
||||||
|
"rkey": rkey
|
||||||
|
}
|
||||||
|
client.com.atproto.repo.delete_record(data=delete_data)
|
||||||
|
total_undone += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Undone like: {record_uri}")
|
||||||
|
except Exception as e:
|
||||||
|
record_uri = getattr(record, "uri", "unknown")
|
||||||
|
logger.error(f"Error undoing like {record_uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Undone {total_undone} likes.")
|
||||||
73
skywipe/logger.py
Normal file
73
skywipe/logger.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"""Centralized logging module for Skywipe"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
|
class ProgressTracker:
|
||||||
|
def __init__(self, operation: str = "Processing"):
|
||||||
|
self.current = 0
|
||||||
|
self.operation = operation
|
||||||
|
|
||||||
|
def update(self, count: int = 1):
|
||||||
|
self.current += count
|
||||||
|
|
||||||
|
def batch(self, batch_num: int, batch_size: int, total_batches: Optional[int] = None):
|
||||||
|
logger = logging.getLogger("skywipe.progress")
|
||||||
|
if total_batches:
|
||||||
|
logger.info(
|
||||||
|
f"{self.operation} - batch {batch_num}/{total_batches} ({batch_size} items)"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
f"{self.operation} - batch {batch_num} ({batch_size} items)")
|
||||||
|
|
||||||
|
|
||||||
|
class LevelFilter(logging.Filter):
|
||||||
|
def __init__(self, min_level: int, max_level: int):
|
||||||
|
super().__init__()
|
||||||
|
self.min_level = min_level
|
||||||
|
self.max_level = max_level
|
||||||
|
|
||||||
|
def filter(self, record: logging.LogRecord) -> bool:
|
||||||
|
return self.min_level <= record.levelno <= self.max_level
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logger(verbose: bool = False, log_file: Optional[Path] = None) -> logging.Logger:
|
||||||
|
logger = logging.getLogger("skywipe")
|
||||||
|
logger.setLevel(logging.DEBUG if verbose else logging.INFO)
|
||||||
|
|
||||||
|
if logger.handlers:
|
||||||
|
return logger
|
||||||
|
|
||||||
|
formatter = logging.Formatter(fmt="%(levelname)s: %(message)s")
|
||||||
|
|
||||||
|
info_handler = logging.StreamHandler(sys.stdout)
|
||||||
|
info_handler.setLevel(logging.DEBUG if verbose else logging.INFO)
|
||||||
|
info_handler.addFilter(LevelFilter(logging.DEBUG, logging.INFO))
|
||||||
|
info_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(info_handler)
|
||||||
|
|
||||||
|
error_handler = logging.StreamHandler(sys.stderr)
|
||||||
|
error_handler.setLevel(logging.WARNING)
|
||||||
|
error_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(error_handler)
|
||||||
|
|
||||||
|
if log_file:
|
||||||
|
log_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
file_handler = logging.FileHandler(log_file, encoding="utf-8")
|
||||||
|
file_handler.setLevel(logging.DEBUG)
|
||||||
|
file_formatter = logging.Formatter(
|
||||||
|
fmt="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||||
|
datefmt="%Y-%m-%d %H:%M:%S"
|
||||||
|
)
|
||||||
|
file_handler.setFormatter(file_formatter)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger() -> logging.Logger:
|
||||||
|
return logging.getLogger("skywipe")
|
||||||
95
skywipe/medias.py
Normal file
95
skywipe/medias.py
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
"""Media post deletion module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
def delete_posts_with_medias():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting media post deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_deleted = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Deleting posts with media")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
response = client.get_author_feed(
|
||||||
|
actor=did, limit=batch_size, cursor=cursor)
|
||||||
|
|
||||||
|
posts = response.feed
|
||||||
|
if not posts:
|
||||||
|
break
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(posts))
|
||||||
|
|
||||||
|
for post in posts:
|
||||||
|
post_record = post.post
|
||||||
|
|
||||||
|
embed = getattr(post_record, 'embed', None)
|
||||||
|
has_media = False
|
||||||
|
if embed:
|
||||||
|
embed_type = getattr(embed, 'py_type', None)
|
||||||
|
media_types = {
|
||||||
|
'app.bsky.embed.images',
|
||||||
|
'app.bsky.embed.video',
|
||||||
|
'app.bsky.embed.external'
|
||||||
|
}
|
||||||
|
|
||||||
|
if embed_type:
|
||||||
|
embed_type_base = embed_type.split('#')[0]
|
||||||
|
|
||||||
|
if embed_type_base in media_types:
|
||||||
|
has_media = True
|
||||||
|
|
||||||
|
if not has_media and embed_type_base in ('app.bsky.embed.recordWithMedia', 'app.bsky.embed.record_with_media'):
|
||||||
|
media = getattr(embed, 'media', None)
|
||||||
|
if media:
|
||||||
|
media_type = getattr(media, 'py_type', None)
|
||||||
|
if media_type:
|
||||||
|
media_type_base = media_type.split('#')[0]
|
||||||
|
if media_type_base in media_types:
|
||||||
|
has_media = True
|
||||||
|
|
||||||
|
if not has_media:
|
||||||
|
for attr in ('images', 'video', 'external'):
|
||||||
|
if hasattr(embed, attr):
|
||||||
|
has_media = True
|
||||||
|
break
|
||||||
|
if isinstance(embed, dict) and embed.get(attr):
|
||||||
|
has_media = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not has_media:
|
||||||
|
logger.debug(f"Skipping post without media: {post_record.uri}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.delete_post(post_record.uri)
|
||||||
|
total_deleted += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Deleted post with media: {post_record.uri}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error deleting post {post_record.uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Deleted {total_deleted} posts with media.")
|
||||||
59
skywipe/posts.py
Normal file
59
skywipe/posts.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
"""Post deletion module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
def delete_all_posts():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting post deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_deleted = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Deleting posts")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
if cursor:
|
||||||
|
response = client.get_author_feed(
|
||||||
|
actor=did, limit=batch_size, cursor=cursor)
|
||||||
|
else:
|
||||||
|
response = client.get_author_feed(actor=did, limit=batch_size)
|
||||||
|
|
||||||
|
posts = response.feed
|
||||||
|
if not posts:
|
||||||
|
break
|
||||||
|
|
||||||
|
post_uris = [post.post.uri for post in posts]
|
||||||
|
progress.batch(batch_num, len(post_uris))
|
||||||
|
|
||||||
|
for uri in post_uris:
|
||||||
|
try:
|
||||||
|
client.delete_post(uri)
|
||||||
|
total_deleted += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Deleted post: {uri}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error deleting post {uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Deleted {total_deleted} posts.")
|
||||||
77
skywipe/quotes.py
Normal file
77
skywipe/quotes.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
"""Quote post deletion module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
def delete_quotes_posts():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(f"Starting quote post deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_deleted = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Deleting quote posts")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
response = client.get_author_feed(
|
||||||
|
actor=did, limit=batch_size, cursor=cursor)
|
||||||
|
|
||||||
|
posts = response.feed
|
||||||
|
if not posts:
|
||||||
|
break
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(posts))
|
||||||
|
|
||||||
|
for post in posts:
|
||||||
|
post_record = post.post
|
||||||
|
|
||||||
|
embed = getattr(post_record, 'embed', None)
|
||||||
|
has_quote = False
|
||||||
|
if embed:
|
||||||
|
embed_type = getattr(embed, 'py_type', None)
|
||||||
|
if embed_type:
|
||||||
|
embed_type_base = embed_type.split('#')[0]
|
||||||
|
quote_types = {
|
||||||
|
'app.bsky.embed.record',
|
||||||
|
'app.bsky.embed.recordWithMedia',
|
||||||
|
'app.bsky.embed.record_with_media'
|
||||||
|
}
|
||||||
|
if embed_type_base in quote_types:
|
||||||
|
has_quote = True
|
||||||
|
|
||||||
|
if not has_quote and (hasattr(embed, 'record') or (isinstance(embed, dict) and embed.get('record'))):
|
||||||
|
has_quote = True
|
||||||
|
|
||||||
|
if not has_quote:
|
||||||
|
logger.debug(f"Skipping post without quote: {post_record.uri}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.delete_post(post_record.uri)
|
||||||
|
total_deleted += 1
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Deleted quote post: {post_record.uri}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error deleting quote post {post_record.uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Deleted {total_deleted} quote posts.")
|
||||||
73
skywipe/reposts.py
Normal file
73
skywipe/reposts.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
"""Repost undoing module for Skywipe"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from atproto import models
|
||||||
|
from .auth import Auth
|
||||||
|
from .configure import Configuration
|
||||||
|
from .logger import get_logger, ProgressTracker
|
||||||
|
|
||||||
|
|
||||||
|
REPOST_COLLECTION = "app.bsky.feed.repost"
|
||||||
|
|
||||||
|
|
||||||
|
def undo_reposts():
|
||||||
|
logger = get_logger()
|
||||||
|
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)
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Starting repost deletion with batch_size={batch_size}, delay={delay}s")
|
||||||
|
|
||||||
|
did = client.me.did
|
||||||
|
cursor = None
|
||||||
|
total_undone = 0
|
||||||
|
batch_num = 0
|
||||||
|
progress = ProgressTracker(operation="Undoing reposts")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
batch_num += 1
|
||||||
|
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
|
||||||
|
|
||||||
|
progress.batch(batch_num, len(records))
|
||||||
|
|
||||||
|
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
|
||||||
|
progress.update(1)
|
||||||
|
logger.debug(f"Undone repost: {record_uri}")
|
||||||
|
except Exception as e:
|
||||||
|
record_uri = getattr(record, "uri", "unknown")
|
||||||
|
logger.error(f"Error undoing repost {record_uri}: {e}")
|
||||||
|
|
||||||
|
cursor = response.cursor
|
||||||
|
if not cursor:
|
||||||
|
break
|
||||||
|
|
||||||
|
if delay > 0:
|
||||||
|
time.sleep(delay)
|
||||||
|
|
||||||
|
logger.info(f"Undone {total_undone} reposts.")
|
||||||
27
skywipe/safeguard.py
Normal file
27
skywipe/safeguard.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
"""Safeguard module for Skywipe"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from .logger import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
CONFIRM_RESPONSES = {"yes", "y"}
|
||||||
|
|
||||||
|
|
||||||
|
def require_confirmation(operation: str, skip_confirmation: bool = False) -> None:
|
||||||
|
if skip_confirmation:
|
||||||
|
return
|
||||||
|
|
||||||
|
logger = get_logger()
|
||||||
|
logger.warning(f"This will {operation}")
|
||||||
|
logger.warning("This operation is DESTRUCTIVE and cannot be undone!")
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = input(
|
||||||
|
"Are you sure you want to continue? (y/N): ").strip().lower()
|
||||||
|
except (EOFError, KeyboardInterrupt):
|
||||||
|
logger.info("\nOperation cancelled.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if response not in CONFIRM_RESPONSES:
|
||||||
|
logger.info("Operation cancelled.")
|
||||||
|
sys.exit(0)
|
||||||
2
uv.lock
generated
2
uv.lock
generated
@@ -381,14 +381,12 @@ version = "0.1.0"
|
|||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "atproto" },
|
{ name = "atproto" },
|
||||||
{ name = "cryptography" },
|
|
||||||
{ name = "pyyaml" },
|
{ name = "pyyaml" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "atproto", specifier = ">=0.0.65" },
|
{ name = "atproto", specifier = ">=0.0.65" },
|
||||||
{ name = "cryptography", specifier = ">=42.0.0" },
|
|
||||||
{ name = "pyyaml", specifier = ">=6.0" },
|
{ name = "pyyaml", specifier = ">=6.0" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user