Zelara Weather Worker is a microservice designed to interact with the OpenWeather API and MongoDB, retrieving and storing weather data for different cities. It uses FastAPI for handling API requests and Docker for deployment. The service provides functionality to add, find, and manage weather data in MongoDB.
Before running this service, ensure you have the following installed:
- Docker: Install Docker from here.
- MongoDB: The service interacts with MongoDB as the data store.
- OpenWeather API Key: You will need an API key from OpenWeather. Sign up here to get one.
git clone https://github.com/zelara-ai/zelera-weather.git>
cd zelara-weather
Create a .env
file in the root directory with your OpenWeather API key:
OPENWEATHER_API_KEY=your_api_key_here
MONGO_URL=mongodb://db:27017/zelara_db
You can use Docker Compose to easily set up and run the services:
docker-compose up
This will start:
- MongoDB container.
- FastAPI server running the weather worker.
The application will be accessible at http://localhost:8000
.
- Base URL:
http://localhost:8000/
- Get all data:
GET /api/data
- Find city by name:
GET /find/city?name=<city_name>
- Find city by ID:
GET /find/id?id=<city_id>
- Add a city:
POST /add?city=<city_name>
- Modify the
db-fixtures/fixture.json
file to add initial data for the database. - You can rebuild the container to apply the new data with:
docker-compose down docker-compose up
- The application logic resides in
src/main.py
. You can add more routes or modify existing functionality here.
After making changes, run:
docker-compose down
docker-compose up --build
You can test the API locally using tools like Postman or curl. Ensure the MongoDB container is running before performing any tests.
- The project includes a GitHub Actions workflow for automating the Docker image build and pushing it to GitHub Container Registry (GHCR).
- The workflow is triggered when you push a new tag (e.g.,
v1.0.0
).
To deploy:
- Tag your commit:
git tag v1.0.0 git push origin v1.0.0
- The GitHub Action will automatically build and push the Docker image to GHCR.
This project is licensed under the MIT License. See the LICENSE file for details.