Skip to content

Instantly share code, notes, and snippets.

@mvexel
Last active August 30, 2024 21:19
Show Gist options
  • Save mvexel/284c3c03b3ee801ea9d4409d4132a258 to your computer and use it in GitHub Desktop.
Save mvexel/284c3c03b3ee801ea9d4409d4132a258 to your computer and use it in GitHub Desktop.
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