forked from s045pd/DarkNet_ChineseTrading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor.py
84 lines (71 loc) Β· 2.26 KB
/
cursor.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from model import (
DarkNet_Domain,
DarkNet_DataSale,
DarkNet_IMGS,
DarkNet_Notice,
DarkNet_Saler,
DarkNet_User,
)
from peewee import fn
from log import info, error
class Cursor:
@staticmethod
def get_last_domain():
try:
return (
DarkNet_Domain.select()
.order_by(DarkNet_Domain.datetime)
.limit(1)[0]
.domain
)
except Exception as e:
error(f"[Cursor->get_last_domain]: {e}")
@staticmethod
def create_new_domain(domain):
return DarkNet_Domain.create(**{"domain": domain})
@staticmethod
def create_new_user(datas):
return DarkNet_User.create(**datas)
@staticmethod
def get_random_user():
try:
return (
DarkNet_User.select()
.where(DarkNet_User.useful == True)
.order_by(fn.Rand())
.limit(1)[0]
)
except Exception as e:
error(f"[Cursor->get_random_user]: {e}")
@staticmethod
def ban_user(usr):
return (
DarkNet_User.update({"useful": False})
.where(DarkNet_User.user == usr)
.execute()
)
@staticmethod
def get_model_details(uid, sid):
details = DarkNet_DataSale.select().where((DarkNet_DataSale.sid == sid))
person = DarkNet_Saler.select().where((DarkNet_Saler.uid == uid))
notice = DarkNet_Notice.select().where((DarkNet_Notice.sid == sid))
img = DarkNet_IMGS.select().where((DarkNet_IMGS.sid == sid))
return details, person, notice, img
@staticmethod
def create_person(datas):
return DarkNet_Saler.create(**datas)
@staticmethod
def update_person(datas, uid):
return DarkNet_Saler.update(datas).where((DarkNet_Saler.uid == uid)).execute()
@staticmethod
def create_notice(datas):
return DarkNet_Notice.create(**datas)
@staticmethod
def create_img(datas):
return DarkNet_IMGS.create(**datas)
@staticmethod
def create_details(datas):
return DarkNet_DataSale.create(**datas)
@staticmethod
def update_details(datas, sid):
DarkNet_DataSale.update(datas).where((DarkNet_DataSale.sid == sid)).execute()