Youtube uses pubsubhub to send push notifications for new video uploads. This app subscribes when a user requests a channel ID to be linked to a subreddit. This handshake occurs when the app acknowledges the GET request from pubsubhub by serving its challenge in the http response (seen as request.args["hub.challenge"]
). Now we should receive POST requests containing XML data about the new uploads for the YT channel the app is subscribed to. This app then regularly keep leases from pubsubhub "fresh" by renewing leases in its database that may expire in the near future.
/pubsubhub/hook
the hook to use with pubsubhub/subscriptions/new
endpoint for creating a new subscription for a channel + subreddit
zappa deploy production
this will also create the bucket specified in thes3_bucket
section ofzappa_settings.json
- Ensure that an
env.json
is in the bucket project- ex: if
"remote_env": "s3://zappa-yt-pubsub-handler-production/env.json"
then theenv.json
should be place in the appropriate bucket after deploy
- ex: if
- Set up db:
zappa invoke production 'yt_pubsub_handler.db_utils.init_db'
{
"DATABASE_URL": "postgresql+psycopg2://user:pw@host/production",
"SECRET_KEY": "dev", // see Flask docs for how to generate
"client_id": "", // reddit client id for account that makes posts
"client_secret": "", // reddit client_secret
"reddit_password": "", // reddit pw
"reddit_username": "", // reddit user
"URL_ROOT": "https://root_of_your_site/" // for working outside flask request context
}
Flask-Migrate is used for migrations.
- Start a local flask session with
./local_dev.sh
- Edit
yt_pubsub_handler/models.py
with your intended changes - In a seperate terminal, make sure env variable is set:
export FLASK_APP=yt_pubsub_handler
- Run
flask db migrate
to automatically create a revision in themigrations/versions
folder- Review this thoroughly and make any changes, alembic auto-generates these and they may sometimes contain flaws
- Commit your changes and submit PR. Once merged to master
zappa update production
will push the revision to the prod environment - to execute the migration in production:
zappa invoke production 'run.run_alembic_upgrade'
- for downgrade simply use
run_alembic_downgrade
instead
- for downgrade simply use