-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
113 lines (97 loc) · 2.9 KB
/
app.py
File metadata and controls
113 lines (97 loc) · 2.9 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
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
103
104
105
106
107
108
109
110
111
112
import twitter
from _constants import *
import time
import datetime
# authentication
def auth():
api = twitter.Api(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token_key=access_token,
access_token_secret=access_token_secret)
return api
# get tweet IDs
def getTweetId(username):
api = auth()
try:
tweets = api.GetUserTimeline(screen_name=username, count=200)
result = list()
ids = list()
for i in range(len(tweets)):
result.append(tweets[i])
for id in range(len(result)):
ids.append(result[id].id)
return ids
except Exception as e:
print('Oops something error: ', e)
print('Please wait..')
time.sleep(60)
pass
# delete tweets
def deleteAllTweets():
tweetIds = []
api = auth()
username = api.VerifyCredentials()
username = username.AsDict()['screen_name']
while True:
if len(tweetIds) != 0:
try:
for id in tweetIds:
try:
api.DestroyStatus(id)
except Exception:
tweetIds = getTweetId(username)
print('%s was deleted' % id)
time.sleep(5)
except Exception as e:
print('Oops something error: ', e)
print('please wait..')
time.sleep(60)
else:
try:
tweetIds = getTweetId(username=username)
print('tweets reloaded')
if len(tweetIds) == 0:
print('---task done---')
break
except Exception as e:
print('Oops something error: ', e)
print('please wait..')
time.sleep(60)
pass
def run():
print('script is running..')
def switch(hari=str()):
hari = hari.lower()
switcher = {
'senin': 0,
'selasa': 1,
'rabu': 2,
'kamis': 3,
'jumat': 4,
'sabtu': 5,
'minggu': 6
}
return switcher.get(hari, 6)
def switch2(hari):
switcher = {
0 : 'senin',
1 : 'selasa',
2 : 'rabu',
3 : 'kamis',
4 : 'jumat',
5 : 'sabtu',
6 : 'minggu'
}
return switcher.get(hari)
while True:
day = datetime.datetime.today().weekday()
hour = datetime.datetime.today().time().hour
minute = datetime.datetime.today().time().minute
if day == switch(hari):
deleteAllTweets()
else:
print('waiting %s %s:%s' % (switch2(switch(hari))))
print('today is %s %s:%s' % (switch2(day), hour, minute))
time.sleep(5)
if __name__ == '__main__':
run()