-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_reader.py
49 lines (40 loc) · 1.51 KB
/
content_reader.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
from datadog import initialize, statsd
import logging
import time
from common.config import (
DATADOG_OPTIONS,
JOB_SLEEP_TIME_SECONDS,
READER_MODE,
QUERIES,
LOCAL_STORE,
GOOGLE_FORM_ID,
GOOGLE_SERVICE_ACCOUNT_FILE,
)
from google_forms.reader import run_form_reader
from reddit.feed_reader import run_reddit_feed
from twitter.searcher import run_twitter_searches
logging.basicConfig()
logging.root.setLevel(logging.INFO)
logger = logging.getLogger(__name__)
initialize(**DATADOG_OPTIONS)
if __name__ == "__main__":
twitter_since_id = None
try:
while True:
logger.info(f"Job Starting.")
statsd.increment(f"job.start", 1, tags=[f"job_mode:{READER_MODE}"])
if READER_MODE == "reddit":
run_reddit_feed()
elif READER_MODE == "twitter":
twitter_since_id = run_twitter_searches(twitter_since_id, QUERIES, READER_MODE, LOCAL_STORE)
elif READER_MODE == "form":
run_form_reader(GOOGLE_SERVICE_ACCOUNT_FILE, GOOGLE_FORM_ID, READER_MODE)
else:
raise ValueError(f"READER_MODE {READER_MODE} not supported")
statsd.increment(f"job.finish", 1, tags=[f"job_mode:{READER_MODE}"])
if READER_MODE in {"form"}:
exit(0)
logger.info(f"Job complete. Sleeping for {JOB_SLEEP_TIME_SECONDS} seconds.")
time.sleep(JOB_SLEEP_TIME_SECONDS)
except KeyboardInterrupt:
logger.info("KeyboardInterrupt called. Exiting.")