This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rand_del_fav_twi.py
102 lines (100 loc) · 2.92 KB
/
rand_del_fav_twi.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
96
97
98
99
100
101
102
from requests_oauthlib import OAuth1Session
from linebot import LineBotApi
from linebot.models import TextSendMessage
from time import sleep
import conf,json,sys,requests,random
#get favs or tweets data
def retrieve(url,s):
max=""
params = {
'count' : 200,
'screen_name' : conf.t_user_id
}
for i in range(0,10**19):
dame=False
if i != 0:
params['max_id'] = max
res = s.get(url, params = params)
if res.status_code == 200:
timelines = json.loads(res.text)
idlist = []
for lines in timelines:
idlist.append(lines["id"])
dame=True
max=id-1
else:
print ("Error: %d" % req.status_code)
if not dame:
break
return idlist,int(idlist/2)
#delete tweet every tweet_id
def del_twe(id_twe,s):
url="https://api.twitter.com/1.1/statuses/destroy/"+str(id_twe)+".json"
params = {
"trim_user" : "false"
}
res = s.post(url, params = params)
#delete favorite every favorite_id
def del_fav(id_fav,s):
url="https://api.twitter.com/1.1/favorites/destroy.json"
params = {
"id" : id_fav,
"include_entities" : "false"
}
res = s.post(url, params = params)
#notify to line room
def notify_line(seed,result):
l = LineBotApi(conf.l_AT)
messages = TextSendMessage(
text="seedは"+seed+"でした.\nよって,"+result+"."
)
l.push_message(conf.l_id, messages=messages)
#delete half of favorites
def del_fav_hal(list_fav,s):
for id in list_fav[0][list_fav[1]]:
del_fav(id,s)
return "いいね半消し"
#delete favorites all
def del_fav_all(list_fav,s):
for id in list_fav[0]:
del_fav(id,s)
return "いいね全消し"
#delete half of tweets
def del_twe_hal(list_twe,s):
for id in list_twe[0][list_twe[1]]:
del_twe(id,s)
return "つぶやき半消し"
#delete tweets all
def del_twe_all(list_twe,s):
for id in list_twe:
del_twe(id,s)
return "つぶやき全消し"
#do nothing
def del_nothing():
return "なにもなし"
##########
##main()##
##########
while True:
result="いいね・つぶやき全消し"
sleep(86400)
twitter = OAuth1Session(conf.CK, conf.CS, conf.t_AT, conf.AS)
url = "https://api.twitter.com/1.1/favorites/list.json"
list_fav=retrieve(url,twitter)
url = "https://api.twitter.com/1.1/statuses/user_timeline.json"
list_twe=retrieve(url,twitter)
seed=random.randrange(100)
if seed in range(0,30):
result=del_fav_hal(list_fav,twitter)
elif seed in range(30,55):
result=del_fav_all(list_fav,twitter)
elif seed in range(55,65):
result=del_twe_hal(list_twe,twitter)
elif seed in range(65,70):
result=del_twe_all(list_twe,twitter)
elif seed in range(70,99):
result=del_nothing()
else:
del_fav_all(list_fav,twitter)
del_twe_all(list_twe,twitter)
notify_line(seed,result)