-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (32 loc) · 1.49 KB
/
Copy pathmain.py
File metadata and controls
37 lines (32 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import plotly.express as px
from backend import get_data
# Add title, text input, slider, selectbox, and subheader
st.title("Weather Forecast for the Next Days")
place = st.text_input("Place: ")
days = st.slider("Forecast Days", min_value=1, max_value=5,
help="Select the number of forecasted days")
option = st.selectbox("Select data to view",
("Temperature", "Sky"))
st.subheader(f"{option} for the next {days} days in {place}")
if place:
# Get the temperature/sky data
try:
filtered_data = get_data(place, days)
if option == "Temperature":
temperatures = [dict["main"]["temp"] / 10 for dict in filtered_data]
dates = [dict["dt_txt"] for dict in filtered_data]
# Create temperature plot
figure = px.line(x=dates, y=temperatures, labels={"x": "Date", "y": "Temperature (C)"})
st.plotly_chart(figure)
if option == "Sky":
images = {"Clear":"images/clear.png",
"Clouds":"images/cloud.png",
"Rain":"images/rain.png",
"Snow":"images/snow.png"}
sky_conditions = [dict["weather"][0]["main"] for dict in filtered_data]
image_paths = [images[condition] for condition in sky_conditions]
print(sky_conditions)
st.image(image_paths, width=115)
except KeyError:
st.write("Tha place does not exist")