For this lab you will create a basic site statistics app using Flask and Redis, and deploy it to Heroku.
Follow the instructions in the Getting Started Guide to install Heroku/the Heroku Toolbelt on your machine. After you have entered your Heroku credentials at the command line, continue to step 2.
Clone this repository to your computer. Navigate to the project directory and delete the existing .git folder.
- From the project directory, type
git init
to initialize a fresh git repo, then add and commit all of the files. - Type
heroku create
to create a new heroku app. Heroku will respond with the URL for your new site, something like "Creating wandering-pines-3938... done, stack is cedar, http://wandering-pines-3938.herokuapp.com" - Give the app a better name than the autogenerated one with
heroku rename "newname"
. For example,heroku rename "iloveiolab"
will change the name of the app to iloveiolab and the address will now be http://iloveiolab.herokuapp.com. - Install the redis add-on for your site with
heroku addons:add redistogo
Deploy the test app to Heroku with git push heroku master
. Go to the app's URL in the browser and verify you see a page appear. Refresh the page and watch the counter go up.
Right now the app only keeps track of the number of hits. Modify the code so that it also keeps a log of what operating system visitors are using (hint: take a look at Flask's request.user_agent output, and the python module httpagentparser). Print the result to the index.html page. For example:
Windows: 10
Mac: 1
If you have time, log the user's browser as well, and make a visualization of the data (pie chart? bar chart?)