Sanjayraju30 commited on
Commit
8d45176
·
verified ·
1 Parent(s): f3d03f6

Update weather_utils.py

Browse files
Files changed (1) hide show
  1. weather_utils.py +3 -4
weather_utils.py CHANGED
@@ -1,6 +1,6 @@
1
  import requests
2
 
3
- API_KEY = "YOUR_API_KEY" # Replace this with your actual OpenWeatherMap API key
4
 
5
  def get_emoji(condition):
6
  condition = condition.lower()
@@ -16,7 +16,6 @@ def get_emoji(condition):
16
  def get_weather_by_coordinates(lat, lon):
17
  url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_KEY}&units=metric"
18
  response = requests.get(url)
19
-
20
  if response.status_code != 200:
21
  return "❌ Could not fetch weather data"
22
 
@@ -24,6 +23,6 @@ def get_weather_by_coordinates(lat, lon):
24
  temp = data["main"]["temp"]
25
  condition = data["weather"][0]["description"]
26
  emoji = get_emoji(condition)
 
27
 
28
- location = data["name"] or "Selected Area"
29
- return f"📍 **Location:** {location}\n🌡️ **Temperature:** {temp}°C\n📌 **Condition:** {condition} {emoji}"
 
1
  import requests
2
 
3
+ API_KEY = "YOUR_API_KEY" # 🔁 Replace this with your OpenWeatherMap key
4
 
5
  def get_emoji(condition):
6
  condition = condition.lower()
 
16
  def get_weather_by_coordinates(lat, lon):
17
  url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_KEY}&units=metric"
18
  response = requests.get(url)
 
19
  if response.status_code != 200:
20
  return "❌ Could not fetch weather data"
21
 
 
23
  temp = data["main"]["temp"]
24
  condition = data["weather"][0]["description"]
25
  emoji = get_emoji(condition)
26
+ location = data.get("name", "Selected Location")
27
 
28
+ return f"📍 **{location}**\n🌡️ **Temperature:** {temp}°C\n📌 **Condition:** {condition} {emoji}"