A village charity fundraises using a lottery bonus-ball game for local residents. A solution was required to make game administration simpler for the people running it.
Players each have one or more bonus balls allocated. They win if their number matches the drawn number for that week.
This app enables a lottery bonus ball game coordinator to manage players, their allocated numbers and weekly draws for the game through a simple password-protected UI.
A cron job on an AWS EC2 instance runs weekly to execute a script that gets the bonus ball from the weekly draw website and adds it to the database in the app. The app provides a UI and coordinator(s) are emailed the result and winner following a weekly draw.
myscript.cron
# https://fauzan186.medium.com/how-to-add-django-custom-command-in-cron-57b5606f4ea4
# https://jainsaket-1994.medium.com/installing-crontab-on-amazon-linux-2023-ec2-98cf2708b171
#
# Run scheduled_task every sat at 8pm
0 20 * * 6 { printf "\%s: " "$(date "+\%F \%T")"; /home/ec2-user/venv/bin/python /home/ec2-user/wv-lottery/manage.py scheduled_task ; } >> /home/ec2-use>
#
# Test
#* * * * * { printf "\%s: " "$(date "+\%F \%T")"; /home/ec2-user/venv/bin/python --version ; } >> /home/ec2-user/test_cron.log 2>&1
Run this script
$ crontab MyScript.cron
Some useful commands
$ crontab -l (Check current running cron job)
$ crontab -r (Remove cron job)
- Clone the repository
- Set-up a python 3.9 virtual environment
- Install dependencies from the project root with
pip install -r requirements.txt
- Create the local
db.sqlite3
database withpython manage.py migrate
- Create a superuser with
python manage.py createsuperuser
- Run the web interface with
python manage.py runserver
and log-in with the user account you created in the previous step 7You may also use the admin interface to create other app users: append/admin
to the url in the browser to access the admin site
Optionally:
- Deploy the cron script above to an AWS EC2 instance (charges may apply) with a copy of the repo code, or alternatively manually enter the draw result in the app (this option does not provide email notifications).
- The helper script
create_balls.py
can be used to create bonus balls withpython manage.py shell < create_balls.py