A simple Flask-based voting application. Users vote for candidates for a list of posts. Votes are stored in a JSON file on the server. A results endpoint calculates winners and an Excel export can be generated via result.py.
- Interactive voting UI (JavaScript + Flask backend)
- Dark / light theme toggle
- JSON persistence of vote counts
- Endpoint to update vote data (
POST /updatejson) - Endpoint to fetch current data (
GET /getjson) - Endpoint to fetch winners (
GET /results) - Script to build initial candidate list from a posts text file (
import-data.py) - Script to export winners to Excel (
result.py)
server.py- Flask app and API endpointsrun.py- Entry point to run the dev servertemplates/index.html- Voting page templatestatic/Js/main.js- Voting logic (fetch/update JSON)templates/Data/Data.json- Persisted vote dataresult.py- Functions to compute winners and export to Excelimport-data.py- Interactive script to seed candidate datamerge.py- Merges two JSON vote files (for aggregating results)
- Create and activate a virtual environment (optional but recommended).
- Install dependencies:
pip install -r requirements.txt - Seed candidate data (optional):
Select your
python import-data.pyPosts.txtfile when prompted and enter candidate names. - Run the server:
python run.py - Open
http://127.0.0.1:8000in your browser to vote.
GET /getjsonreturns the full vote data array.POST /updatejsonaccepts the full updated vote data array and overwrites the JSON file.GET /resultsreturns an object mapping each post to the winning candidate.
[
{
"post": "Owner",
"candidates": [
{"name": "Alice", "votes": 3},
{"name": "Bob", "votes": 5}
]
}
]Run:
python result.py
This creates results.xlsx listing each post and the winning candidate.
If you collected votes in separate JSON files, place a second file named final.json beside merge.py containing the same structure and edit the paths if needed, then run:
python merge.py
It sums votes per candidate (matching by position and order) and rewrites final.json with merged totals.
- Add per-user authentication & one-vote-per-user enforcement
- Record individual ballots rather than only aggregated counts
- Input form for creating posts and candidates via the web interface
- Add unit tests (pytest) for validation and result logic
- Better error handling and logging
Currently unspecified. Add a license file if you intend to distribute.