Skip to content

Commit

Permalink
feat: Calculate and filter priority disturbances, currently threshold…
Browse files Browse the repository at this point in the history
… is higher than 35
  • Loading branch information
spleiner committed Aug 27, 2024
1 parent b39fb2a commit 96d1998
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions slussen.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,48 @@ def get_departures(timestamp):
return departures


@st.cache_data
def get_deviations(timestamp):
deviations = []
sites = ["9192", "1321"]
sitestring = ""
for site in sites:
sitestring += f"&site={site}"
headers = {"Content-Type": "application/json"}
url = f"https://deviations.integration.sl.se/v1/messages?future=true{sitestring}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
for deviation in data:
for message in deviation["message_variants"]:
if (
deviation["priority"]["importance_level"]
* deviation["priority"]["influence_level"]
* deviation["priority"]["urgency_level"]
> 35
):
if message["language"] == "sv":
deviationinfo = {
"header": message["header"],
"details": message["details"],
}
deviations.append(deviationinfo)
else:
return deviations

return deviations


timestamp = time.strftime("%Y%m%d%H%M")
departuredata = get_departures(timestamp)
deviationdata = get_deviations(timestamp)

if deviationdata:
with st.expander("**:red[Trafikstörningar]**", icon="🚨"):
for deviation in deviationdata:
st.error(f"**{deviation['header']}**")
st.write(deviation["details"])


if departuredata == []:
st.error("Inga avgångar hittades")
Expand Down

0 comments on commit 96d1998

Please sign in to comment.