Skip to content

About

Analysis for me to decide which state house district to run in

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Georgia State House District Analysis

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.

Overview

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.

Components

1. Data Extraction

  • 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.

2. District Analysis

  • district_analysis/analysis.py: Generates detailed reports for each district using Google's Gemini AI, incorporating both scraped data and demographic PDFs.

Available Data

  • 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

Usage

  1. Ensure all required dependencies are installed and API keys are set in your .env file.

  2. Run the data extraction script:

    python data_extraction/extract_district_history.py
    

    This will populate the districts.json file with structured data for all 180 districts.

  3. 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/.

  4. Review the generated report to assess the viability of running in that district.

APIs and Environment Variables

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

API Usage

  1. Firecrawl API: Used for web scraping Ballotpedia pages. Sign up at Firecrawl to obtain an API key.

  2. OpenAI API: Utilized for processing and structuring the scraped data. You'll need an API key from OpenAI.

  3. 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.

Customization

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.

Note

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.

About

Analysis for me to decide which state house district to run in

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages