Skip to content

Commit

Permalink
etl script to use routemodel etl
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-lam committed Oct 24, 2023
1 parent 86f1463 commit e855ce5
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
17 changes: 17 additions & 0 deletions etl2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ETL Usage

#### 1. Make sure you're in a virtual environment and have all the requirements installed:

```
virtualenv venv --python=python3.10
./venv/Scripts/activate
pip install -r requirements.txt
```

#### 2. Run the ETL script. The script will guide you through its usage:

```
python etl.py
```

That's it!
82 changes: 82 additions & 0 deletions etl2/etl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from pathlib import Path

import psycopg2
import questionary
from termcolor import colored
from etl_routemodel.etl_routemodel import main as run_routemodel_etl


def validate_db_creds(db_user, db_password, db_host, db_name):
host, port = db_host.split(":")
try:
conn = psycopg2.connect(
host=host, port=port, user=db_user, password=db_password, dbname=db_name
)
conn.close()
return True
except:
return False


def validate_path(path, extension):
path = Path(path).absolute()
return path.is_file() and path.suffix == extension


def cmd_routemodel():
answers = questionary.form(
gpx_json_filepath=questionary.path(
"Path to GPX data (JSON file)",
default="",
validate=lambda p: validate_path(p, ".json"),
),
db_host=questionary.text("Database host:port", default=""),
db_name=questionary.text("Database name", default=""),
db_user=questionary.text("Database user", default=""),
db_password=questionary.password("Database user password", default=""),
confirm=questionary.confirm(
"Confirm routemodel ETL operation",
default=False,
auto_enter=False,
),
).ask()

gpx_json_filepath, db_user, db_password, db_host, db_name, confirm = map(
answers.get,
(
"gpx_json_filepath",
"db_user",
"db_password",
"db_host",
"db_name",
"confirm",
),
)
if not confirm:
print(colored("routemodel ETL cancelled", "red"))
elif confirm and validate_db_creds(db_user, db_password, db_host, db_name):
run_routemodel_etl(gpx_json_filepath, db_user, db_password, db_host, db_name)
print(colored("routemodel ETL success", "green"))
else:
print(colored("Incorrect database credentials", "red"))


def cmd_weather():
...


if __name__ == "__main__":
print(
colored(
"Using this ETL script requires your database to be updated and working with db_gateway",
"yellow",
)
)
etl_name = questionary.select(
"Select ETL operation", choices=["routemodel", "weather"]
).ask()

if etl_name == "routemodel":
cmd_routemodel()
elif etl_name == "weather":
cmd_weather()
4 changes: 4 additions & 0 deletions etl2/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ geopy==2.4.0
greenlet==3.0.0
numpy==1.26.1
pandas==2.1.1
prompt-toolkit==3.0.36
psycopg2-binary==2.9.9
python-dateutil==2.8.2
pytz==2023.3.post1
questionary==2.0.1
six==1.16.0
soupsieve==2.5
SQLAlchemy==2.0.22
termcolor==2.3.0
typing_extensions==4.8.0
tzdata==2023.3
wcwidth==0.2.8

0 comments on commit e855ce5

Please sign in to comment.