INTRODUCTION:
Hello, esteemed community members! I’m thrilled to share my captivating program that unlocks the incredible potential of data extraction and web data—two vital skills that can elevate your journey in the field of data science.
TOOLS:
Here are the powerful tools that drive this program:
PYTHON LIBRARIES:
PROGRAM PHILOSOPHY AND LOGIC:
This program was designed with a passion for learning and discovery. By leveraging the OpenWeatherMap API, a cutting-edge open-source platform for weather forecasting, we can tap into a wealth of data.
urllib
, json
, and datetime
libraries, laying the foundation for our data adventure.datetime
library, allowing us to explore selected time frames and reveal the rich narratives behind the weather events we wish to study.Join me on this journey of exploration and empowerment through data!
Below is my GitHub link. Feel free to look at my project.
https://github.com/h2005mirza/weather-forecasting
Below is the Python code I developed:
import urllib.request, urllib.error, urllib.parse import json from datetime import datetime api_key = "fa07f03ac7822f26f40d5bb67daf3d3c" weather_url = "http://api.openweathermap.org/data/2.5/forecast?" city = input("Enter the name of the city: ") start_date = input("Enter the start date (YYYY-MM-DD): ") end_date = input("Enter the end date (YYYY-MM-DD): ") parsed_url = f"{weather_url}q={city}&appid={api_key}&units=metric" try: response = urllib.request.urlopen(parsed_url) weather_data = json.load(response) print(f"Weather forecast of {city} from {start_date} to {end_date}") for forecast in weather_data['list']: forecast_date = forecast['dt_txt'] forecast_datetime = datetime.strptime(forecast_date, '%Y-%m-%d %H:%M:%S') start_datetime = datetime.strptime(start_date, '%Y-%m-%d') end_datetime = datetime.strptime(end_date, '%Y-%m-%d') if start_datetime <= forecast_datetime <= end_datetime: temp = forecast['main']['temp'] description = forecast['weather'][0]['description'] print(f"Date: {forecast_date} | Temperature: {temp}°C | Description: {description}") except urllib.error.URLError as e: print(f"An HTTP error occurred: {e.reason}") except Exception as e: print(f"An error: {e}")
There are no datasets linked
There are no datasets linked
There are no models linked
There are no models linked