Skip to content

Instantly share code, notes, and snippets.

@belzebub40k
Created February 16, 2022 12:53
Show Gist options
  • Save belzebub40k/8c348cb0fe30039e7a73057c1ad5c26b to your computer and use it in GitHub Desktop.
Save belzebub40k/8c348cb0fe30039e7a73057c1ad5c26b to your computer and use it in GitHub Desktop.
fetch all Freifunk API entries from directory.api.freifunk.net
#!/usr/bin/env python3
import json
import requests
URL = "https://raw.githubusercontent.com/freifunk/directory.api.freifunk.net/master/directory.json"
for community, url in requests.get(URL).json().items():
try:
res = requests.get(url)
except Exception as e:
print(community, e)
continue
print(community, res.status_code)
if res.status_code == 200:
try:
data = res.json()
with open('communities/%s.json' % community.replace('/','_'), 'w') as f:
json.dump(data, f, indent=True, sort_keys=True)
except Exception as e:
print(community, e)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment