44from weather_forecast .forecast import WeatherForecast
55import matplotlib .pyplot as plt
66
7+
78class SkyCast :
89 def __init__ (self ):
910 self .geolocation_model = GeolocationModel ()
@@ -15,16 +16,16 @@ def title(self):
1516 st .markdown (
1617 '<div style="border: 1px solid #ccc; padding: 20px; border-radius: 10px;">'
1718 '<h1 style="text-align: center; color: #0080FF;">SkyCast 🌤️</h1>'
18- ' </div>' ,
19- unsafe_allow_html = True
19+ " </div>" ,
20+ unsafe_allow_html = True ,
2021 )
2122
2223 def input (self ):
2324 st .sidebar .title ("Weather Options" )
2425 self .weather_option = st .sidebar .radio (
2526 "Choose Weather Option" ,
2627 options = ["Today's Weather" , "Forecast Weather" ],
27- key = "weather_option"
28+ key = "weather_option" ,
2829 )
2930
3031 if self .weather_option == "Today's Weather" :
@@ -33,7 +34,6 @@ def input(self):
3334 self .display_forecast_weather ()
3435
3536 def display_today_weather (self ):
36-
3737 latitude , longitude = None , None
3838 # Manually enter the city name
3939 city_name = st .sidebar .text_input ("Enter City Name" , key = "city_name" )
@@ -43,8 +43,10 @@ def display_today_weather(self):
4343 # If the submit button is not clicked, do not proceed further
4444 return
4545
46-
47- st .markdown (f"<h2 style='text-align: center;'>Today's Weather</h2>" , unsafe_allow_html = True )
46+ st .markdown (
47+ f"<h2 style='text-align: center;'>Today's Weather</h2>" ,
48+ unsafe_allow_html = True ,
49+ )
4850
4951 if latitude is not None and longitude is not None :
5052 # Make API request
@@ -58,7 +60,7 @@ def display_today_weather(self):
5860 # Date and time
5961 st .markdown (
6062 f'<h3 style="text-align: center;">{ weather_data ["city_name" ]} , { weather_data ["country_code" ]} : { datetime_value } </h3>' ,
61- unsafe_allow_html = True
63+ unsafe_allow_html = True ,
6264 )
6365
6466 # Additional weather information
@@ -71,7 +73,9 @@ def display_today_weather(self):
7173 st .markdown (f'Visibility: { weather_data ["vis" ]} km' )
7274
7375 with col2 :
74- st .markdown (f'Weather Description: { weather_data ["weather" ]["description" ]} ' )
76+ st .markdown (
77+ f'Weather Description: { weather_data ["weather" ]["description" ]} '
78+ )
7579 st .markdown (f'Wind Direction: { weather_data ["wind_cdir_full" ]} ' )
7680 st .markdown (f'UV Index: { weather_data ["uv" ]} ' )
7781 st .markdown (f'Dew Point: { weather_data ["dewpt" ]} °C' )
@@ -80,29 +84,41 @@ def display_today_weather(self):
8084 st .write ("Location not found." )
8185
8286 def display_forecast_weather (self ):
83-
8487 latitude , longitude = None , None
8588 # Manually enter the city name
8689 city_name = st .sidebar .text_input ("Enter City Name" , key = "city_name" )
87- days = st .sidebar .number_input ("How Many days do you want to Forecast" , key = "days" , value = 1 , min_value = 1 , step = 1 , format = "%d" )
90+ days = st .sidebar .number_input (
91+ "How Many days do you want to Forecast" ,
92+ key = "days" ,
93+ value = 1 ,
94+ min_value = 1 ,
95+ step = 1 ,
96+ format = "%d" ,
97+ )
8898
8999 if st .sidebar .button ("Submit" ):
90100 latitude , longitude = self .geolocation_model .get_location_by_name (city_name )
91101 else :
92102 # If the submit button is not clicked, do not proceed further
93103 return
94- st .markdown (f"<h2 style='text-align: center;'>Forecast Weather</h2>" , unsafe_allow_html = True )
104+ st .markdown (
105+ f"<h2 style='text-align: center;'>Forecast Weather</h2>" ,
106+ unsafe_allow_html = True ,
107+ )
95108
96109 if latitude is not None and longitude is not None :
97110 # Create an instance of the WeatherForecast class
98- weather = WeatherForecast (latitude , longitude , self .api_key ,days )
111+ weather = WeatherForecast (latitude , longitude , self .api_key , days )
99112
100113 # Retrieve the weather forecast data
101114 forecast_df = weather .get_weather_forecast ()
102115
103116 # Show forecast data
104117 for i in range (len (forecast_df )):
105- st .markdown (f'<h3 style="text-align: center;">{ forecast_df ["date" ][i ]} </h3>' , unsafe_allow_html = True )
118+ st .markdown (
119+ f'<h3 style="text-align: center;">{ forecast_df ["date" ][i ]} </h3>' ,
120+ unsafe_allow_html = True ,
121+ )
106122
107123 col1 , col2 = st .columns (2 )
108124
@@ -113,7 +129,9 @@ def display_forecast_weather(self):
113129 st .markdown (f'Visibility: { forecast_df ["visibility" ][i ]} km' )
114130
115131 with col2 :
116- st .markdown (f'Weather Description: { forecast_df ["weather_description" ][i ]} ' )
132+ st .markdown (
133+ f'Weather Description: { forecast_df ["weather_description" ][i ]} '
134+ )
117135 st .markdown (f'Wind Direction: { forecast_df ["wind_direction" ][i ]} ' )
118136 st .markdown (f'UV Index: { forecast_df ["uv_index" ][i ]} ' )
119137 st .markdown (f'Dew Point: { forecast_df ["dew_point" ][i ]} °C' )
@@ -123,22 +141,38 @@ def display_forecast_weather(self):
123141 max_temp = forecast_df ["max_temp" ]
124142 date = forecast_df ["date" ]
125143
126- st .set_option (' deprecation.showPyplotGlobalUse' , False )
144+ st .set_option (" deprecation.showPyplotGlobalUse" , False )
127145 plt .figure (figsize = (10 , 6 )) # Set the figure size
128146
129147 # Plot the temperature line
130- plt .plot (date , temp , label = 'Temperature' , marker = 'o' , linestyle = '-' , color = 'blue' )
148+ plt .plot (
149+ date , temp , label = "Temperature" , marker = "o" , linestyle = "-" , color = "blue"
150+ )
131151
132152 # Plot the minimum temperature line
133- plt .plot (date , min_temp , label = 'Min Temperature' , marker = 'o' , linestyle = '-' , color = 'green' )
153+ plt .plot (
154+ date ,
155+ min_temp ,
156+ label = "Min Temperature" ,
157+ marker = "o" ,
158+ linestyle = "-" ,
159+ color = "green" ,
160+ )
134161
135162 # Plot the maximum temperature line
136- plt .plot (date , max_temp , label = 'Max Temperature' , marker = 'o' , linestyle = '-' , color = 'red' )
163+ plt .plot (
164+ date ,
165+ max_temp ,
166+ label = "Max Temperature" ,
167+ marker = "o" ,
168+ linestyle = "-" ,
169+ color = "red" ,
170+ )
137171
138172 # Set the labels and title
139- plt .xlabel (' Date' )
140- plt .ylabel (' Temperature (°C)' )
141- plt .title (' Temperature Forecast' )
173+ plt .xlabel (" Date" )
174+ plt .ylabel (" Temperature (°C)" )
175+ plt .title (" Temperature Forecast" )
142176
143177 # Add a legend
144178 plt .legend ()
@@ -154,7 +188,7 @@ def get_weather_data(self, latitude, longitude):
154188 "lat" : latitude ,
155189 "lon" : longitude ,
156190 "key" : self .api_key ,
157- "include" : "minutely"
191+ "include" : "minutely" ,
158192 }
159193 try :
160194 response = requests .get (self .base_url , params = params )
@@ -174,4 +208,4 @@ def get_weather_data(self, latitude, longitude):
174208
175209# Display the title and input fields
176210weather_forecast .title ()
177- weather_forecast .input ()
211+ weather_forecast .input ()
0 commit comments