CatDataPages
Source code for a Flask website populated with data from the CatAPI, hosted on Render.
Cat-Data-Pages.onrender.com
Contents
Motivation
Make an interesting, fun page using data on cat breeds provided from The Cat API. Include details on data processing for demonstration/education.
Features
Cat Breed Information
- List index of data pages for each breed
- Side-by-side comparison page
- Choropleth map of cat breed origins
JSON API
- Detailed descriptions with examples
Description | Scheme | |
---|---|---|
Random Cat Image | random cat image, updated every 10 minutes | api/image |
Breed Names | list of cat breeds, helpful for data requests | api/names |
Cat Breed Data | type info / stats / graph for a specified or random cat |
api/<cat>/<type> info, stats, graphs |
Data Demonstration
- Pages detailing how the CatAPI data was processed and presented
- Pandas, Matplotlib, and Plotly code demonstration and discussion
- Pages analyzing the overall data distributions
Deployment
The current version of this project was built with Python 3.10, and the packages listed in requirements.txt.
pip install -r requirements.txt
Render
Cat-Data-Pages can be run in earlier Python versions using the more general requirements for render, which does not list specific package versions.
pip install -r render_requirements.txt
This was utilized to avoid build errors in Render.
# settings
Name = Cat-Data-Pages
Branch = main
Build Command = pip install --upgrade pip setuptools wheel && pip install -r requirements_render.txt
Start Command = gunicorn -w 2 app:app
# testing "gunicorn --workers=2 --threads=4 app:app" for start command
# environment
PYTHON_VERSION = 3.10.9
TZ = America/Los_Angeles
gthread worker type used instead of sync if threads > 1
Local Installation
This project can be deployed locally using the default Flask Werkzeug server. Download the source code to a directory and see the Flask documentation help setting up a virtual environment, installing requirements, and options for running the application.
Run in debug mode:
cd your-directory
# activate virtual environment
flask --debug run
Updates
This project was recently updated (Dec 2021 --> Dec 2022) as I moved it to Render from Heroku.
- Documentation on Github
- will leave sparse and provide links to project and/or screenshots
- Improved formatting for some pages, mainly widened margins
- source code links in data story pages, version list in homepage footer
- Bugfixes for saving graphs (create folder if not exists), and generating map
- Changed method of saving random cat image
- from txt file with link --> JSON file with dictionary --> storing dictionary in memory
- cleaned up code a little, changed to class
- added try / except block in case of empty return from thecatapi
- Simple API and description page
- Returns URL, time remaining for random cat image
- Returns list of cat names to facilitate other requests
- Returns graphs/information/stats for a particular or random cat
- Gunicorn deployment on Render, associated requirements file
- optimizing # workers / threads . . .
- Jan 2023
- updated code for change in cat breed URL
- added note in data cleaning page, accordingly
- changed app to prepopulate all matplotlib graphs on startup, should provide faster responses to cat pages
- this takes ~20s per cat, or about 25 minutes on the free plan
- formatting changes to homepage and api info page
- updated code for change in cat breed URL