Ejemplo n.º 1
0
 def __init__(self, hq_hotel_id_set, logger, ota_hotels=None):
     self.hq_hotel_id_set = hq_hotel_id_set
     self.logger = logger
     self.download_suppliers = Tools.get_dls_suppliers()
     self.ota_hotels = ota_hotels
     self.hotel_city_map = dict()
     """记录ota各个端的酒店信息"""
Ejemplo n.º 2
0
 def pick_interested_hotels(self, limit=2000):
     """
     选取用户感兴趣好巧酒店, 30天以内穿透量最多的limit家好巧酒店
     :param limit: 吐出酒店数量上限
     :return: set
     """
     try:
         interested_hotels_info = dict()
         download_suppliers = Tools.get_dls_suppliers()
         if not download_suppliers:
             return set()
         day = datetime.datetime.today() - datetime.timedelta(days=30)
         for supplier_id in download_suppliers:
             try:
                 sql = "SELECT hq_hotel_id, price_num FROM summary%s WHERE stat_date >= '%s' " \
                       "ORDER BY price_num DESC limit %s;" % (supplier_id, day, limit)
                 ret = pymysql_query(sql, Const.summary)
                 if ret == DB_EXCEPTION:
                     self.logger.error(traceback.format_exc())
                     continue
                 for row in ret:
                     hq_hotel_id = row[Const.hq_hotel_id]
                     price_num = row[Const.price_num]
                     if price_num == 0:
                         break
                     if hq_hotel_id not in interested_hotels_info:
                         interested_hotels_info[hq_hotel_id] = price_num
                     else:
                         interested_hotels_info[hq_hotel_id] += price_num
             except:
                 self.logger.error(traceback.format_exc())
         # 根据最大请求数降序排序
         sorted_hotels = sorted(interested_hotels_info.items(),
                                lambda x, y: cmp(x[1], y[1]),
                                reverse=True)
         interested_hotels = set()
         for item in sorted_hotels[:limit]:
             hq_hotel_id, num = item
             interested_hotels.add(hq_hotel_id)
         return interested_hotels
     except:
         self.logger.error(traceback.format_exc())
         return set()