The weather.py script is designed to retrieve weather information for a specific location by making an API call to a weather service. This application is unique as it's set up to run as a cron job using GitHub Actions, allowing for regular, automated updates.
- Automated Weather Logging: Utilizes GitHub Actions to schedule and run the script at specified intervals.
- Weather Data Retrieval: Makes API calls to a weather service to get real-time weather data.
- Logging: Records the weather data into a weather_status.log file for historical tracking and analysis.
This application leverages the GitHub Actions feature, making the most out of the 2000 free minutes available per month on GitHub's free tier. This approach is not only cost-effective but also demonstrates a practical application of GitHub Actions for automation projects.
- GitHub Actions Configuration:
- The cron job is configured in the .github/workflows/weather_cronjobs.yml file.
- Modify the schedule in the YAML file to set the desired frequency for the script execution.
- API Token Configuration:
- Ensure that the API_TOKEN environment variable is set in your GitHub repository settings for secure API access.
- Logging Configuration:
- The script writes output to weather_status.log.
- Log file management (e.g., rotation, backup) is handled within the script.
To run the script locally:
- Clone the repository.
- Install required dependencies from requirements.txt.
- Set up the API_TOKEN environment variable.
- Run python weather.py.
Dockerization
This application is also dockerized for easy deployment and scalability:
-
Build the Docker image using the provided Dockerfile.
docker build -t weather-app
-
Run the Docker container, passing the API_TOKEN as an environment variable.
docker run -e API_TOKEN=enter_your_token_here -v /path/on/host:/usr/src/app/logs weather-app