Dharsan Decodes Data

(Eng) S5 E4.1. Python essentials for DE

14 min · 29. tammi 2026
jakson (Eng) S5 E4.1. Python essentials for DE kansikuva

Kuvaus

pip install requests import requests # Telling Python we want to use this power-up # The "Waiter's" Address (A free API for current weather) url = "https://api.open-meteo.com/v1/forecast?latitude=13.08&longitude=80.27¤t_weather=true" # 1. Send the request response = requests.get(url) # 2. Convert the "mess" into a Python Dictionary data = response.json() # 3. Dig into the Dictionary to find the temperature # (Based on the JSON structure the API provides) current_temp = data["current_weather"]["temperature"] print(f"The current temperature in Chennai is {current_temp}°C")

Kommentit

0

Ole ensimmäinen kommentoija

Rekisteröidy nyt ja liity Dharsan Decodes Data-yhteisöön!

Aloita nyt

3 kuukautta hintaan 3,99 €

Sitten 7,99 € / kuukausi · Peru milloin tahansa.

  • Podimon podcastit
  • 20 kuunteluaikaa / kuukausi
  • Lataa offline-käyttöön

Kaikki jaksot

37 jaksot

jakson (Eng) S5 E4.2. Python essentials for DE II kansikuva

(Eng) S5 E4.2. Python essentials for DE II

import requests url = "https://api.weather.com/v1/current" # Example URL try: response = requests.get(url, timeout=5) # Stop waiting after 5 seconds response.raise_for_status() # Automatically trigger an error if status isn't 200 data = response.json() print("Data fetched successfully!") except requests.exceptions.HTTPError as err: print(f"The Server had an issue: {err}") except requests.exceptions.ConnectionError: print("The Internet is down! Checking again in 5 minutes...") except Exception as e: print(f"Something weird happened: {e}") import os from dotenv import load_dotenv load_dotenv() # Load the secrets from the .env file api_key = os.getenv("WEATHER_API_KEY") print(f"Using API Key: {api_key[:4]}****") # Only print a tiny bit for safety

30. tammi 202611 min