-
Notifications
You must be signed in to change notification settings - Fork 1
/
twitter_rm.py
executable file
·44 lines (32 loc) · 1.09 KB
/
twitter_rm.py
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
#!/usr/bin/env python3
import os
import twitter
import sys
import pdb
TWEET_DOES_NOT_EXIST_CODE=144
# Ensure these environment variables are set with twitter access codes.
api = twitter.Api(consumer_key=os.environ["CONSUMER_KEY"],
consumer_secret=os.environ["CONSUMER_SECRET"],
access_token_key=os.environ["ACCESS_TOKEN"],
access_token_secret=os.environ["ACCESS_TOKEN_SECRET"])
def extract_status_id(inp):
return inp.split('|')[0]
fn = lambda: sys.argv[1] if sys.argv[1:] else "deletables.txt"
fh = open(str(fn()))
next_line = fh.readline().rstrip()
while next_line:
status_id = extract_status_id(next_line)
try:
status_id_to_i = int(status_id)
status_id = status_id_to_i
except ValueError:
next_line = fh.readline().rstrip()
continue
print(f"Processing {status_id}")
try:
result = api.DestroyStatus(status_id)
except twitter.error.TwitterError as e:
if e.message[0]['code'] == TWEET_DOES_NOT_EXIST_CODE:
print(f"Skipped {status_id}")
pass
next_line = fh.readline().rstrip()