-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgg.py
More file actions
37 lines (31 loc) · 1.13 KB
/
gg.py
File metadata and controls
37 lines (31 loc) · 1.13 KB
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
import requests
from xml.etree import ElementTree
# Define the Overpass API endpoint
url = "http://overpass-api.de/api/interpreter"
# Define the Overpass query to get all districts in Japan in English, including place IDs
query = """
[out:xml];
area["ISO3166-1"="JP"][admin_level=2];
(node["place"="city"]["name:en"](area);
way["place"="city"]["name:en"](area);
rel["place"="city"]["name:en"](area);
);
out body;
"""
# Send the query to the Overpass API
response = requests.post(url, data={'data': query})
# Check if the request was successful
if response.status_code == 200:
# Parse the XML response
root = ElementTree.fromstring(response.content)
# Extract district names in English and their IDs
districts = []
for element in root.findall('.//tag[@k="name:en"]/..'):
name_en = element.find('./tag[@k="name:en"]').get('v')
place_id = element.get('id')
districts.append((name_en, place_id))
# Print the district names in English and their IDs
for name_en, place_id in districts:
print(f"Name: {name_en}, Place ID: {place_id}")
else:
print("Failed to retrieve data:", response.status_code)