|
18 | 18 |
|
19 | 19 | print(' ', c.country, c.polygon_id)
|
20 | 20 |
|
| 21 | + # polygon_id can be an integer, or a list of integers |
| 22 | + polygon_id = c.polygon_id |
| 23 | + if isinstance(polygon_id, int): |
| 24 | + polygon_id = (polygon_id, ) |
| 25 | + |
21 | 26 | # generate relation boundary
|
22 |
| - try: |
23 |
| - r = requests.post(relation_generation_url, params={'id': c.polygon_id}, data={'refresh': 1}, timeout=120) |
24 |
| - except requests.exceptions.Timeout: |
25 |
| - print(" Timeout") |
26 |
| - fails.append([c.country, c.polygon_id, 'Timeout']) |
27 |
| - continue |
28 |
| - if r.status_code == 500: |
29 |
| - print(" Geom Error -", r.url) |
30 |
| - fails.append([c.country, c.polygon_id, 'Geom Error']) |
31 |
| - continue |
32 |
| - elif r.status_code != 200: |
33 |
| - print(" Error -", r.url) |
34 |
| - fails.append([c.country, c.polygon_id, 'Error']) |
| 27 | + relation_failing = False |
| 28 | + for poly_id in polygon_id: |
| 29 | + try: |
| 30 | + r = requests.post(relation_generation_url, params={'id': str(poly_id)}, data={'refresh': 1}, timeout=120) |
| 31 | + except requests.exceptions.Timeout: |
| 32 | + print(" Timeout") |
| 33 | + fails.append([c.country, polygon_id, 'Timeout']) |
| 34 | + relation_failing = True |
| 35 | + continue |
| 36 | + if r.status_code == 500: |
| 37 | + print(" Geom Error -", r.url) |
| 38 | + fails.append([c.country, polygon_id, 'Geom Error']) |
| 39 | + relation_failing = True |
| 40 | + continue |
| 41 | + elif r.status_code != 200: |
| 42 | + print(" Error -", r.url) |
| 43 | + fails.append([c.country, polygon_id, 'Error']) |
| 44 | + relation_failing = True |
| 45 | + continue |
| 46 | + |
| 47 | + if relation_failing: |
35 | 48 | continue
|
36 | 49 |
|
37 | 50 | # get associated poly file
|
38 | 51 | try:
|
39 |
| - r = requests.get(polygon_union_url, params={'id': c.polygon_id, 'params': 0}, timeout=120) |
| 52 | + poly_id = ",".join(map(str, polygon_id)) |
| 53 | + r = requests.get(polygon_union_url, params={'id': poly_id, 'params': 0}, timeout=120) |
40 | 54 | except requests.exceptions.Timeout:
|
41 | 55 | print(" Poly Timeout")
|
42 |
| - fails.append([c.country, c.polygon_id, 'Poly Timeout']) |
| 56 | + fails.append([c.country, polygon_id, 'Poly Timeout']) |
43 | 57 | continue
|
44 | 58 | if r.status_code != 200:
|
45 | 59 | print(" Bad geom -", r.url)
|
46 |
| - fails.append([c.country, c.polygon_id, 'Bad geom']) |
| 60 | + fails.append([c.country, polygon_id, 'Bad geom']) |
47 | 61 |
|
48 | 62 | if len(fails) > 0:
|
49 | 63 | print(fails)
|
|
0 commit comments