-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (37 loc) · 1.31 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Main script."""
#!/usr/bin/env python3
import configparser
from pathlib import Path
from toolbelt.duckdb_database_handling import (
database_exists, create_database,
execute_query_on_db,
install_load_extension
)
# Config
config = configparser.ConfigParser()
config.read("config.ini")
# Get db_path
db_path = Path(config["DuckDB"]["db_path"])
# Overture maps
release = Path(config["OvertureMaps"]["release"])
xmin = Path(config["OvertureMaps"]["xmin"])
xmax = Path(config["OvertureMaps"]["xmax"])
ymin = Path(config["OvertureMaps"]["ymin"])
ymax = Path(config["OvertureMaps"]["ymax"])
# Create database if not exists
if not database_exists(db_path):
create_database(db_path)
# Install needed extension in database
install_load_extension(db_path)
for table in ['admins', 'places', 'buildings', 'transportation'] :
# Download OvertureMaps data
with open(f"sql/{table}.sql", "r", encoding="utf-8") as file:
sql_script = file.read()
sql_script = sql_script.format(millesime=release,
xmin=xmin,
xmax=xmax,
ymin=ymin,
ymax=ymax
)
execute_query_on_db(sql_script, db_path, f"Download {table}")
g