├── runtime.txt ├── Procfile ├── .gitignore ├── requirements.txt ├── README.md └── main.py /runtime.txt: -------------------------------------------------------------------------------- 1 | python-2.7.14 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | clock: python main.py 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config.py 2 | *.pyc 3 | .env 4 | venv 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | twython 2 | oauthlib 3 | requests 4 | pytz 5 | APScheduler==3.0.0 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mcgrawtower 2 | Big Ben Clock clone for Cornell McGraw Tower 3 | 4 | This is the source code for @mcgrawtower. It is a simple Python script that tweets "CHIME" times the current hour. The application is currently running on Heroku. 5 | 6 | # Installation 7 | Clone this repo and install dependencies via `pip install -r requirementes.txt` inside a virtualenv. Add Twitter app secrets to your environment and run with `python main.py` to start scheduling tweets. 8 | 9 | Or, install the heroku toolbelt, create a `.env` file containing your Twitter secrets, and run the app with `heroku local`. You can then host the app on Heroku as well. 10 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from twython import Twython 3 | import pytz 4 | import datetime 5 | import os 6 | 7 | from apscheduler.schedulers.blocking import BlockingScheduler 8 | 9 | 10 | CONSUMER_KEY=os.environ.get('CONSUMER_KEY') 11 | CONSUMER_SECRET=os.environ.get('CONSUMER_SECRET') 12 | ACCESS_TOKEN=os.environ.get('ACCESS_TOKEN') 13 | ACCESS_TOKEN_SECRET=os.environ.get('ACCESS_TOKEN_SECRET') 14 | 15 | 16 | sched = BlockingScheduler() 17 | 18 | 19 | @sched.scheduled_job('cron', minute=0) 20 | def main(): 21 | print "Scheduled job running..." 22 | 23 | # Generate the status that mcgrawtower will tweet 24 | tz = pytz.timezone("US/Eastern") 25 | dt = datetime.datetime.now(tz) 26 | hour = dt.hour % 12 27 | if hour == 0: 28 | hour = 12 29 | msg = "CHIME " * hour 30 | 31 | # Tweet the message out 32 | twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) 33 | try: 34 | result = twitter.update_status(status=msg) 35 | print result 36 | except Exception as e: 37 | print e 38 | finally: 39 | print "Done." 40 | 41 | sched.start() 42 | --------------------------------------------------------------------------------