-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_data.py
More file actions
19 lines (15 loc) · 826 Bytes
/
get_data.py
File metadata and controls
19 lines (15 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
import requests
data_dir = 'data/'
countries = requests.get('https://restcountries.eu/rest/v2/all?fields=name;alpha2Code').json()
# download stats for each country
for country in countries:
code = country['alpha2Code']
print(code)
response = requests.get('https://api.wigle.net/api/v2/stats/regions?country={}'.format(code)).json()
with open('{}stats_regions_{}.json'.format(data_dir, code), 'w+') as new_file:
json.dump({ 'name': country['name'], 'code': response['country'], 'encryption': response['encryption'] }, new_file)
# download wifi count for all countries
response = requests.get('https://api.wigle.net/api/v2/stats/countries').json()
with open('{}stats_countries_wifi_count.json'.format(data_dir), 'w+') as stats_countries_file:
json.dump(response, stats_countries_file)