-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_bsky.py
More file actions
63 lines (48 loc) · 2.08 KB
/
clean_bsky.py
File metadata and controls
63 lines (48 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import datetime
import os
from dotenv import load_dotenv
from atproto import Client, exceptions
# Load variables from .env file
load_dotenv()
# --- CONFIGURATION ---
HANDLE = os.getenv("BLUESKY_HANDLE")
APP_PASSWORD = os.getenv("BLUESKY_APP_PASSWORD")
DRY_RUN = False # Set to False to actually delete posts!
# ---------------------
def delete_todays_posts():
# Validation: Ensure credentials exist
if not HANDLE or not APP_PASSWORD:
print("Error: Credentials missing. Please check your .env file.")
return
client = Client()
try:
print(f"Logging in as {HANDLE}...")
client.login(HANDLE, APP_PASSWORD)
# Bluesky timestamps are in UTC
today = datetime.datetime.now(datetime.timezone.utc).date()
print(f"Searching for posts made on: {today}")
# Fetch the latest 50 posts from your feed
response = client.get_author_feed(actor=HANDLE, limit=50)
deleted_count = 0
for feed_view in response.feed:
post = feed_view.post
post_date = datetime.datetime.fromisoformat(post.record.created_at).date()
if post_date == today:
print(f"\n[MATCH] Found post from {post.record.created_at}:")
print(f"Content: {post.record.text[:50]}...")
if DRY_RUN:
print(">>> DRY RUN: Post would be deleted.")
else:
try:
client.delete_post(post.uri)
print(">>> SUCCESS: Post deleted.")
except Exception as e:
print(f">>> ERROR: Could not delete post: {e}")
deleted_count += 1
print(f"\nTask complete. Total posts identified: {deleted_count}")
if DRY_RUN and deleted_count > 0:
print("To actually delete these, set 'DRY_RUN = False' in the script.")
except exceptions.AtProtocolError as e:
print(f"Authentication failed: {e}")
if __name__ == "__main__":
delete_todays_posts()