Heroku app to view GNIB appointments
published: (updated: )
by Harshvardhan J. Pandit
is part of: GNIB Appointments
GNIB server visa web-dev
source: hosted on Github here
webapp: hosted on Heroku here shows available timings for GNIB and Visa appointments
The good thing about a script is that they can be run pretty much anywhere, such as a dedicated web-server, or the phone (through some tedious efforts), a raspberry pi, or through free services like heroku.
In this post, I describe setting up the appointment script on a heroku instance. The appointments are refreshed every 30mins (a resonable time), and can be viewed at any time using this website.
Heroku is a PaaS service, which means that it takes care of everything and lets you focus only on the web browser part of it. It provides 50 free instances for apps, which can be accessed using the address https://app-name.herokuapp.com. Oh, and free HTTPS! Heroku provides app support for a large variety of languages, which (on the date of this post) include Node.js, Ruby, Python, Java, PHP, Go, Scala, and Clojure. There is support for more languages, which can be checked through official documentation.
Publishing apps on heroku requires an account, which is free to sign up. The free tier gives access to 1000 free hours of compute time which can be used in as many instances as you want, though I think the number is limited to 50. Each app/instance or as heroku terms it - dyno - is automatically suspended after 30 mins of inactivity. That means that it starts (and is a little slow) after 30 mins of no-one using the app. Each dyno has access to 512MB of RAM (generous!) and can perform operations on a single CPU (thread/worker).
Deployment can be made by using the heroku toolbelt which are a set of utilities that help with version control and pulling logs from the app instance. Or the app can be connected to a git repository online such as Github so that commits are automatically deployed to the app.
Procfile specifies the command and parameters for heroku to use when running the instance.
The procfile should be situated in the base directory of the app. For a simple, single dyno, free app,
the procfile specifies the command
web: command --arguments as a way to specify that the dyno
is of type
web (as opposed to
worker) and starting it will run
command with the specified
Heroku supports third-party libraries which (in the case of python) can be specified using
requirements.txt. Any library in this file will be installed before starting the app.
Bottle is a small, minimal python web framework that provides routing
and templates and is very easy to run. Bottle is a single file library/module. Since the requirements
of the GNIB project are simple, the project contains just one file -
app.py. It uses much of the same
code as specified in the last post to perform the actual requests.
Gunicorn is a python WSGI HTTP server, which in plain-speak means that it handles requests and lets bottle do the routing and actual work of generating page responses. The following snippet runs gunicorn with bottle.
run( debug=True, server='gunicorn', host='0.0.0.0', port=int(env.get("PORT", 5000)))
Checking appointments every 30 minutes
Since our free app contains only a
web worker without any background processes, we use a simple
if-then-else conditional to check if it has been more than 30 mins since we last checked appointments.
from datetime import datetime last_checked = None def check(): if last_checked is None: get_appointments() last_checked = now else: now = datetime.now() diff = now - last_checked if diff.days > 0 or diff.seconds > 1800: get_appointments() last_checked = now
- Retrieve Visa appointments
- Chrome extension