diff --git a/amarillo/app/utils/__init__.py b/amarillo/app/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/amarillo/app/utils/container.py b/amarillo/app/utils/container.py new file mode 100644 index 0000000..5cc69ed --- /dev/null +++ b/amarillo/app/utils/container.py @@ -0,0 +1,2 @@ + +container = {} \ No newline at end of file diff --git a/amarillo/app/utils/utils.py b/amarillo/app/utils/utils.py new file mode 100644 index 0000000..51a48e6 --- /dev/null +++ b/amarillo/app/utils/utils.py @@ -0,0 +1,40 @@ +import os +import re +from datetime import datetime, date, timedelta +from pyproj import Geod + +def assert_folder_exists(foldername): + if not os.path.isdir(foldername): + os.makedirs(foldername) + + +def agency_carpool_ids_from_filename(carpool_filename): + """ + Returns agency_id, carpool_id from a carpool filename. + It is assumed, that carpool_filename matches the regex + /([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+).json$ + """ + m = re.search(r'\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)\.json$', carpool_filename) + if m: + return m[1], m[2] + else: + return None, None + +def is_older_than_days(date_to_check, number_of_days): + if date_to_check is None: + return True + if isinstance(date_to_check, datetime): + date_to_check = date_to_check.date() + return date_to_check < date_days_ago(number_of_days) + +def yesterday(): + return date_days_ago(1) + +def date_days_ago(number_of_days): + return date.today() - timedelta(days=number_of_days) + +def geodesic_distance_in_m(coord1, coord2): + geod = Geod(ellps="WGS84") + lons = [coord1[0], coord2[0]] + lats = [coord1[1], coord2[1]] + return geod.line_lengths(lons, lats)[0] \ No newline at end of file diff --git a/amarillo/main.py b/amarillo/main.py index 2db61f3..c27e6a9 100644 --- a/amarillo/main.py +++ b/amarillo/main.py @@ -86,7 +86,7 @@ app = FastAPI(title="Amarillo - The Carpooling Intermediary", import importlib import pkgutil -import amarillo.plugins # FIXME this namespace does not exist if there are 0 plugins installed +import amarillo.plugins diff --git a/pyproject.toml b/pyproject.toml index a85c402..289d973 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,5 +5,6 @@ dependencies = [ "fastapi[all]==0.104.0", "uvicorn[standard]==0.23.2", "pydantic[dotenv]==2.4.2", - "starlette" + "starlette", + "pyproj==3.6.1", ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 770e810..2150765 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ fastapi[all]==0.104.0 uvicorn[standard]==0.23.2 pydantic[dotenv]==2.4.2 -starlette \ No newline at end of file +starlette +pyproj==3.6.1 \ No newline at end of file