forked from awesome-archive/lianjia-scrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
126 lines (105 loc) · 3.15 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
from peewee import *
import datetime
import settings
if settings.DBENGINE.lower() == 'mysql':
database = MySQLDatabase(
settings.DBNAME,
host=settings.DBHOST,
port=settings.DBPORT,
user=settings.DBUSER,
passwd=settings.DBPASSWORD,
charset='utf8',
use_unicode=True,
)
elif settings.DBENGINE.lower() == 'sqlite3':
database = SqliteDatabase(settings.DBNAME)
elif settings.DBENGINE.lower() == 'postgresql':
database = PostgresqlDatabase(
settings.DBNAME,
user=settings.DBUSER,
password=settings.DBPASSWORD,
host=settings.DBHOST,
charset='utf8',
use_unicode=True,
)
else:
raise AttributeError("Please setup datatbase at settings.py")
class BaseModel(Model):
class Meta:
database = database
class Community(BaseModel):
id = BigIntegerField(primary_key=True)
title = CharField()
link = CharField(unique=True)
district = CharField()
bizcircle = CharField()
tagList = CharField()
onsale = CharField()
onrent = CharField(null=True)
year = CharField(null=True)
housetype = CharField(null=True)
cost = CharField(null=True)
service = CharField(null=True)
company = CharField(null=True)
building_num = CharField(null=True)
house_num = CharField(null=True)
price = CharField(null=True)
city = CharField(null=True)
validdate = DateTimeField(default=datetime.datetime.now)
class Houseinfo(BaseModel):
houseID = CharField(primary_key=True)
title = CharField()
link = CharField()
community = CharField()
years = CharField()
housetype = CharField()
square = CharField()
direction = CharField()
floor = CharField()
taxtype = CharField()
totalPrice = CharField()
unitPrice = CharField()
followInfo = CharField()
decoration = CharField()
validdate = DateTimeField(default=datetime.datetime.now)
class Hisprice(BaseModel):
houseID = CharField()
totalPrice = CharField()
date = DateTimeField(default=datetime.datetime.now)
class Meta:
primary_key = CompositeKey('houseID', 'totalPrice')
class Sellinfo(BaseModel):
houseID = CharField(primary_key=True)
title = CharField()
link = CharField()
community = CharField()
years = CharField()
housetype = CharField()
square = CharField()
direction = CharField()
floor = CharField()
status = CharField()
source = CharField()
totalPrice = CharField()
unitPrice = CharField()
dealdate = CharField(null=True)
updatedate = DateTimeField(default=datetime.datetime.now)
class Rentinfo(BaseModel):
houseID = CharField(primary_key=True)
title = CharField()
link = CharField()
region = CharField()
zone = CharField()
meters = CharField()
other = CharField()
subway = CharField()
decoration = CharField()
heating = CharField()
price = CharField()
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()