This Python script collects weather data automatically using GitHub Actions. It runs on a schedule of 5:30 GMT, collects the latest weather information from the Open-Meteo API, and pushes the changes to the repository for easy tracking and analysis.
- Automatic weather data collection
- Scheduled execution using GitHub Actions
- Data collected includes hourly temperature readings
- Commit and push data to the repository
Before running this script, make sure you have the following:
- Python 3 installed on your machine
- A GitHub account
- Access to the repository where you want to store the weather data
-
Clone the repository to your local machine:
https://github.com/Cozmeh/WeatherCollector.git
-
Navigate to the project directory:
cd WeatherCollector
-
Install the required Python packages:
pip install requests
-
Open the
collector.py
script in a text editor. -
Modify the latitude and longitude values in the API call to specify the location for which you want to collect weather data. For example:
rawData = requests.get('https://api.open-meteo.com/v1/forecast?latitude=12.9719&longitude=77.5937&hourly=temperature_2m&forecast_days=1')
Replace
latitude
andlongitude
with the coordinates of your desired location. -
Save the changes to the script.
-
Commit the script to the repository:
git add collector.py git commit -m "Add Weather Data Collector script" git push
-
Go to your GitHub repository and navigate to the "Actions" tab.
-
Click on "Set up a workflow yourself" and create a new workflow file, such as
.github/workflows/weather-data-collector.yml
. -
Paste the following code into the workflow file:
- Check out https://github.com/Cozmeh/WeatherCollector/blob/main/.github/workflows/Action.yml
- Do not forget to change the
email
in the config section - Also ensure that the
cron
expression in theon.schedule
section matches your desired schedule. The example above runs at 5:30 GMT. ie 11:00 IST
- Commit and push the workflow file to the repository
The script will now run automatically according to the specified schedule, collect weather data from the Open-Meteo API, and commit and push the changes to the repository. The collected data will be stored in the HourlyTemperature.csv
file as the weather dataset.
- Currently the script collects the weather data of Bengaluru
- Use Open-Meteo to get your desired location's weather