β‘ Python Power Shots β π€οΈ Get Live Weather Info
Posted on: November 10, 2025
Description:
π Introduction
Want to check the weather right from your terminal? βοΈ
With just a few lines of Python, you can fetch and display live weather updates for any city β no setup, no API keys.
This Power Shot uses the public wttr.in API, a lightweight web service that returns weather data as plain text or JSON.
π Explanation
- requests.get() β fetches live data from the URL https://wttr.in/
?format=j1. - The JSON response includes temperature, humidity, weather conditions, and more.
- You can print a clean summary directly in the terminal.
- Works globally for any city β just change the location name.
β Key Takeaways
- π€οΈ Get real-time weather data in seconds.
- βοΈ Works without API keys or sign-ups.
- π Fetch data for any city worldwide using simple HTTP requests.
Code Snippet:
# Import requests to make HTTP requests
import requests
# --- Step 1: Define the city you want weather info for ---
city = "Pune" # You can replace this with any city name
# --- Step 2: Fetch weather data from wttr.in ---
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
# --- Step 3: Check if the request was successful ---
if response.status_code == 200:
data = response.json()
# --- Step 4: Extract useful information ---
current = data["current_condition"][0]
temperature = current["temp_C"]
feels_like = current["FeelsLikeC"]
humidity = current["humidity"]
weather_desc = current["weatherDesc"][0]["value"]
# --- Step 5: Display the weather report ---
print(f"π Weather in {city}:")
print(f"π‘οΈ Temperature: {temperature}Β°C (Feels like {feels_like}Β°C)")
print(f"π§ Humidity: {humidity}%")
print(f"βοΈ Condition: {weather_desc}")
else:
print("β οΈ Failed to fetch weather data. Please check your city name or internet connection.")
Link copied!
Comments
Add Your Comment
Comment Added!
No comments yet. Be the first to comment!