├── runtime.txt ├── Procfile ├── .gitignore ├── requirements.txt ├── README.md └── main.py /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.7.2 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn main:app 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config.py 2 | *.pyc 3 | .env 4 | venv 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | gunicorn 3 | twython 4 | oauthlib 5 | requests 6 | pytz 7 | APScheduler==3.0.0 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BANG BANG 2 | bang bang 3 | 4 | # Installation 5 | 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. 6 | 7 | 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. 8 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import pytz 3 | import datetime 4 | import os 5 | from random import randint 6 | from flask import Flask, abort, request 7 | from twython import Twython 8 | 9 | app = Flask(__name__) 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 | POST_KEY = os.environ.get('POST_KEY') 15 | 16 | @app.route('/', methods=['POST']) 17 | def tweet(): 18 | data = request.get_json() 19 | if data and data.get('key') == POST_KEY: 20 | # Generate the message that the bot will tweet 21 | tz = pytz.timezone("US/Pacific") 22 | msg = "BANG BANG occurred at " + datetime.datetime.now(tz).strftime("%m/%d/%Y, %H:%M:%S") 23 | 24 | # Tweet the message out 25 | twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) 26 | result = twitter.update_status(status=msg) 27 | return result 28 | else: 29 | abort(400) 30 | 31 | if __name__ == '__main__': 32 | app.run() 33 | --------------------------------------------------------------------------------