📘 Lesson · Lesson 97
Weather API Program
इस Project के बारे में
💡 एक नज़र में
यह program requests library से weather API से किसी city का live weather लाता है।
Program
Python
import requests
city = "Delhi"
api_key = "YOUR_API_KEY"
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
response = requests.get(url)
data = response.json()
if response.status_code == 200:
print("City:", data["name"])
print("Temp:", data["main"]["temp"], "C")
print("Weather:", data["weather"][0]["description"])
else:
print("City not found")City: Delhi
Temp: 32 C
Weather: clear sky
सारांश
requests.get()API call करता है;.json()response parse करता है।- चलाने को OpenWeatherMap से free API key लें।
💻 लाइव कोड एडिटर
इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.