https://github.com/morgan-sell/weather-api
An application that fetches and returns weather data from a 3rd party API and caches results in Redis.
https://github.com/morgan-sell/weather-api
api ci flask html pytest python redis redis-cache shell webapp
Last synced: about 2 months ago
JSON representation
An application that fetches and returns weather data from a 3rd party API and caches results in Redis.
- Host: GitHub
- URL: https://github.com/morgan-sell/weather-api
- Owner: Morgan-Sell
- License: mit
- Created: 2024-10-26T16:42:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T20:39:33.000Z (over 1 year ago)
- Last Synced: 2025-07-03T05:03:52.151Z (12 months ago)
- Topics: api, ci, flask, html, pytest, python, redis, redis-cache, shell, webapp
- Language: Python
- Homepage:
- Size: 4.32 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Weather Application
A Python-based application that checks the weather for a specified location. It first checks a Redis cache for recent data. If the weather data is not cached, the application fetches the data from a third-party weather API and caches the data for future requests. This reduces API calls, speeds up responses, and supports a better user experience.
The application obtains data from [Visiual Crossing's API](https://www.visualcrossing.com/weather-api).
## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Application Walkthrough](#application-walkthrough)
- [Features](#features)
- [Configuration](#configuration)
- [Dependencies](#dependencies)
- [Troubleshooting](#troubleshooting)
- [License](#license)
- [Acknowledgement](#acknowledgement)
## Installation
1. **Clone the Repository**
```
git clone https://github.com/Morgan-Sell/weather-api.git
cd weather-api
```
2. **Environment Variables:** Set up a .env file in the root directory of the project with the following variable.
```
API_KEY=
```
3. **Run Initial Setup:** Use the provided run.sh script for setting up your environment.
```
./run.sh initial-setup
```
## Usage
### Starting the Application
To start the application, run the following command:
./run.sh run-app
This will:
- Start a Redis server if it is not already running.
- Load the environment variables.
- Run the main application script located in `src/main.py`.
## Application Walkthrough
### 1. Launching the Application
When you access http://127.0.0.1:5001 via your web browser, you'll be greeted by the home page.
### 2. Submit Location
Enter the name of your desired city in the text box.
### 3. See the Results
Select "Collect Weather Data" and you will be directing to the current weather for your selected location.
### Available Commands
You can manage the environment and dependencies using `run.sh`:
- **Run the application:** `./run.sh run-app`
- **Set up virtual environment:** `./run.sh setup-venv`
- **Install dependencies:** `./run.sh install-deps`
- **Load environment variables:** `./run.sh load-env`
## Features
- **Weather Caching:** Checks for cached weather data in Redis before making API requests, reducing redundant calls and improving response times.
- **Cross-Platform Support:** Works on Windows, macOS, and Linux.
- **Easy Setup:** Simple bash script for environment setup, dependency installation, and application management.
## Configuration
- **Redis Configuration:** The application relies on Redis to cache weather data. The Redis server starts automatically through `run.sh run-app`, but you may need to ensure it is accessible and configured properly.
- **Weather API Key:** Obtain an API key from Visiual Crossing and add it to the `.env` file.
```
API_KEY=
```
## Dependencies
All the required dependencies can be found in `requirements.txt`. The dependencies are automatically installed when `run.sh initial-setup` is executed.
## Troubleshooting
- **Environment Variables:** Missing environment variables will prevent the application from running. Ensure they are correctly defined in your `.env` file.
- **Redis Issues:** Redis will automatically start when `run.sh run-app`. If Redis is not properly terminated, the Redis process may enter a "stopped" or "zombie" state preventing the application from properly functioning. If this occurs follow these steps:
1. Check if Redis is already running on your system.
```
ps aux | grep redis
```
This will show any existing Redis processes. Look for a process running on port 6379.
1. If a Redis process is running, kill the process.
```
sudo kill -9
```
Replace with the process ID of the running Redis server.
1. Confirm the process has been terminated by rerunning:
```
ps aux | grep redis
```
## License
This project is licensed under the MIT License. See the `LICENSE` file for more details.
## Acknowledgement
This application was built following the architecture outlined in [roadmap.sh's Weather API project](https://roadmap.sh/projects/weather-api-wrapper-service).