Skip to content

Commit a0c313d

Browse files
committed
Final saving function.
1 parent 174628f commit a0c313d

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

exploratory/osm_download.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,27 @@ def process_element(element_etree: ET.ElementTree) -> tuple[pd.DataFrame, pd.Dat
163163

164164
versions_list = []
165165
changes_list = []
166+
failed_rows = []
166167

167168
for idx, row in elements_table.iterrows():
168169
print(f" Row {idx}: type={row['type']}, id={row['id']}")
169170
history_url = f"https://api.openstreetmap.org/api/0.6/{row['type']}/{row['id']}/history"
170-
history_response = requests.get(history_url, timeout = TIMEOUT)
171+
try:
172+
history_response = requests.get(history_url, timeout = TIMEOUT)
173+
except Exception as e:
174+
print(f"Failed to get history for row {idx}: {e}")
175+
failed_rows.append(row)
176+
time.sleep(1)
177+
continue
171178
history_etree = ET.fromstring(history_response.text)
172179
versions_df, changes_df = process_element(history_etree)
173180
versions_list.append(versions_df)
174181
changes_list.append(changes_df)
175182
if idx % 100 == 0:
176183
print(f"Processed {idx} rows")
177-
pd.concat(versions_list).to_csv('osm_versions.csv', index = False)
178-
pd.concat(changes_list).to_csv('osm_changes.csv', index = False)
184+
185+
versions_df = pd.concat(versions_list)
186+
changes_df = pd.concat(changes_list)
187+
188+
versions_df.to_csv('osm_versions.csv', index = False)
189+
changes_df.to_csv('osm_changes.csv', index = False)

0 commit comments

Comments
 (0)