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 for fetching, parsing and storing election night results #6

Open
gordonje opened this issue Sep 28, 2016 · 5 comments
Open

Script for fetching, parsing and storing election night results #6

gordonje opened this issue Sep 28, 2016 · 5 comments
Assignees

Comments

@gordonje
Copy link
Owner

Here is what I did last time around: https://github.com/gordonje/MO_votes_2014/blob/master/get_data.py

@NathanLawrence
Copy link
Collaborator

My suggested structure (from #3, where I had put it before by mistake):

Use a function that takes in an elections results URL as string. Inside that function, parse the XML out into a nice, clean Python dict (object type ducked from var = {}), then push that out wherever you need it with Python's built-in json.dumps(dict) function.

@gordonje
Copy link
Owner Author

gordonje commented Oct 19, 2016

Other stuff this script needs:

  • Adding key/values for FIPs to counties (and any other county-level data, number of voters perhaps)
  • Conditional formatting of the results:
    • Each contested statewide constitutional office race (type "State of Missouri") should be its own type
    • Ballot measures "races" will all be under their own type, but instead of including a candidates list, there will be 'yes_votes' and 'no_votes' attributes on each county.
    • Some of the judicial races are similar, allowing for voting yes or no for each candidate. James is a liar
  • We should probably check the <ElectionResults LastUpdated=...> before saving the XML to s3 or writing to the database (I think?) If not, then our own 'last_updated' attribute of the election_results table items should probably just be the current date time.
  • Batch writing of table items? unnecessary

@NathanLawrence
Copy link
Collaborator

@qbscarlie and @DanielLevitt32, any progress on these, namely the FIP pairing? Tempus fugit...

@gordonje
Copy link
Owner Author

@NathanLawrence Shoot. I meant to reference e25b701 wherein I added this.

Does this look right to you? I've made the fips an attribute of each associative array in the counties array. Could also make the counties into an associative array, keyed off of FIPS, but I assume that wouldn't help much, and iterating over the counties would not be as straight-forward.

{
  "last_updated": 1415152662,
  "race_type": "State Senate",
  "races": [
    {
      "counties": [
        {
          "candidates": [
            {
              "id": "750074485",
              "name": "Joseph (Joe) Keaveny",
              "party": "Democratic",
              "votes": "0"
            },
            {
              "id": "750074484",
              "name": "Courtney Blunt",
              "party": "Republican",
              "votes": "0"
            }
          ],
          "fips": "189",
          "name": "St. Louis",
          "reporting_precincts": "0",
          "total_precincts": "24"
        },
        {
          "candidates": [
            {
              "id": "750074485",
              "name": "Joseph (Joe) Keaveny",
              "party": "Democratic",
              "votes": "0"
            },
            {
              "id": "750074484",
              "name": "Courtney Blunt",
              "party": "Republican",
              "votes": "0"
            }
          ],
          "fips": "510",
          "name": "St. Louis City",
          "reporting_precincts": "0",
          "total_precincts": "101"
        }
      ],
      "title": "State Senator - District 4"
    },

@NathanLawrence
Copy link
Collaborator

NathanLawrence commented Oct 24, 2016

I like this layout -- it's exactly what I had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants