-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_user_projects.py
48 lines (35 loc) · 1.47 KB
/
get_user_projects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Lists projects a mapper joined, including number of mapped and validated tasks
#!/usr/bin/python3
import json
import sys
import urllib.parse
import urllib.request
from termcolor import colored
def main():
if len (sys.argv) == 2:
user = sys.argv[1]
else:
print ("Usage: hot_tm_get_user_projects <username>")
return 1
req = urllib.request.Request ("https://" + urllib.parse.quote ("tasking-manager-tm4-production-api.hotosm.org/api/v2/projects/queries/" + user + "/touched/"),
headers={"accept": "application/json", "Accept-Language": "en"}
)
with urllib.request.urlopen (req) as response:
res = json.loads (response.read ())
if "Error" in res:
print (res["Error"])
return 1
if len (res["mappedProjects"]) < 0:
print ("no projects mapped or validated so far")
return 1
for proj in res["mappedProjects"]:
print ("--------------------------------------")
print (proj["projectId"], ": ", proj["name"])
print (colored(" https://tasks.hotosm.org/projects/" + str(proj["projectId"]), "green"))
print (" mapped ", proj["tasksMapped"])
if proj["tasksValidated"] > 0:
print (colored(" validated " + str(proj["tasksValidated"]), "red"))
else:
print (" validated: NONE")
if __name__ == "__main__":
main()