-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharryplotter.py
More file actions
69 lines (61 loc) · 2.04 KB
/
harryplotter.py
File metadata and controls
69 lines (61 loc) · 2.04 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
#!/usr/bin/env python
def update_last_id(config):
tweets = None
logging.debug("updating last id on start")
while tweets is None:
try:
tweets = get_tweets_by_terms(terms, config.getint("state", "last_id"), tweets_per_page = config.getint("twitter", "tweets_per_page"), recursive = False)
except TweetsError, e:
logging.info("A TweetsError accured.")
logging.info(e)
except Exception, e:
logging.exception(e)
config.set("state", "last_id", str(tweets[-1].id) if len(tweets) is not 0 else config.get("state", "last_id"))
def processing_loop(config, terms):
tweets = None
logging.info("Searching twitter")
while tweets is None:
try:
tweets = get_tweets_by_terms(terms, config.getint("state", "last_id"), \
tweets_per_page = config.getint("twitter", "tweets_per_page"), recursive = True)
except TweetsError, e:
logging.info("A TweetsError accured.")
logging.info(e)
except Exception, e:
logging.exception(e)
logging.debug(str(len(tweets)) + " tweets found")
try:
for tweet in tweets:
while not harry.plot_tweet(tweet): time.sleep(1)
logging.debug("Plotted tweet: " + str(tweet.id))
logging.tweet(tweet)
logging.debug("Tweets plotted")
except PlotterError, e:
logging.exception(e)
import atexit
from logginghelper import logging
from harrytools import plotter, config, PlotterError
from twitterhelper import get_tweets_by_terms, TweetsError
config = config()
harry = plotter(config)
def cleanup():
config.save()
logging.info("Programm was closed")
logging.shutdown()
def main():
terms = [term.strip() for term in config.get("twitter", "terms").split(",")]
logging.info("Programm started")
logging.debug("Serial Interface: " + config.get("plotter", "serial_device"))
logging.debug("Twitter Terms: " + config.get("twitter", "terms"))
if config.getboolean("twitter", "update_last_id_on_start"):
update_last_id(config)
while True:
try:
processing_loop(config, terms)
except KeyboardInterrupt:
break
except Exception, e:
logging.exception(e)
if __name__ == '__main__':
atexit.register(cleanup)
main()