-
Notifications
You must be signed in to change notification settings - Fork 0
/
about.py
78 lines (61 loc) · 1.59 KB
/
about.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
import json, requests, tweepy, sys, time, inflect
from fdict import sfdict
p = inflect.engine()
INTERVAL = 60 * 1
RETWEET = True
cache = sfdict(filename = 'history.db')
def erase():
api = authenticate()
for id in cache.values():
try:
api.destroy_status(id)
print('Destroyed: ',id)
time.sleep(INTERVAL)
except tweepy.error.TweepError as e:
print(e, id)
def makeFile():
with open('sentences.txt','w') as f:
for i in range(1,20):
f.write('This is my '+str(p.ordinal(i))+' tweet\n')
def exit():
print('Force Terminating...')
cache.sync()
cache.close()
print('Done...')
sys.exit(0)
def postTweet(api, tweet):
try:
print('Posting', tweet)
id = api.update_status(status=tweet).id
print('>>>>>>>',id)
print(id, tweet, 'sleepling '+str(INTERVAL)+'s')
if id:
cache[tweet] = id
except tweepy.error.TweepError as e:
print('Erasing to repost')
api.destroy_status(cache[tweet])
id = api.update_status(status=tweet).id
print('done',id, tweet, 'sleepling '+str(INTERVAL)+'s')
if id:
cache[tweet] = id
def main(content = 'sentences.txt'):
api = authenticate()
with open(content,'r') as f:
content = f.read().split('\n')
for tweet in content:
try:
postTweet(api, tweet)
time.sleep(INTERVAL)
except KeyboardInterrupt:
exit()
def authenticate():
with open('keys.json','r') as f:
keys=json.load(f)
auth = tweepy.OAuthHandler(keys['consumer_key'],keys['consumer_secret'])
auth.set_access_token(keys['token'],keys['token_secret'])
api = tweepy.API(auth)
return api
if __name__ == '__main__':
print('Started...')
main()
print('Terminating...')