Initial commit
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
commit
f0cab2f7c3
54 changed files with 19984 additions and 0 deletions
25
static/hrc/collection.py
Executable file
25
static/hrc/collection.py
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
import requests
|
||||
import csv
|
||||
import time
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
headers = {"User-Agent": "Hard Rock Cafe Blog Post From Julien Riou"}
|
||||
session = requests.Session()
|
||||
session.headers.update(headers)
|
||||
|
||||
with open("collection_with_coordinates.csv", "w") as dest:
|
||||
writer = csv.writer(dest)
|
||||
with open("collection.csv", "r") as source:
|
||||
for row in csv.reader(source):
|
||||
name = row[0]
|
||||
r = session.get(f"https://nominatim.openstreetmap.org/search?q={name}&limit=1&format=json")
|
||||
time.sleep(1)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
if len(data) == 1:
|
||||
data = data[0]
|
||||
writer.writerow([name, data["lon"], data["lat"]])
|
||||
else:
|
||||
print(f"Location not found for {title}, skipping")
|
Loading…
Add table
Add a link
Reference in a new issue