Last active
August 30, 2024 21:19
-
-
Save mvexel/284c3c03b3ee801ea9d4409d4132a258 to your computer and use it in GitHub Desktop.
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
import csv | |
import requests | |
mr_challenge_list_endpoint = "https://maproulette.org/api/v2/challenges?limit={limit}&page={page}" | |
mr_challenge_endpoint = "https://maproulette.org/api/v2/challenge/{id}" | |
page = 0 | |
limit = 100 | |
instr_list = [] | |
while True: | |
try: | |
resp = requests.get(mr_challenge_list_endpoint.format( | |
limit=limit, | |
page=page) | |
).json() | |
if len(resp) == 0: | |
break | |
except ConnectionError: | |
print("failed connection") | |
for item in resp: | |
id = item["id"] | |
try: | |
challenge = requests.get( | |
mr_challenge_endpoint.format(id=id)).json() | |
instructuction = challenge["instruction"] | |
instr_list.append([id, instructuction]) | |
except ConnectionError: | |
print("failed connection") | |
continue | |
print(f"{limit * (page + 1)} challenges processed") | |
page += 1 | |
with open("instructions.csv", "w") as fh: | |
writer = csv.writer(fh) | |
writer.writerows(instr_list) | |
print("done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment