-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (25 loc) · 1.24 KB
/
main.py
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
import streamlit as st
import plotly.express as px
from fore_backend import get_data
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:
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]
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 = [dict["weather"][0]["main"] for dict in filtered_data]
image_paths = [images[condition] for condition in sky]
print(sky)
st.image(image_paths,width=118)
except KeyError:
st.write("That Place does not Exit...... \n Write Correct Place.")