forked from devio/de-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathde-x.py
95 lines (68 loc) · 2.33 KB
/
de-x.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##
# de-x.py -- delete all your tweets w/o API access
# Copyright 2023 Thorsten Schroeder
#
# Published under 2-Clause BSD License (https://opensource.org/license/bsd-2-clause/)
#
# Please see README.md for more information
##
##
# Unlike-Tweets-X -- delete all your favorites w/o API access
# Copyright 2023 Metin Emre Koral
# Forked and developed from devio's de-x script: (https://github.com/devio/de-x)
#
# Please see README.md for more information
##
import sys
import json
import requests
import random
import time
def get_tweet_ids(json_data):
result = []
data = json.loads(json_data)
for d in data:
result.append(d['like']['tweetId'])
return result
def parse_req_headers(request_file):
sess = {}
with open(request_file) as f:
line = f.readline()
while line:
try:
k,v = line.split(':', 1)
val = v.lstrip().rstrip()
sess[k] = val
except:
# ignore empty lines
pass
line = f.readline()
return sess
def main(ac, av):
if(ac != 3):
print(f"[!] usage: {av[0]} <jsonfile> <req-headers>")
return
f = open(av[1], encoding='UTF-8')
raw = f.read()
f.close()
# skip data until first '['
i = raw.find('[')
ids = get_tweet_ids(raw[i:])
session = parse_req_headers(av[2])
for i in ids:
delete_tweet(session, i)
# as a chrishenninger's comment in another alike project; X's UnfavoriteTweet endpoint has rate limiting: ~500 tweets in a ~15 minutes https://gist.github.com/aymericbeaumet/d1d6799a1b765c3c8bc0b675b1a1547d?permalink_comment_id=4694790#gistcomment-4694790
sleep_time = random.uniform(1, 5)
time.sleep(sleep_time)
def delete_tweet(session, tweet_id):
print(f"[*] delete tweet-id {tweet_id}")
delete_url = "https://twitter.com/i/api/graphql/ZYKSe-w7KEslx3JhSIk5LA/UnfavoriteTweet"
data = {"variables":{"tweet_id":tweet_id,"dark_request":False},"queryId":"ZYKSe-w7KEslx3JhSIk5LA"}
# set or re-set correct content-type header
session["content-type"] = 'application/json'
r = requests.post(delete_url, data=json.dumps(data), headers=session)
print(r.status_code, r.reason)
print(r.text[:500] + '...')
return
if __name__ == '__main__':
main(len(sys.argv), sys.argv)