def get_Presets(self): db_manager = DatabaseManager('Database.db') db_manager.check_database() cursor = db_manager.conn.cursor() cursor.execute("SELECT DISTINCT(preset) FROM Products") list = cursor.fetchall() list = [x[0] for x in list] return list
def delete_Preset(self): preset_name = self.Select_Window2.window.List.currentItem().text() db_manager = DatabaseManager('Database.db') db_manager.check_database() cursor = db_manager.conn.cursor() cursor.execute("DELETE FROM Products WHERE preset=?", (preset_name, )) cursor.execute("SELECT * FROM Products") print(cursor.fetchall()) db_manager.conn.commit() db_manager.close_connection() self.Select_Window2.hide()
def check_price(self, products, Notif_List, email): header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" } # initialize the prices previous_prices = [x[1] for x in products] links = [x[0] for x in products] if 0 in previous_prices: self.initialize_prices(products) # checking the prices every 900sec db_manager = DatabaseManager('Database.db') db_manager.check_database() cursor = db_manager.conn.cursor() while True: for i in range(0, len(links)): page = requests.get(links[i], headers=header) main = BeautifulSoup(page.content, 'html.parser') price = main.find(class_="product-new-price").get_text() name = main.find(class_="page-title").get_text() name = name.strip() price = price.strip() price = self.number(price[0:len(price) - 6]) if price < previous_prices[i]: aux = previous_prices[i] - price print_message = "Price has been dropped by {0} lei for product {1}".format( aux, name) previous_prices[i] = price subject = "Price was decreased by {0} lei for product {1}".format( aux, name) body = "Check the link {}".format(links[i]) message = f"Subject: {subject}\n\n{body}" self.send_mail(message, email) ######################################## cursor.execute( "UPDATE Products SET previous_price =? WHERE link=?", (previous_prices[i], links[i])) Notif_List.addItem(QListWidgetItem(print_message)) db_manager.conn.commit() else: if price < previous_prices[i]: print_message = "Price was increased by {0} lei for product {1}".format( price - previous_prices[i], name) Notif_List.addItem(QListWidgetItem(print_message)) else: print_message = "Price it's the same for product {0}".format( name) Notif_List.addItem(QListWidgetItem(print_message)) print(print_message) time.sleep(300)
def load_Preset(self): self.window.Notif_List.clear() preset_name = self.Select_Window.window.List.currentItem().text() db_manager = DatabaseManager('Database.db') db_manager.check_database() cursor = db_manager.conn.cursor() cursor.execute( "SELECT link,previous_price FROM Products WHERE preset=?", (preset_name, )) self.Select_Window.hide() if str(preset_name) is not None: self.window.Status_Label.setText(str(preset_name) + " loaded!") ######################################### self.start_thread(cursor.fetchall(), self.window.Notif_List, self.email) self.preset_is_loaded = True
def save_Preset(self): if len(self.Dialog_Window.window.Name_Input.text()) == 0: QMessageBox.about(self, "eMag Price Tracker", "You must choose a name for the preset!") list = self.get_Presets() if str(self.Dialog_Window.window.Name_Input.text()) in list: QMessageBox.about(self, "eMag Price Tracker", "The preset already exists!") else: db_manager = DatabaseManager('Database.db') if db_manager.check_database(): cursor = db_manager.conn.cursor() cursor.execute("""create table if not exists Products( link text, preset text, previous_price integer )""") for i in range(self.window.Tracker_List.count()): cursor.execute( """INSERT INTO Products VALUES(?,?,?)""", (str(self.window.Tracker_List.item(i).text()), str(self.Dialog_Window.window.Name_Input.text()), 0)) cursor.execute("SELECT * FROM Products") print(cursor.fetchall()) db_manager.conn.commit() db_manager.close_connection() self.window.Tracker_List.clear() self.Dialog_Window.hide()
def initialize_prices(self, products): # initialize the prices previous_prices = [x[1] for x in products] links = [x[0] for x in products] header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" } for i in range(0, len(links)): page = requests.get(str(links[i]), headers=header) main = BeautifulSoup(page.content, 'html.parser') price = main.find(class_="product-new-price").get_text() price = price.strip() price = self.number(price[0:len(price) - 6]) previous_prices[i] = price db_manager = DatabaseManager('Database.db') db_manager.check_database() cursor = db_manager.conn.cursor() for i in range(0, len(previous_prices)): cursor.execute( "UPDATE Products SET previous_price =? WHERE link=?", (previous_prices[i], links[i])) db_manager.conn.commit() db_manager.close_connection()