Ejemplo n.º 1
0
 def insert(self, hotels, request):
     try:
         check = self.select_in("chat", "*", "id_chat",
                                (request.get_id_chat, ))
         if len(check) == 0:
             self.insert_in("chat", "id_chat", (request.get_id_chat, ))
         date = dt.today().strftime('%Y-%m-%d %H:%M')
         self.insert_in("history_requests", "id_chat, input, date, href",
                        (request.get_id_chat, request.get_input, date,
                         request.get_href))
         id_request = self.c.lastrowid
         for i in hotels:
             hash = hash_string(i.get_name)
             hotel = "SELECT id_hotel FROM hotel WHERE name = '%s'" % i.get_name
             self.c.execute(hotel)
             id_hotel = self.c.fetchone()
             if id_hotel is None:
                 self.insert_in(
                     "hotel",
                     "id_hotel, name,star,rating,count_recom,thumb_up,distance,amenities,image,link",
                     (hash, i.get_name, i.get_star, i.get_rating,
                      i.get_count_of_review, i.get_thumb_up,
                      i.get_distance_from_center, i.get_amenities,
                      i.get_image, i.get_link_on_hotel))
                 id_hotel = self.c.lastrowid
             self.insert_in("prices", "id_hotel,price,date",
                            (hash, i.get_price, date))
             self.insert_in("list_hotels", "id_request, id_hotel",
                            (id_request, hash))
         self.conn.commit()
     except sqlite3.Error as e:
         raise Exception('SQLite error, method - insert: ', e.args[0])
Ejemplo n.º 2
0
 def remove_favorite(self, id_chat, name_hotel):
     check = self.check_favorite(name_hotel)
     if check:
         self._operation.remove_in("favorite_hotels", "id_chat, id_hotel",
                                   (id_chat, hash_string(name_hotel)))
         self._sql.conn.commit()
         return True
     return False
Ejemplo n.º 3
0
 def dynamics_of_prices(self, hotel,id_chat):
     id_hotel = hash_string(hotel)
     prices = "SELECT date, price from prices where id_hotel = %d" % id_hotel
     self.c.execute(prices)
     fetch = self.c.fetchall()
     if fetch is not None:
         name = str(id_chat) + ".png"
         dir = './dynamic_of_price/'
         if not os.path.exists(dir):
             os.makedirs(dir)
         relative_path=os.path.join(dir,name)
         self._graph_data(prices, hotel)
         plt.savefig(relative_path)
         return relative_path
Ejemplo n.º 4
0
 def check_favorite(self, id_chat, name_hotel):
     """ Проверить в избранном отель по конкретному чату id_chat """
     return self._operation.is_exist_row("favorite_hotels", "*",
                                         "id_chat, id_hotel",
                                         (id_chat, hash_string(name_hotel)))
Ejemplo n.º 5
0
 def is_exist_hotel(self, hotel):
     """ Существование отеля в бд без зависимости от id chat """
     return self._operation.is_exist_row("hotel", "name", "id_hotel",
                                         (hash_string(hotel), ))
Ejemplo n.º 6
0
 def get_info_hotel(self, name_hotel):
     """Вывести данные отеля"""
     return self._operation.get_info_hotel(hash_string(name_hotel))