This project is a prototype API that returns political representative details for a given U.S. ZIP code.
It demonstrates database design, web scraping, API development using Flask, and basic LLM integration for data extraction.
- Database Schema for:
- Geography (ZIP, City, State, District)
- Representatives (Name, Title, Party, Branch)
- Mapping between Geography & Representatives
- API Endpoint:
- Input: ZIP Code (e.g.,
zip=11354) - Output: JSON with Representative Details
- Input: ZIP Code (e.g.,
- Scraping + LLM Integration:
- Uses Google Gemini API +
BeautifulSoupfor representative data extraction.
- Uses Google Gemini API +
- Prototype Demo:
- Supports one or two ZIP codes as proof-of-concept.
├── app.py # Flask API for fetching representatives
├── scraper\_gemini.py # Scraping + LLM extraction + DB insertion
├── setup\_database.py # Creates SQLite DB & inserts initial data
├── civic\_tracker.db # SQLite Database (auto-generated)
├── requirements.txt # Python dependencies
└── README.md # Project Documentation
git clone https://github.com/<your-username>/civic-tracker-api.git
cd civic-tracker-apipython -m venv venv
source venv/bin/activate # For Mac/Linux
venv\Scripts\activate # For Windowspip install -r requirements.txtCreate a .env file in the root directory:
GOOGLE_API_KEY=your_google_gemini_api_key_herepython setup_database.pyFetch representative details for sample ZIP codes:
python scraper_gemini.pypython app.pyThe API will start on http://127.0.0.1:5000.
GET /representatives?zip=<ZIP_CODE>
GET http://127.0.0.1:5000/representatives?zip=11354
{
"zip": "11354",
"representatives": [
{ "name": "Grace Meng", "title": "U.S. House Rep, NY-6" },
{ "name": "Chuck Schumer", "title": "U.S. Senator, NY" },
{ "name": "Kathy Hochul", "title": "Governor, New York" }
]
}Tables:
- geography: Stores ZIP, City, State, District
- representatives: Stores Representative Details
- rep_geography_map: Many-to-Many Mapping Table
- Python (Flask, Requests, BeautifulSoup)
- SQLite for lightweight storage
- Google Gemini API for LLM-based data extraction
Video Demo Link : https://drive.google.com/file/d/1Fg7OYozHXtNWU2QfWw4aPktkLxYc2gDh/view?usp=sharing
Your Name Email: [email protected] GitHub: @sarth-04