Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to pull georgia nov 24 presidential election #2063

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/scrapers/georgia-results-downloader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# georgia-results-downloader

### Overview

Extract the per-county results in Georgia for the November 2024 presidential race to help our audit specialists track the audit.

1. Open the “index.html” file, this should open in a browser such as Chrome
2. Click “Download Results” and wait for ~5-10 seconds as it downloads
3. Open the downloaded file - “GA_presidential_results_nov_2024.csv”
14 changes: 14 additions & 0 deletions scripts/scrapers/georgia-results-downloader/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
margin: 2rem;
}

.heading {
align-items: center;
display: flex;
}

.icon {
height: 2rem;
margin-right: 0.5rem;
width: 2rem;
}
15 changes: 15 additions & 0 deletions scripts/scrapers/georgia-results-downloader/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Georgia Results Downloader</title>
<link rel="stylesheet" type="text/css" href="./index.css">
</head>
<body>
<h1 class="heading"><img class="icon" src="./vx.svg" />Georgia Results Downloader</h1>
<p><button id="downloadResultsButton">Download Results</button></p>
<script src="./papaparse.min.js"></script>
<script src="./index.js"></script>
</body>
</html>
78 changes: 78 additions & 0 deletions scripts/scrapers/georgia-results-downloader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
document
.getElementById("downloadResultsButton")
.addEventListener("click", async () => {
try {
const response = await fetch(
"https://results.sos.ga.gov/cdn/results/Georgia/export-2024NovGen.json"
);
if (!response.ok) throw new Error("Network response was not ok");

const jsonData = await response.json();
const rows = transformData(jsonData);
createAndDownloadCSV(rows);
} catch (error) {
console.error("Error fetching or processing JSON:", error);
alert("Failed to fetch or process the data.");
}
});

// Transform data from json to rows
function transformData(jsonData) {
const rows = [];

const localResults = jsonData.localResults;
localResults.forEach((jurisdiction) => {
const row = {
Jurisdiction: jurisdiction.name.replace(" County", ""),
"Donald J. Trump (Rep) - SoS Results": 0,
"Kamala D. Harris (Dem) - SoS Results": 0,
"Chase Oliver (Lib) - SoS Results": 0,
"Jill Stein (Grn) - SoS Results": 0,
};

const ballotItems = jurisdiction.ballotItems;
const presidentialItem = ballotItems[0];
const presidentialOptions = presidentialItem.ballotOptions;
presidentialOptions.forEach((option) => {
row[option.name + " - SoS Results"] = option.voteCount;
});

rows.push(row);
});

// Sort rows by Jurisdiction name
rows.sort((a, b) => a.Jurisdiction.localeCompare(b.Jurisdiction));

const totalResults = jsonData.results;
const presidentialTotal = totalResults.ballotItems[0];
const presidentialTotalOptions = presidentialTotal.ballotOptions;
const totalRow = {
Jurisdiction: "Total",
};
presidentialTotalOptions.forEach((option) => {
totalRow[option.name + " - SoS Results"] = option.voteCount;
});

rows.push(totalRow);
return rows;
}

// Create and download CSV
function createAndDownloadCSV(rows) {
const csvContent = Papa.unparse({
data: rows,
});

const blob = new Blob([csvContent], {
type: "text/csv;charset=utf-8;",
});
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "GA_presidential_results_nov_2024.csv";
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
Loading