Building a COVID-19 API off NCDC’s website
In the wake of this pandemic I wanted to make myself useful and build something simple and at the same time put my web scrapping skills to use. So I decided to build an API off NCDC’s website (https://covid19.ncdc.gov.ng/) and be able to use it to build an information bot using Twilio’s whatsapp sandbox. Well this write up is just focused on building the API used in the information bot and as you can guess it was built using python.
For this project I made use of Flask and its restful library and hosted this on heroku. This is the result of this project. https://ncdcapi.herokuapp.com/ .For the full code of this project you can visit my young Github repo. => https://github.com/jideilori/ncdc-api
Step 1. Getting data from NCDC’s website.
After getting the response from NCDC’s website. “lxml” and “cssselect” was used to get the necessary information which included summary of cases for all states in the country. Below is the snippet which extracts the necessary information.
Step 2. Passing the scraped data to the flasks Restful API
Step 3. Hosting on heroku
In order to host your webapp on heroku you will need three things.
1. Procfile — notice the capital ‘P’. this simply just specifies the commands that are excuted by the app on startup. Well mine contained just one line.
web: gunicorn app:app
2. requirements.txt — This can be gotten by doing pip freeze > requirements.txt in your virtualenv of course else it will generate a file with all globally installed python libraries on machine. Always work with a virtualenv when you are building any deployable project(django, flask etc).
3. runtime.txt — which just simply specifies the python version
python-3.6.7
· After you have gotten this three files. Simply upload them to your github repo.
· Create a heroku account if you don’t have one and create a new app
· Click on the deploy tab link it up to your github repo. A password might be required.
· Then click deploy and wait for it to install and that’s it.
Conclusion
Anytime the link is visited. It actually gets new data from the site and returns a JSON format which can be used for a lot of things. Like what I used it for — an info bot using Twilio’s whatsapp sandbox. Which is currently hosted on Twilio and can be accessed by adding +14155238886 and messaging among-model then say Hi or by clicking the link https://api.whatsapp.com/send?phone=14155238886&text=join%20among-model