59 lines
1.7 KiB
Markdown
59 lines
1.7 KiB
Markdown
Get current fioul price from Bretagne Multi Énergie and store it. Also with an
|
|
incredible web interface to list price history.
|
|
|
|
# Requirements
|
|
|
|
This project is written in Python and uses the following libraries:
|
|
|
|
* requests: to retrieve current price using a GraphQL query;
|
|
* peewee: a simple ORM, to store and query the data in a SQL database;
|
|
* bottle: a micro web framework.
|
|
|
|
Those libraries are all packaged in Debian and can be installed with:
|
|
|
|
```
|
|
apt install python3-request python3-peewee python3-bottle
|
|
```
|
|
|
|
Optional: a MySQL server (although switching to another database should be
|
|
easy). Otherwise, a SQLite backend can be used.
|
|
|
|
|
|
# Installation
|
|
|
|
We suppose the repository is cloned under `/opt/fioul`.
|
|
|
|
Create a `fioul.ini` config file, and fill in MySQL credentials. You can use
|
|
`fioul.ini.example` as a starting point. MySQL database can be created with the
|
|
following commands:
|
|
|
|
```sql
|
|
create database fiouldb;
|
|
create user 'fioul'@'localhost' identified by 'fioul_is_beautifioul';
|
|
grant all privileges on fiouldb.* TO 'fioul'@'localhost';
|
|
```
|
|
|
|
Tables can be created by running `./fioul.py initdb`
|
|
|
|
|
|
To update the database every 15 minutes, the following line can be
|
|
installed as a cronjob:
|
|
|
|
```
|
|
*/15 * * * * /opt/fioul/fioul.py update
|
|
```
|
|
|
|
To launch the server automatically, you can install and use the systemd
|
|
service file :
|
|
|
|
```
|
|
adduser --system --group --no-create-home fioul
|
|
ln -s /opt/fioul/fioul.service /etc/systemd/system/fioul.service
|
|
systemctl enable fioul.service
|
|
systemctl start fioul.service
|
|
```
|
|
|
|
The server listens to port 9980 on localhost by default, unless
|
|
otherwise specified in the config file. Setting up a reverse proxy and
|
|
ssl is left as an exercise to the reader.
|