-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_infobox.py
31 lines (26 loc) · 1 KB
/
add_infobox.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
import requests
import json
import time
# Load the combined response
file_path = "combined_response.json"
with open(file_path, 'r') as file:
data = json.load(file)
# Function to fetch infobox detsnails
def fetch_infobox(uri):
base_url = 'https://meldeplattform-rad.muenchenunterwegs.de'
url = base_url + uri
response = requests.get(url)
return response.json()
# Add infobox details to each feature
total_features = len(data['features'])
for i, feature in enumerate(data['features']):
infobox_uri = feature['properties'].get('infobox_uri')
if infobox_uri:
infobox_data = fetch_infobox(infobox_uri)
feature['properties']['infobox_data'] = infobox_data
print(f"Processed {i + 1} of {total_features} elements")
time.sleep(0.5) # Sleep to avoid hitting the server too hard
# Save the updated data to a new file
with open('updated_combined_response.json', 'w') as file:
json.dump(data, file, indent=4)
print("Updated data saved to updated_combined_response.json")