-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.py
executable file
·52 lines (41 loc) · 1.32 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
""" database.py - get persistence for data
v0.0.4 - 2022-01-27 - nelbren@nelbren.com"""
import os
from pathlib import Path
from peewee import SqliteDatabase, Model, CharField, IntegerField, FloatField
HOME = str(Path.home())
PWD = os.path.dirname(os.path.realpath(__file__))
PWD_DIR = os.path.basename(PWD)
BASE = f"{HOME}/.{PWD_DIR}.db"
db = SqliteDatabase(BASE)
class BaseModel(Model):
"""Database"""
class Meta:
"""Metadata"""
# pylint: disable=too-few-public-methods
database = db
class Unpaid(BaseModel):
"""Unpaid table"""
source = CharField(max_length=50)
currency = CharField(max_length=3)
work = IntegerField()
step = IntegerField()
timestamp = CharField(max_length=18)
value = FloatField()
usd = FloatField()
class Meta:
"""Metadata"""
# pylint: disable=too-few-public-methods
db_table = "unpaid"
indexes = (
(("source", "currency", "work", "step", "timestamp"), True),
(("source", "currency", "work", "step"), True),
)
def __str__(self):
# pylint: disable=no-member
return (
f"{self.id} : SRC: {self.source} CUR: {self.currency} "
f"WKR: {self.work} STP: {self.step} "
f"VAL: {self.value} USD: {self.usd}"
)