not putting into postgres atm but logging everything
This commit is contained in:
parent
17548fec12
commit
a7d993861d
1 changed files with 24 additions and 2 deletions
|
@ -1,16 +1,38 @@
|
||||||
import azure.functions as func
|
import azure.functions as func
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import urllib.request
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
app = func.FunctionApp()
|
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(
|
@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:
|
def Timer(myTimer: func.TimerRequest) -> None:
|
||||||
if myTimer.past_due:
|
if myTimer.past_due:
|
||||||
logging.info("The timer is past due!")
|
logging.info("The timer is past due!")
|
||||||
|
|
||||||
logging.info("Python timer trigger function executed.")
|
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
|
||||||
|
|
Loading…
Reference in a new issue