This project fetches weather data for a list of cities using the OpenWeatherMap API. It retrieves both current city data and forecast data.
- Fetches current weather data for a list of cities.
- Fetches forecast data for each city.
- Displays the collected data in a readable format.
- Exports data in CSV, XML, HTML, and JSON formats.
- Python 3.x
requests
librarypandas
librarytqdm
library
-
Clone the repository:
git clone https://github.com/y0geshx/weather-data-fetcher.git cd weather-data-fetcher
-
To activate a Python virtual environment in your project, follow these steps:
-
Create a virtual environment (if you haven't already):
python -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
After activating the virtual environment, you can install the required dependencies and run your scripts within this isolated environment.
-
Install the required libraries:
pip install requests pandas tqdm
-
Or use:
pip install -r requirements.txt
-
Set your OpenWeatherMap API key in the weather.py script:
API_KEY = 'your_api_key_here'
-
Prepare a CSV file with a list of cities. The CSV should have a column named
City
. -
Run the script:
python weather.py
-
The script will fetch and display the weather data for the listed cities.
-
Export the data in the desired format:
# Example for exporting data data.to_csv('weather_data.csv') data.to_json('weather_data.json') data.to_html('weather_data.html') data.to_xml('weather_data.xml')
Here is an example of how to use the script:
-
Create a CSV file named
in_cities.csv
with the following content:City London Paris New York
-
Run the script:
python weather.py
-
The script will fetch and display the weather data for the listed cities.
-
Export the data in the desired format:
data.to_csv('weather_data.csv') data.to_json('weather_data.json') data.to_html('weather_data.html') data.to_xml('weather_data.xml')
Contributions are welcome! Please open an issue or submit a pull request for any changes.
This project is licensed under the MIT License. See the LICENSE file for details.