-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·41 lines (31 loc) · 973 Bytes
/
main.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
#!/usr/bin/env python
from twython import Twython
import pytz
import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler
CONSUMER_KEY=os.environ.get('CONSUMER_KEY')
CONSUMER_SECRET=os.environ.get('CONSUMER_SECRET')
ACCESS_TOKEN=os.environ.get('ACCESS_TOKEN')
ACCESS_TOKEN_SECRET=os.environ.get('ACCESS_TOKEN_SECRET')
sched = BlockingScheduler()
@sched.scheduled_job('cron', minute=0)
def main():
print "Scheduled job running..."
# Generate the status that mcgrawtower will tweet
tz = pytz.timezone("US/Eastern")
dt = datetime.datetime.now(tz)
hour = dt.hour % 12
if hour == 0:
hour = 12
msg = "CHIME " * hour
# Tweet the message out
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
try:
result = twitter.update_status(status=msg)
print result
except Exception as e:
print e
finally:
print "Done."
sched.start()