Created
February 16, 2022 12:53
-
-
Save belzebub40k/8c348cb0fe30039e7a73057c1ad5c26b to your computer and use it in GitHub Desktop.
fetch all Freifunk API entries from directory.api.freifunk.net
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 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