Skip to content

Instantly share code, notes, and snippets.

@hoosteeno
Created October 24, 2013 23:11
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 hoosteeno/7146759 to your computer and use it in GitHub Desktop.
Save hoosteeno/7146759 to your computer and use it in GitHub Desktop.
Get the number of Mozillians in every country.
import requests
def get_some(offset):
r = requests.get('https://mozillians.org/api/v1/countries/', params = {
'app_name': 'get_your_own',
'app_key': 'get_your_own',
'format': 'json',
'limit': 500,
'offset': offset,
'is_vouched': 'true'
})
return r
offset = 0
countries = {}
while offset is not None:
response = get_some(offset)
payload = response.json()
offset = payload['meta'].get('next')
for country in payload['objects']:
name = country['country_name']
# this because https://bugzilla.mozilla.org/show_bug.cgi?id=929718
if name in countries:
countries[name] += country.get('population')
else:
countries[name] = country.get('population')
for country in sorted(countries.keys()):
print(country + "," + str(countries[country]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment