osmus / teachosm.org

The TeachOSM website
http://teachosm.org
Apache License 2.0
43 stars 19 forks source link

publish the URL of the API #243

Open mfrasca opened 2 years ago

mfrasca commented 2 years ago

in my experience it is useful to allow outsiders query the tasking manager through the API, let us collect statistics, or to get the bounding polygon a specific task.

on hotosm.org, they keep it at https://tasking-manager-tm4-production-api.hotosm.org/ where is it on teachosm.org?

one of my use cases, as said, is getting the polygon:

#!/usr/bin/env python3

import sys
import requests

if len(sys.argv) != 2:
    sys.exit(-1)

info = requests.get(f"https://tasking-manager-tm4-production-api.hotosm.org/api/v2/projects/{sys.argv[1]}/queries/aoi/")
print("""\
<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' upload='never' generator='JOSM'>""")

i = 0
points = info.json()['coordinates'][0][0]

for point in points:
    i += 1
    print(f"  <node id='-{i}' lat='{point[1]}' lon='{point[0]}' />")

print(f"  <way id='-{len(points)}'>")

for i in range(len(points)):
    print(f"    <nd ref='-{i+1}' />")
print("    <nd ref='-1' />")

print("""\
  </way>
</osm>""")