Save prices to database (sqlite)

This commit is contained in:
2022-07-10 21:07:06 +02:00
parent dfb8edc01b
commit 6222214a89
3 changed files with 43 additions and 1 deletions

24
models.py Normal file
View File

@@ -0,0 +1,24 @@
from peewee import SqliteDatabase
from peewee import Model
from peewee import AutoField, DateField, IntegerField
from peewee import IntegrityError
# SQLite database using WAL journal mode and 64MB cache.
db = SqliteDatabase("fioul.db")
class BaseModel(Model):
class Meta:
database = db
class Price(BaseModel):
id = AutoField()
date = DateField(unique=True)
price = IntegerField()
def init():
db.connect()
db.create_tables([Price])