North Carolina is the definition of a battleground state; since 1992, with only one exception, we have elected a Democratic governor at the same time as a Republican president, and every year the margins grow closer.
On election night, news organizations were already posting about close contests and recounts. The most high-profile case has been for a seat on the North Carolina Supreme Court between Allison Riggs and Jefferson Griffin. While Griffin initially led, Riggs took the lead later. The margin has been razor-thin even during recounts.
I thought it might be interesting to look at which races were the closest in this election. So, instead of refreshing the State Board of Elections’ website every five minutes, I decided to tackle an election-night coding project to take the edge off.
My goal was to write an application which would generate a report of the closest contests in this election.
My first task was finding the data. I went back to the Election Night Dashboard hosted by the State Board of Elections. That page had been updating regularly all night as more election results came in, so my assumption was that it was feeding off an API.
I was right! The website was pulling data from a few different endpoints which generally lined up with the filters that were on the page: which election, which county, which contest type, and which individual contest. Interestingly, each of the endpoints is served as a .txt file, despite returning valid JSON.
By searching through each of the endpoints, I was able to put together a pretty comprehensive understanding of how the dashboard works. From that, I spent a few hours building the app out, and along the way decided to futureproof (and pastproof) it; it’ll work with all elections that there’s data for, going back to 1992 – before I was born!
As of now, it can produce an HTML report that lists out the races that match your criteria. There are a number of other options that it has; you can explore the code at AriannaStory/CloseNCElections on GitHub. Let me know what you think! 🙂
By the way, this is my first time writing a blog post like this, so I’d love some feedback! You can reach me on Bluesky at @ari.codes.