I’d like to configure HA to trigger every 5 minutes, and scrape a website of police/ems dispatches. A pyscript should interpret that data and update a hass-helper, as well as determine whether to notify me (notification service already setup)
I already have a python script working by itself, but I could not get the pyscript jupyter kernel to work, so I am looking for some guidance on how to integrate this with HA.
What I have so far:
def scrape():
# DONE: hits the url
# DONE: parses html
# DONE: returns the datetimes, and dispatches
def keep(cutoff_datetime, keywords, payload):
# the payload is the dispatches, plus datetimes
# DONE: current_last_known is from the payload
# DONE: filters the results to only dispatches that I want (are local, with keywords, since the prior_last_known
# DONE: returns the dispatches I would care about (if any)
def main():
# DONE: payload = scrape()
# TBD: retrieve hass-helper prior_last_known?
# DONE: calculate current_last_known from the data
# DONE: keep(prior_last_known, keywords, payload)
# DONE: check if the results are empty
# TBD: if NOT, call a service to notify (this is already configured)
# TBD: update hass-helper prior_last_known to the current_last_known
A couple of questions:
(a) any glaring issues with my logic here
(b) any pointers, examples of similar pyscripts that I can use to complete this?
(c) will the timing/trigger have to be in this script, or will I be able to do a time-trigger in a different automation, and then call service - main() as the action?