Ejemplo n.º 1
0
 def topFirst(self):
     # 获取评论数量前十的景区
     ten_site = site_db.select_sql(
         ['site_name', 'num_comment'],
         sqlFilter=f"order by num_comment desc limit 10")
     ten_site = sorted(ten_site,
                       key=lambda x: int(x['num_comment']),
                       reverse=True)
     # 获取评分最高的10个酒店
     ten_hotel = hotel_db.select_sql(
         ['hotel_name', 'comment_num'],
         sqlFilter=f"order by comment_num desc limit 10")
     ten_hotel = sorted(ten_hotel,
                        key=lambda x: int(x['comment_num']),
                        reverse=True)
     # 获取游记数量最多的10个地区
     ten_site_info = site_db.select_sql(
         ['site_name', 'num_ginfo'],
         sqlFilter=f"order by num_ginfo desc limit 10")
     ten_site_info = sorted(ten_site_info,
                            key=lambda x: int(x['num_ginfo']),
                            reverse=True)
     print(ten_site_info)
     return ten_site, ten_hotel, ten_site_info
Ejemplo n.º 2
0
 def picData(self):
     ten_site = site_db.select_sql(
         ['site_name', 'num_comment', 'num_ginfo'],
         sqlFilter=f"order by num_comment desc limit 14")
     ten_site = sorted(ten_site,
                       key=lambda x: int(x['num_comment']),
                       reverse=True)
     res = []
     for item in ten_site:
         temp = {
             'name': item['site_name'],
             'value1': item['num_comment'],
             'value2': item['num_ginfo'],
         }
         res.append(temp)
     return res
Ejemplo n.º 3
0
    def second(self):
        # 获取详情页面内容
        for url in allSite:
            targetUrl = self.detail_info_url + url
            print('second', targetUrl)
            detailRoot = self.request(targetUrl)
            imgs = self.secondImg(detailRoot)
            img = json.dumps(imgs, ensure_ascii=False)
            name = self.secondTitle(detailRoot)
            brief = self.secondBrief(detailRoot)
            site = self.secondSite(detailRoot)
            site_id = produce_id()
            # 获取评论信息
            comment_num = self.commentNum(detailRoot)
            comment_category = self.commentCategory(detailRoot)

            other = {
                'comment_num': comment_num,
                'comment_category': comment_category
            }
            other = json.dumps(other, ensure_ascii=False)

            # fixme 数据存储
            is_exist = site_db.select_sql(
                target=['id'], sqlFilter=f"where site_name = '{name}'")[0]
            print('is_exist =============== ', is_exist)
            # if not is_exist and brief:
            #     data = [site_id, name, site, brief, img, other]
            #     target = ['id', 'site_name', 'site', 'brief', 'imgs', 'other']
            #     site_db.insert_sql(target, data)
            #
            #     for index in range(1, 16):
            #         comment_id = self.commentContent(detailRoot, index)
            #         data = [site_id, comment_id]
            #         target = ['site_id', 'comment_id']
            #         relationship_db.insert_sql(target, data)
            if is_exist:
                for index in range(1, 16):
                    comment_id = self.commentContent(detailRoot, index)
                    site_id = is_exist.get('id')
                    data = [site_id, comment_id]
                    target = ['site_id', 'comment_id']
                    relationship_db.insert_sql(target, data)
            driver.close()
Ejemplo n.º 4
0
def getContent(id):
    site = site_db.select_sql(["*"], sqlFilter=f'where id = "{id}"')
    return site
Ejemplo n.º 5
0
def getManySite():
    allSite = site_db.select_sql(["*"], sqlFilter=f'where img != "" limit 16')
    return allSite
Ejemplo n.º 6
0
def getSite():
    allSite = site_db.select_sql(
        ["*"], sqlFilter=f'order by num_comment desc limit 12')
    return allSite