Parul-23 commited on
Commit
8419767
·
verified ·
1 Parent(s): edea5dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
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": Mumbai,
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
- city = st.text_input("Enter city name")
22
- if city:
23
- data = get_weather_data(city)
24
- if data["cod"] == 200:
25
- weather = data["weather"][0]["description"]
26
- temperature = data["main"]["temp"]
27
- humidity = data["main"]["humidity"]
28
- wind_speed = data["wind"]["speed"]
29
- st.write(f"Weather in {city}: {weather}")
30
- st.write(f"Temperature: {temperature}°C")
31
- st.write(f"Humidity: {humidity}%")
32
- st.write(f"Wind Speed: {wind_speed} m/s")
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()