Skip to content

Instantly share code, notes, and snippets.

@breyten
Last active August 28, 2015 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breyten/2b8c756f03d3e23772c0 to your computer and use it in GitHub Desktop.
Save breyten/2b8c756f03d3e23772c0 to your computer and use it in GitHub Desktop.
Query NPO backstage API for the name of a person.
#!/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