Prize Bond Draw is a web application for managing prize bonds which are a unique method of investment that are essentially lotteries backed by the government.
- This is a full stack web application that supports all the CRUD operations.
- Supports role based mechanism to authorize the users.
Admin
Can add denominations and their respective prizes, update the winning list and announce the notifications to all the users.User
Can store their bond serials and check the results of either all of their serials or by entering any particular serial.
- One unique feature is that you can add your bond serial by just uploading their picture.
If you would like to read more about how prize bond works then check out this link Prize Bond.
NOTE: I have made this website in accordance with how the prize bond works in Pakistan only and I am not sure of the process followed in other countries.
Here's the breif overview of the tech stack I have used:
-
This project uses Flask Microframework. Flask is a open source python web framework that is built with only minimalistic features and easy to extend philosophy.
-
For data storage the project uses Postgresql which is an open source relational database.
-
Various other flask extension have been used to further extend the functionalities as flask only provides the core features.
-
For the User Interface the project uses HTML/CSS , Javascript and Bootstrap V5.0.
-
For the extraction of serial and denomination from the bond picture, the project uses Microsoft Azure Optical Character Recognition service.
- Install Postgresql on Ubuntu.
sudo apt update
sudo apt install postgresql postgresql-contrib
- Access the postgres prompt by running.
sudo -u postgres psql
- Create a new database and the user.
CREATE DATABASE prizebond_draw_db;
CREATE USER prizebond_draw_user WITH PASSWORD 'password';
- Now grant the access rights to our newly created database user.
GRANT ALL PRIVILEGES ON DATABASE prizebond_draw_db TO prizebond_draw_user;
- Now exit the shell.
/q
Make sure you have python3 and pip3 installed.
- Clone the repository and navigate to the project directory.
git clone https://github.com/zain2323/prizebond-draw.git
cd prizebond-draw
- Activate the virtual environment.
source venv/bin/activate
- Install this package first as it is a required dependency for psycopg2 library.
sudo apt install python3-dev libpq-dev
- Now install all the required dependencies.
pip3 install -r requirements.txt
- Create Microsoft Azure account if you don't have one.
- To obtain
subscription_key
andendpoint
refer to this official guide.
- navigate to the project directory.
cd prizebond-draw
- Copy the
secrets.json
file to the/etc/
directory.
sudo cp secrets.json /etc/
- To generate a secret key for the project run this script in the python shell and copy the output string.
import secrets
secrets.token_hex()
- Now open the secrets.json file.
sudo nano /etc/secrets.json
- Replace all the necessary details in the file with the correct one.
{
"SECRET_KEY": "<PASTE YOUR SECRET KEY HERE>",
"MAIL_USERNAME":"<USERNAME>",
"MAIL_PASSWORD": "<PASSWORD>",
"EMAIL": "<EMAIL>",
"DB_PASSWORD": "<DB_PASSWORD>",
"DB_ROLE": "<DB_ADMIN>",
"DB_NAME": "<DB_NAME>",
"HOST": "<DB_SERVER>",
"SUBSCRIPTION_KEY": "<YOUR MICROSOFT AZURE SUBSCRIPTION_KEY>",
"ENDPOINT": "<YOUR MICROSOFT AZURE ENDPOINT>"
}
- Make sure to save all the changes.
If you are running this application locally then
"HOST": "localhost"
- Initialize the flask environment variable and run the migration script to setup the database schema.
export FLASK_APP=run.py
flask db upgrade
- To run the application execute this command.
flask run
Now navigate to the localhost:5000
on your browser to use the application.
Hosted with ❤️ by Azure
This project uses Github Actions for the deployment.