https://github.com/imranc07/python-live-weather-fetcher
Python script to fetch and display live weather data for cities using OpenWeatherMap API, with JSON output and formatted terminal reports
https://github.com/imranc07/python-live-weather-fetcher
datetime formatted-output json live-data openwheatherapi python requests-module
Last synced: 4 months ago
JSON representation
Python script to fetch and display live weather data for cities using OpenWeatherMap API, with JSON output and formatted terminal reports
- Host: GitHub
- URL: https://github.com/imranc07/python-live-weather-fetcher
- Owner: imranc07
- Created: 2025-09-06T19:20:34.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-09-06T19:31:15.000Z (5 months ago)
- Last Synced: 2025-09-06T21:29:37.703Z (5 months ago)
- Topics: datetime, formatted-output, json, live-data, openwheatherapi, python, requests-module
- Language: Python
- Homepage: https://openweathermap.org/api
- Size: 9.77 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🌤️ Weather Info Fetcher
## 📌 Problem Statement
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.
---
## 📖 Features
- 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)**.
---
## ⚙️ Requirements
- Python 3.x
- `requests` library
- OpenWeatherMap API key (get one for free: [https://openweathermap.org/api](https://openweathermap.org/api))
Install dependencies:
```bash
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:
```bash
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.
---
## 🚀 Usage
### Option 1: Single City (User Input)
Uncomment these lines in the script:
```python
city_from_user = input("Enter your city name: ")
get_weather(city_from_user)
```
### Option 2: Multiple Cities (Predefined List)
Modify the list in the script:
```python
cities = ["Mumbai", "Delhi", "London", "New York"]
for city in cities:
get_weather(city)
```
---
## 📂 Project Structure
```
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
```
---
## 💾 Output Example (Saved JSON)
Example saved JSON (`Delhi_weather.json`):
```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"
}
```
---
## 🖥️ Sample Terminal Output
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
```
---
## 📝 Notes
- 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.