forked from s045pd/DarkNet_ChineseTrading
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
144 lines (111 loc) · 4.42 KB
/
model.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import datetime
import hashlib
import json
import pymysql
from peewee import *
from conf import Config
from peewee import __exception_wrapper__
Links = {
"host": Config.mysql_host,
"port": Config.mysql_port,
"user": Config.mysql_usr,
"password": Config.mysql_pass,
}
try:
con = pymysql.connect(**Links)
with con.cursor() as cursor:
cursor.execute(
f"create database {Config.mysql_db} character set UTF8mb4 collate utf8mb4_bin"
)
con.close()
except pymysql.err.ProgrammingError as e:
if "1007" in str(e):
pass
except Exception as e:
raise e
class RetryOperationalError(object):
def execute_sql(self, sql, params=None, commit=True):
try:
cursor = super(RetryOperationalError, self).execute_sql(sql, params, commit)
except OperationalError:
if not self.is_closed():
self.close()
with __exception_wrapper__:
cursor = self.cursor()
cursor.execute(sql, params or ())
if commit and not self.in_transaction():
self.commit()
return cursor
class RetryMySQLDatabase(RetryOperationalError, MySQLDatabase):
pass
Links["database"] = Config.mysql_db
db = RetryMySQLDatabase(**Links, charset="utf8mb4")
class DarkNet_Domain(Model):
mid = AutoField(primary_key=True)
domain = CharField(max_length=180)
datetime = DateTimeField(default=datetime.datetime.now)
class Meta:
database = db
class DarkNet_Saler(Model):
uid = IntegerField(primary_key=True, verbose_name="用户编号")
user = CharField(unique=True, max_length=20, verbose_name="用户外键")
regtime = DateField(verbose_name="注册时间")
salenums = IntegerField(verbose_name="在售单数")
totalsales = FloatField(verbose_name="总出售额")
totalbuys = FloatField(verbose_name="总购买额")
class Meta:
database = db
class DarkNet_User(Model):
user = CharField(max_length=20, primary_key=True, verbose_name="用户名")
pwd = CharField(max_length=20, verbose_name="密码")
useful = BooleanField(default=True)
intime = DateTimeField(default=datetime.datetime.now)
class Meta:
database = db
class DarkNet_IMGS(Model):
sid = IntegerField(primary_key=True, verbose_name="交易编号")
img = TextField(verbose_name="图片json")
detail = TextField(default=json.dumps([]), verbose_name="备注")
islink = BooleanField(default=True)
class Meta:
database = db
class DarkNet_Notice(Model):
sid = IntegerField(primary_key=True, verbose_name="交易编号")
wechat = BooleanField(default=False, verbose_name="企业微信")
email = BooleanField(default=False, verbose_name="邮件")
telegram = BooleanField(default=False, verbose_name="telegram")
class Meta:
database = db
class DarkNet_DataSale(Model):
sid = IntegerField(primary_key=True, verbose_name="交易编号")
intime = DateTimeField(default=datetime.datetime.now, verbose_name="数据插入时间")
uptime = DateTimeField(verbose_name="发布时间")
lasttime = DateTimeField(verbose_name="商家最后在线")
user = ForeignKeyField(DarkNet_Saler, on_delete=None, verbose_name="发布用户ID")
area = CharField(max_length=32, verbose_name="区域")
title = CharField(max_length=155, verbose_name="发布标题")
priceBTC = FloatField(verbose_name="出售价格(BTC)")
priceUSDT = FloatField(verbose_name="出售价格(美元)")
lines = IntegerField(verbose_name="保护期")
hot = IntegerField(verbose_name="关注度")
detailurl = CharField(max_length=255, verbose_name="详情地址")
types = CharField(max_length=32, verbose_name="交易类型")
status = CharField(max_length=32, verbose_name="交易状态")
oversell = BigIntegerField(verbose_name="出售数量(出售数量)") # 出售数量
sold = IntegerField(verbose_name="已经出售(本单成交)") # 已经出售
img = ForeignKeyField(DarkNet_IMGS, on_delete=None, verbose_name="图片Base64")
notice = ForeignKeyField(DarkNet_Notice, verbose_name="消息提醒", on_delete="CASCADE")
class Meta:
database = db
indexes = ((("uptime", "user", "title"), True),)
db.connect()
db.create_tables(
[
DarkNet_Domain,
DarkNet_User,
DarkNet_Saler,
DarkNet_IMGS,
DarkNet_Notice,
DarkNet_DataSale,
]
)