Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,9 @@ API_KEY = "ce6b189b71e3e5d00019ab59aa6e38fe" # Replace with your OpenWeatherMap
|
|
| 6 |
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
|
| 7 |
|
| 8 |
# Function to fetch weather data
|
| 9 |
-
def get_weather_data(city):
|
| 10 |
params = {
|
| 11 |
-
"q":
|
| 12 |
"appid": API_KEY,
|
| 13 |
"units": "metric"
|
| 14 |
}
|
|
@@ -17,21 +17,19 @@ def get_weather_data(city):
|
|
| 17 |
|
| 18 |
# Streamlit app
|
| 19 |
def main():
|
| 20 |
-
st.title("Weather App")
|
| 21 |
-
|
| 22 |
-
if
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
else:
|
| 34 |
-
st.write("City not found. Please try again.")
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
main()
|
|
|
|
| 6 |
BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
|
| 7 |
|
| 8 |
# Function to fetch weather data
|
| 9 |
+
def get_weather_data(city="Chennai"):
|
| 10 |
params = {
|
| 11 |
+
"q": city,
|
| 12 |
"appid": API_KEY,
|
| 13 |
"units": "metric"
|
| 14 |
}
|
|
|
|
| 17 |
|
| 18 |
# Streamlit app
|
| 19 |
def main():
|
| 20 |
+
st.title("Weather App for Chennai")
|
| 21 |
+
data = get_weather_data()
|
| 22 |
+
if data["cod"] == 200:
|
| 23 |
+
weather = data["weather"][0]["description"]
|
| 24 |
+
temperature = data["main"]["temp"]
|
| 25 |
+
humidity = data["main"]["humidity"]
|
| 26 |
+
wind_speed = data["wind"]["speed"]
|
| 27 |
+
st.write(f"Weather in Chennai: {weather}")
|
| 28 |
+
st.write(f"Temperature: {temperature}°C")
|
| 29 |
+
st.write(f"Humidity: {humidity}%")
|
| 30 |
+
st.write(f"Wind Speed: {wind_speed} m/s")
|
| 31 |
+
else:
|
| 32 |
+
st.write("Failed to fetch weather data for Chennai.")
|
|
|
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
main()
|