App that presents time series prices of crops across Tanzania
# AgritechTZ - Crop Prices Scraper and API
---
AgritechTZ is a FastAPI-based application designed to scrape, store, and serve daily crop price data. This project retrieves crop prices from Viwanda’s data sources, stores them in a PostgreSQL database, and provides a REST API for querying the stored data.
## Table of Contents
1. Requirements
2. Setup
3. Environment Variables
4. Database Migrations
5. Running the Application
6. API Endpoints
7. Scheduler for Daily Updates
8. Testing
9. Contributing
10. License
## Requirements
Python 3.11 (or higher)
PostgreSQL for the database
Docker (optional, for containerized deployment)
## Setup
Follow the following steps to setup and get the application running on your local (development) environment.
### Clone the repository:
```sh
git clone
github.com
cd agritechtz
```
### Create a virtual environment:
```sh
python -m venv .venv
source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
```
### Install dependencies:
```sh
poetry install
```
## Environment Variables
Create a .env file in the root directory with the following variables:
```sh
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/agritechtz
BASE_URL=
viwanda.example.com # Base URL for crop price data
API_KEY=your_api_key # Optional: if the source requires an API key
SCHEDULER_INTERVAL=24h # Interval for running the scheduler
```
> Note: Replace user, password, and localhost:5432/agritechtz with your actual PostgreSQL credentials.
### Database Migrations
Use Alembic to handle database migrations. To apply migrations, run:
```sh
alembic upgrade head
```
To generate a new migration based on changes to the models:
```sh
alembic revision --autogenerate -m "Migration message"
```
### Running the Application
#### Start FastAPI:
```sh
uvicorn agritechtz.main:app --reload
```
This will run the FastAPI app on
127.0.0.1.
#### Run Scheduler:
The scheduler.py script is use …