Last active
August 28, 2015 13:07
-
-
Save breyten/2b8c756f03d3e23772c0 to your computer and use it in GitHub Desktop.
Query NPO backstage API for the name of a person.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
from BeautifulSoup import BeautifulSoup | |
NPO_BACKSTAGE_BASE_URL = 'http://backstage-api.npo.nl' | |
NPO_BACKSTAGE_ENDPOINT_SEARCH = '/v0/search' | |
def get_politician_count(politician, session): | |
SEARCH_DATA = { | |
"query": politician['name'], | |
"size": 20 | |
} | |
response = session.post( | |
NPO_BACKSTAGE_BASE_URL + NPO_BACKSTAGE_ENDPOINT_SEARCH, | |
data=json.dumps(SEARCH_DATA) | |
) | |
return response.json()['hits'].get('total', 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment