The purpose of this project is to create a database of fuel prices in Greece. Daily and weekly data about fuel prices are regularly uploaded at the Παρατηρητήριο Τιμών Υγρών Καυσίμων website by the Greek Government, but the data are published as PDF files. In order to process the data more easily, this project fetches those PDF files, extracts the data from them, inserts them into a database, and exposes them through an API.
Data are available since:
- 2012-04-27 for weekly country data
- 2012-05-04 for weekly prefecture data
- 2017-08-28 for daily country data
- 2017-03-14 for daily prefecture data
The backend API is a Python project, built with FastAPI, and uses Poetry for dependency management. To install the dependencies, run:
poetry installData is stored in an SQLite database. To fetch the data, use:
python -m fuelpricesgr.commands.importThis command supports various parameters to limit the data to be fetched:
python -m fuelpricesgr.commands.import --helpTo launch the API:
uvicorn fuelpricesgr.main:appThe API will be available at http://localhost:3002, with documentation at http://localhost:3002/docs.
To make the setup easier, a Docker image is provided. This allows running the API as a self-contained service with minimal setup.
First, build the Docker image:
docker build -t fuelpricesgr .Run the Docker container:
docker run -p 3002:8000 fuelpricesgrThis will expose the API on localhost:3002. You can access the API documentation at http://localhost:3002/docs.
To run the import command inside the Docker container, use:
docker exec -it <container_name> python -m fuelpricesgr.commands.import --start-date {YYYY-MM-DD} --end-date {YYYY-MM-DD}To set up automated daily updates for fuel prices, modify your Docker container or orchestrate it with a task scheduler (like a cron job in Docker) to run the import command with the --update flag:
python -m fuelpricesgr.commands.import --update| Method | Endpoint | Parameters | Description |
|---|---|---|---|
| GET | /status |
None | Returns the status of the application |
| GET | /fuelTypes |
None | Returns all fuel types |
| GET | /prefectures |
None | Returns all prefectures |
| GET | /dateRange/{data_type} |
None | Get the available data date range for a specific data type |
| Method | Endpoint | Query Parameters | Description |
|---|---|---|---|
| GET | /data/daily/country |
start_date, end_date | Returns the daily country data (for Greece) |
| GET | /data/daily/prefectures/{prefecture} |
start_date, end_date | Returns the daily prefecture data |
| GET | /data/weekly/country |
start_date, end_date | Returns the weekly country data (for Greece) |
| GET | /data/weekly/prefectures/{prefecture} |
start_date, end_date | Returns the weekly prefecture data |
To fetch daily fuel data for a specific prefecture between two dates:
GET /data/daily/prefectures/ATTICA?start_date=2023-01-01&end_date=2023-01-31To run the application tests:
pytestTo get a test coverage report:
coverage run -m pytest .This will generate an HTML coverage report in htmlcov/index.html.
To get a pylint report:
pylint fuelpricesgr- The API exposes endpoints for fuel prices on a daily and weekly basis for both the country and individual prefectures.
- To limit the data to daily prices, use the following command to fetch only
DAILY_COUNTRYandDAILY_PREFECTUREdata:
python -m fuelpricesgr.commands.import --types DAILY_COUNTRY,DAILY_PREFECTURE --start-date {YYYY-MM-DD} --end-date {YYYY-MM-DD}- To configure email notifications for data updates, create a
.envfile in the root of the project folder with the following content:
SECRET_KEY={SECRET_KEY}
MAIL_SENDER={MAIL_SENDER}
MAIL_RECIPIENT={MAIL_RECIPIENT}Then run the import command with the --send-mail flag to trigger an email notification:
python -m fuelpricesgr.commands.import --send-mail