-
Notifications
You must be signed in to change notification settings - Fork 604
/
model.py
106 lines (93 loc) · 2.75 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
from peewee import *
import datetime
from ConfigParser import SafeConfigParser
config = SafeConfigParser()
config.read('config.ini')
if config.getboolean('Mysql', 'enable'):
database = MySQLDatabase(
config.get('Mysql', 'scheme'),
host=config.get('Mysql', 'host'),
port=config.getint('Mysql', 'port'),
user=config.get('Mysql', 'user'),
passwd=config.get('Mysql', 'password'),
charset='utf8',
use_unicode=True,
)
elif config.getboolean('Sqlite', 'enable'):
database = SqliteDatabase(config.get('Sqlite', 'dbname'))
elif config.getboolean('Postgresql', 'enable'):
database = PostgresqlDatabase(
config.get('Postgresql', 'scheme'),
user=config.get('Postgresql', 'user'),
password=config.get('Postgresql', 'password'),
host=config.get('Postgresql', 'host'),
charset='utf8',
use_unicode=True,
)
else:
raise AttributeError("Please enable a datatbase at config.ini")
class BaseModel(Model):
class Meta:
database = database
class Community(BaseModel):
id = PrimaryKeyField()
title = CharField()
link = CharField(unique=True)
district = CharField()
bizcircle = CharField()
tagList = CharField()
class Houseinfo(BaseModel):
houseID = BigIntegerField(primary_key=True)
title = CharField()
link = CharField()
community = CharField()
years = CharField()
housetype = CharField()
square = CharField()
direction = CharField()
floor = CharField()
taxtype = CharField()
totalPrice = IntegerField()
unitPrice = IntegerField()
followInfo = CharField()
validdate = DateTimeField(default=datetime.datetime.now)
class Hisprice(BaseModel):
houseID = BigIntegerField()
totalPrice = IntegerField()
date = DateTimeField(default=datetime.datetime.now)
class Meta:
primary_key = CompositeKey('houseID', 'totalPrice')
class Sellinfo(BaseModel):
houseID = BigIntegerField(primary_key=True)
title = CharField()
link = CharField()
community = CharField()
years = CharField()
housetype = CharField()
square = CharField()
direction = CharField()
floor = CharField()
status = CharField()
source = CharField()
totalPrice = IntegerField()
unitPrice = IntegerField()
dealdate = DateField()
updatedate = DateTimeField(default=datetime.datetime.now)
class Rentinfo(BaseModel):
houseID = BigIntegerField(primary_key=True)
title = CharField()
link = CharField()
region = CharField()
zone = CharField()
meters = CharField()
other = CharField()
subway = CharField()
decoration = CharField()
heating = CharField()
price = IntegerField()
pricepre = CharField()
updatedate = DateTimeField(default=datetime.datetime.now)
def database_init():
database.connect()
database.create_tables([Community, Houseinfo, Hisprice, Sellinfo, Rentinfo], safe=True)
database.close()