Gridiron is a simple quiz platform for testing out out & training your NFL knowledge! This tool primarily leverages:
- Flask (—for serving the single page & hosting the back-end API—) and
- SportRadar (—using their API to retrieve all sorts of league-wide details.)
By default, five different question types are supported & randomly generated with each call to the generateQuestion
endpoint:
"What conference are the {team} in?"
"What division are the {team} in?"
"What team does {player} belong to?"
"Which team is in the {division}?"
"Which of the following is a {position}?"
Once an answer is selected, the question options are passed back to the validateAnswer
endpoint & then completed on the client-side compared against the option the user selected.
- Python 3.10 is required since
typing
definitions using custom classes (—possibly with lists?—) is not supported in <= 3.9. - Registration of a trial SportRadar account to have an API key to use.
Install pre-requisites using pip, then just run the Flask app & navigate to localhost:5000
:
pip install -r requirements.txt
python app.py
If trying to serve this in a public-facing context, a quick (but not robust) solution:
- Install
waitress
viapip
. - Import
serve
fromwaitress
in theapp.py
file. - Replace the Flask-based
app.run
with the Waitress'serve
equivalent.
from waitress import serve
...
# app.run(debug=True)
serve(app, host='0.0.0.0', port=80)
See this useful article for more details regarding hosting Gridiron on your own.
Although waitress
does not currently feature TLS support, you can still set up a reverse proxy through nginx
to finish implementing SSL.
Also, some additional details to keep in mind if hosting externally:
- Make sure to update the URLs referenced in the configuration at the top of the
gridiron.js
file fromlocalhost
to the public-facing URL for CORS to continue working properly. - To prevent abuse,
refresh_cache
can only be triggered locally for force-refreshing the league data (—due to the@local_only
tagging.)
For example:
curl http://localhost:5000/api/v1/refresh_cache
Additional question templates can be added, too!
- Add the new question template underneath the
Question templating
section ofconfig.py
. - Add a new
Enum
under theQuestionType
class ofquestions.py
. - Since new question behavior is automatically compiled when the server starts based on the
@question
tags, simply add a new question definition inquestions.py
with the@question
tag. - Append a new
elif
invalidate_data_by_type
for the answer validation handling infrontend_services.py
. - In
static/js/gridiron.js
, add the corresponding behavior for passing data between thegenerateQuestion
&validateAnswer
functions.
- Create a supplementary script for easier deployment updates in the future.