zele-utils/main.py

77 lines
2.7 KiB
Python
Raw Normal View History

2024-09-07 18:13:36 -04:00
import typer, geopandas, requests, shapely
from bs4 import BeautifulSoup
from zipfile import ZipFile
from typing_extensions import Annotated
from typing import Optional
from pathlib import Path
from enum import Enum
from functions import process_population, push_population, population_write
from functions import process_network, push_network, network_write
from functions import process_metro, push_metro, metro_write
from functions import process_bus, push_bus, bus_write
app = typer.Typer()
class City(str, Enum):
mtl = "mtl"
class DBMode(str, Enum):
drop = "drop"
amend = "amend"
class RTMode(str, Enum):
online = "online"
offline = "offline"
@app.command()
def population(
file: Annotated[Path, typer.Argument(help="Relative path to the file.", show_default=False)],
cleandata: bool = typer.Option(False, "--cleandata", "-cd", help="Clean the data if this flag is used."),
push: bool = typer.Option(False, "--push", "-p", help="Push the data into Database."),
mode: Optional[DBMode] = typer.Option(None, help="Specify either 'amend' or 'drop' when pushing data", show_default=False),
):
if not file.exists():
print("File did does not exist!")
raise typer.Exit()
data = process_population(file,cleandata)
if push:
push_population(data, mode)
else:
population_write(data)
@app.command()
def network(
file: Annotated[Path, typer.Argument(help="Relative path to the file.", show_default=False)],
cleandata: bool = typer.Option(False, "--cleandata", "-cd", help="Clean the data if this flag is used."),
push: bool = typer.Option(False, "--push", "-p", help="Push the data into Database."),
mode: Optional[DBMode] = typer.Option(None, help="Specify either 'amend' or 'drop' when pushing data", show_default=False),
):
if not file.exists():
print("File did does not exist!")
raise typer.Exit()
data = process_network(file,cleandata)
if push:
push_network(data, mode)
else:
network_write(data)
@app.command()
def metro(
city: Annotated[City, typer.Argument(..., help="Choose a city", show_default=False)],
mode: Annotated[RTMode, typer.Argument(..., help="Choose a city", show_default=False)],
address: Annotated[str, typer.Argument(..., help="enter a relative path or URL", show_default=False)],
):
print(f"Hello {city}")
@app.command()
def bus(
city: Annotated[City, typer.Argument(..., help="Choose a city", show_default=False)],
mode: Annotated[RTMode, typer.Argument(..., help="Choose a city", show_default=False)],
address: Annotated[str, typer.Argument(..., help="enter a relative path or URL", show_default=False)],
):
print(f"Hello {city}")
if __name__ == "__main__":
app()