-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice
50 lines (41 loc) · 1.61 KB
/
service
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
#!/usr/bin/python
import sys
import time
import traceback
from datetime import datetime, date
import tweepy
from tweepy import OAuthHandler
from hosted import CONFIG
from twitter import cleanup, filter_and_save
if __name__ == '__main__':
CONFIG.restart_on_update()
# wait till the configuration is non-empty. hosted
# will restart this process when the configuration changes.
if not CONFIG["consumer_key"] or CONFIG["poll_interval"] == 0:
print >>sys.stderr, "waiting for a config change"
while 1: time.sleep(100000)
auth = OAuthHandler(CONFIG['consumer_key'], CONFIG['consumer_secret'])
auth.set_access_token(CONFIG['access_token'], CONFIG['access_token_secret'])
api = tweepy.API(auth)
try:
not_before = datetime.strptime(CONFIG['not_before'], "%d.%m.%Y").date()
except ValueError:
traceback.print_exc()
not_before = date(1,1,1)
print >>sys.stderr, "not before %s" % not_before
while 1:
try:
cleanup()
mode = CONFIG['mode']
if mode == 'favs':
tweets = api.favorites(CONFIG['query'], count=CONFIG['count']+20)
elif mode == 'search':
tweets = api.search(q=CONFIG['query'], count=CONFIG['count']+20)
elif mode == 'timeline':
tweets = api.user_timeline(screen_name=CONFIG['query'], count=CONFIG['count']+20)
filter_and_save(tweets, not_before, CONFIG['count'], CONFIG['filter_garbage'])
except:
traceback.print_exc()
time.sleep(60)
else:
time.sleep(60 * CONFIG['poll_interval'])