SLElectionLive is a Flask-based web application that provides real-time election results for Sri Lanka. It features an interactive dashboard with charts, a live news stream, and an SMS campaign interface. The application scrapes data from results.elections.gov.lk and uses Chart.js for visualizations, Bootstrap for styling, and a responsive design for accessibility across devices.
Explore the live application at https://sl-election-live.vercel.app/. View real-time election results, news updates, and manage SMS campaigns.
- Live Election Results Dashboard: Displays vote shares, seats, and party details with an interactive doughnut chart.
- Real-Time News Stream: Fullscreen news mode with voter turnout, social sharing, and automatic updates every 30 seconds.
- SMS Campaign Interface: Manage and send SMS campaigns for election updates.
- Dark Mode: Toggle between light and dark themes for better usability.
- Responsive Design: Optimized for desktop, tablet, and mobile devices.
- Data Scraping: Fetches live election data from
results.elections.gov.lkusing BeautifulSoup. - Fallback Data: Uses sample data when API or scraping fails, ensuring uninterrupted service.
SLElectionLive/
├── api/
│ ├── app.py # Flask application with routes and scraping logic
│ ├── sample_data.py # Generates sample election data for fallback
│ ├── templates/
│ │ ├── index.html # Election results dashboard
│ │ ├── news.html # Live news stream page
│ │ ├── sms_campaign.html # SMS campaign interface
├── packages.json # Node.js configuration (optional for Vercel)
├── requirements.txt # Python dependencies
├── test.py # Test script for development
├── vercel.json # Vercel deployment configuration
├── README.md # This file
Follow these steps to set up the project locally:
-
Clone the Repository:
git clone https://github.com/Ishanoshada/SLElectionLive.git cd SLElectionLive -
Create a Virtual Environment:
python -m venv venv
-
Activate the Virtual Environment:
- On Windows:
venv\Scripts\activate
- On Linux/Mac:
source venv/bin/activate
- On Windows:
-
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables:
- Create a
.envfile in the root directory:touch .env
- Add necessary configurations (e.g., API keys, if used):
FLASK_ENV=development SECRET_KEY=your_secret_key
- Create a
-
Run the Application:
python api/app.py
- The app will be available at
http://localhost:5000.
- The app will be available at
- Dashboard (
/): View the latest election results with a chart and table of party details. - News Stream (
/news): Access live updates with voter turnout, social sharing buttons, and navigation for recent results. - SMS Campaign (
/sms_campaign): Manage SMS campaigns for election notifications. - Dark Mode: Click the moon/sun icon in the navbar to toggle themes.
- Fullscreen Mode: On the news page, click the fullscreen button for an immersive view.
To test with sample data:
- Modify
app.pyto forceuse_sample_data=Trueor simulate a failed API call.
- Use
gunicornfor production-like local testing:gunicorn -w 4 -b 0.0.0.0:8000 api.app:app
The project includes vercel.json and packages.json, suggesting Vercel compatibility. To deploy:
- Install the Vercel CLI:
npm install -g vercel
- Deploy from the project root:
vercel
- Follow prompts to configure the project (ensure
api/app.pyis the entry point). - Update
vercel.jsonif needed to map routes correctly.
- Heroku: Push to a Heroku app with
Procfile:web: gunicorn api.app:app - Render: Configure as a Python web service with
requirements.txt.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature/your-feature
- Commit changes:
git commit -m "Add your feature" - Push to the branch:
git push origin feature/your-feature
- Open a pull request on
https://github.com/Ishanoshada/SLElectionLive.
Please follow the Code of Conduct and include tests in test.py for new features.
This project is licensed under the MIT License. See the LICENSE file for details.
- Created by: Ishanoshada
- Source Code: https://github.com/Ishanoshada/SLElectionLive
- Data Source: results.elections.gov.lk

