newsdev / elex

A wrapper for the AP v2 Elections API.
Other
170 stars 53 forks source link

Allow requesting of specific office type(s) #320

Closed mileswwatkins closed 6 years ago

mileswwatkins commented 6 years ago

Use case: we want to gather county-level data for some races, but only state-level data for other races.

This is easy enough to do if the county-level data's for president, since that has a known and constant raceID and elex supports the syntax --raceids 0. Since the races we're following are all "national," elex's --national-only flag doesn't help us differentiate. So unless we provide all the desired raceIDs to elex, there's no support for, say, fetching only governor's races.

This is supported concisely in the AP Elections API using the officeID parameter.

mileswwatkins commented 6 years ago

@vv-qian, also note that the valid officeID values are documented in the repo already: https://github.com/newsdev/elex/blob/master/elex/api/maps.py#L150-L169

These may come in handy if you have to raise an exception, or elsewhere. For example, instead of erroring with a message like 'F' is not a valid 'officeID' value, you could instead offer the user suggestions for what values are valid.

palewire commented 6 years ago

This would be a good feature to add. You want to put together a pull request?

mileswwatkins commented 6 years ago

Yup, was getting @vv-qian prepped to tackle it, and checking with @jeremyjbowers that it was a useful feature to have for users outside of @nprapps. Vanessa's working on the PR and I'll do an initial review, she'll give y'all an @-mention (and remove the WIP from the PR title) when it's ready for ya.