forked from ch3p4ll3/QBittorrentBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_management.py
45 lines (30 loc) · 1.03 KB
/
db_management.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
from pony.orm import Database, PrimaryKey, Required, \
db_session, ObjectNotFound
from os import getenv
db = Database()
db.bind(provider='sqlite', filename=f'{"/app/config/" if getenv("IS_DOCKER", False) else "../"}/database.sqlite',
create_db=True)
class Support(db.Entity):
id = PrimaryKey(int, size=64)
Action = Required(str, 255)
class CompletedTorrents(db.Entity):
hash = PrimaryKey(str)
db.generate_mapping(create_tables=True)
def read_support(chat_id):
with db_session:
try:
return Support[chat_id].Action
except ObjectNotFound:
return ""
def write_support(status, chat_id):
with db_session:
try:
Support[chat_id].Action = status
except ObjectNotFound:
Support(Action=status, id=chat_id)
def write_completed_torrents(torrent_hash):
with db_session:
CompletedTorrents(hash=torrent_hash)
def read_completed_torrents(torrent_hash):
with db_session:
return CompletedTorrents.get(hash=torrent_hash)