from peewee import *
db = MySQLDatabase("91jiafan", host="127.0.0.1", port=3306, user="root", password="123456")
class BaseModel(Model):
class Meta:
database = db
#table_name = "product"
#设计数据表的时候有几个重要点一定要注意
"""
char类型, 要设置最大长度
对于无法确定最大长度的字段,可以设置为Text
设计表的时候 采集到的数据要尽量先做格式化处理
default和null=True
"""
class Product(BaseModel):
product_id = IntegerField(primary_key=True) # 产品识别ID
name = CharField(max_length=1000) # 产品名
#name = CharField(max_length=20,primary_key=True) # 产品名
price = FloatField(default=0.0) # 价格
#content = TextField(default="")
sales_num = IntegerField(default=0) # 销量
store_id = IntegerField() # 商家ID
merchant = CharField() # 商家
main_Products = CharField(max_length=2000) # 主营
merchant_Place = CharField(max_length=2000) # 地址
class Product_attributes(BaseModel):
product_id = IntegerField(primary_key=True) # 产品识别ID
price_base = FloatField(default=0.0) # 基准价格
attributes = CharField(max_length=2000) # 商品描述
buyer_num = IntegerField(default=0) # 购买人数
sale_num = IntegerField(default=0) # 销售数量
buyer_rate = FloatField(default=0.0) # 商品复购率
class Store(BaseModel):
store_id = IntegerField(primary_key=True) # 商户的id
store_name = CharField(max_length=2000) # 商户的名字
store_level = TextField(default="") # 商户的等级
store_place = CharField(max_length=2000) # 商户的地址
store_aptitude = CharField(max_length=2000) # 商户资质,保存的url链接
store_describe = CharField() # 商户描述
store_supply = CharField() # 商户供应
store_service = CharField() # 商户服务
class Title(BaseModel): # 爬取目录
#series_id = IntegerField(primary_key=True) # 系列ID
series_name = CharField(max_length=2000) # 系列名称
series_level = IntegerField() # 产品系列的等级
series_id_0 = IntegerField() # 次级产品系列的ID,用来拼接url
series_name_0 = CharField(max_length=2000) # 次级产品系列的名称
series_level_0 = IntegerField() # 次级产品系列的等级
‘‘‘
class Topic(BaseModel):
title = CharField()
content = TextField(default="")
id = IntegerField(primary_key=True)
author = CharField()
create_time = DateTimeField()
answer_nums = IntegerField(default=0)
click_nums = IntegerField(default=0)
praised_nums = IntegerField(default=0)
jtl = FloatField(default=0.0) # 结帖率
score = IntegerField(default=0) # 赏分
status = CharField() # 状态
last_answer_time = DateTimeField()
class Answer(BaseModel):
topic_id = IntegerField()
author = CharField()
content = TextField(default="")
create_time = DateTimeField()
parised_nums = IntegerField(default=0) #点赞数
class Author(BaseModel):
name = CharField()
id = CharField(primary_key=True)
click_nums = IntegerField(default=0) #访问数
original_nums = IntegerField(default=0) #原创数
forward_nums = IntegerField(default=0) # 转发数
rate = IntegerField(default=-1) # 排名
answer_nums = IntegerField(default=0) # 评论数
parised_nums = IntegerField(default=0) # 获赞数
desc = TextField(null=True)
industry = CharField(null=True)
location = CharField(null=True)
follower_nums = IntegerField(default=0) # 粉丝数
following_nums = IntegerField(default=0) # 关注数
‘‘‘
if __name__ == "__main__":
#db.create_tables([Topic, Answer, Author])
db.create_tables([Product,Product_attributes,Store,Title])