Create a Python script that fetches and displays live weather info for a city using the OpenWeatherMap API and saves the extracted data into a JSON file.
- Fetches live weather data from OpenWeatherMap API.
- Displays formatted weather information including:
- π‘οΈ Temperature
- π€ Feels Like temperature
- π§ Humidity
- βοΈ Condition
- π¨ Wind Speed
- π§ Pressure
- π Timestamp when data was fetched
- Saves extracted weather data into a JSON file per city.
- Supports single city (user input) and multiple cities (predefined list).
- Python 3.x
requestslibrary- OpenWeatherMap API key (get one for free: https://openweathermap.org/api)
Install dependencies:
pip install requestsπ Setup & Run Instructions
-
Clone or download the project folder.
-
Open terminal/command prompt and navigate to the project folder.
-
Replace the placeholder API key in weather.py with your own OpenWeatherMap API key.
-
Run the script:
python weather_app.py
-
Check the output:
-
Terminal will display formatted weather reports.
-
JSON files (e.g., Delhi_weather.json) will be saved automatically in the same folder.
Uncomment these lines in the script:
city_from_user = input("Enter your city name: ")
get_weather(city_from_user)Modify the list in the script:
cities = ["Mumbai", "Delhi", "London", "New York"]
for city in cities:
get_weather(city)Weather-Info-Fetcher/
β-- weather_app.py # Main Python script
β-- README.md # Documentation
β-- Mumbai_weather.json # Example saved weather data
β-- Delhi_weather.json # Example saved weather data
β-- London_weather.json # Example saved weather data
β-- New York_weather.json # Example saved weather data
Example saved JSON (Delhi_weather.json):
{
"city": "Delhi",
"temperature (C)": 29.08,
"feels_like (C)": 33.09,
"humidity (%)": 71,
"condition": "Scattered clouds",
"wind_speed (m/s)": 3.31,
"pressure (hPa)": 1005,
"fetched_at": "2025-09-07 00:17:21"
}Below is an example of the formatted weather report displayed in the terminal:
Weather report for Delhi:
π‘οΈ Temperature: 29.08 β
π€ Feels Like: 33.09 β
π§ Humidity: 71 %
βοΈ Condition: Scattered clouds
π¨ Wind Speed: 3.31 m/s
π§ Pressure: 1005 hPa
π
Data Fetched At: 2025-09-07 00:17:21
β
Weather data saved in Delhi_weather.json
- Replace the placeholder API key in the script with your own key.
- Make sure you have a stable internet connection while running the script.
β Developed as part of a Python automation learning exercise.