diff --git a/src/data/azure_function_timer/function_app.py b/src/data/azure_function_timer/function_app.py index 8d37854..47e63ec 100644 --- a/src/data/azure_function_timer/function_app.py +++ b/src/data/azure_function_timer/function_app.py @@ -1,16 +1,38 @@ import azure.functions as func import datetime import json +import urllib.request import logging app = func.FunctionApp() +# https://techcommunity.microsoft.com/blog/adforpostgresql/connect-from-function-app-with-managed-identity-to-azure-database-for-postgresql/1517032 @app.timer_trigger( - schedule="* * * * * *", arg_name="myTimer", run_on_startup=False, use_monitor=False + schedule="*/3 * * * * *", + arg_name="myTimer", + run_on_startup=False, + use_monitor=False, ) def Timer(myTimer: func.TimerRequest) -> None: if myTimer.past_due: logging.info("The timer is past due!") - logging.info("Python timer trigger function executed.") + + endpoint = "https://binghamtonupublic.etaspot.net/service.php?service=get_vehicles&token=TESTING" + contents = urllib.request.urlopen(endpoint).read() + try: + vehicles = json.loads(contents)["get_vehicles"] + time = datetime.datetime.now() + seconds = int( + (time - datetime.datetime(1970, 1, 1)).total_seconds() % (3600 * 24) + ) + for vehicle in vehicles: + route = vehicle["routeID"] + equipment = vehicle["equipmentID"] + lattitude = vehicle["lat"] + longitude = vehicle["lng"] + logging.info(f"{route},{equipment},{lattitude},{longitude},{seconds}") + except Exception as e: + logging.error(e) + raise e