This repository contains tools and scripts to analyze Georgia State House districts, helping potential candidates assess which district might be most favorable for a campaign run.
This project scrapes data from Ballotpedia, extracts relevant information about each district, and generates comprehensive reports to aid in decision-making for potential Democratic candidates.
data_extraction/district_history.py: Defines Pydantic models for structuring district election history and demographic data.data_extraction/extract_district_history.py: Scrapes Ballotpedia for district information, processes it using OpenAI's GPT model, and saves the structured data.
district_analysis/analysis.py: Generates detailed reports for each district using Google's Gemini AI, incorporating both scraped data and demographic PDFs.
- Ballotpedia information:
source_data/ballotpedia_information/district_[NUMBER].md - Demographic PDFs:
source_data/district_pdfs/district_[NUMBER].pdf - Generated reports:
source_data/district_reports/district_[NUMBER].md
-
Ensure all required dependencies are installed and API keys are set in your
.envfile. -
Run the data extraction script:
python data_extraction/extract_district_history.pyThis will populate the
districts.jsonfile with structured data for all 180 districts. -
Generate an analysis for a specific district:
python district_analysis/analysis.py [DISTRICT_NUMBER]This will create a detailed report in
source_data/district_reports/. -
Review the generated report to assess the viability of running in that district.
This project uses several external APIs to gather and process data. You'll need to set up the following environment variables in a .env file in the root directory of the project:
FIRECRAWL_API_KEY=your_firecrawl_api_key
OPENAI_API_KEY=your_openai_api_key
GOOGLE_GEMINI_API_KEY=your_google_gemini_api_key
-
Firecrawl API: Used for web scraping Ballotpedia pages. Sign up at Firecrawl to obtain an API key.
-
OpenAI API: Utilized for processing and structuring the scraped data. You'll need an API key from OpenAI.
-
Google Gemini API: Employed for generating detailed district analysis reports. Obtain an API key from the Google AI Studio.
Ensure you have valid API keys for all these services before running the scripts. Keep your .env file secure and never commit it to version control.
You can modify the prompts in extract_district_history.py and analysis.py to tailor the analysis to your specific needs or to focus on particular aspects of the districts.
This tool is designed to provide data-driven insights, but should be used in conjunction with on-the-ground knowledge and additional research for the most comprehensive understanding of a district's political landscape.