def deploy_to_database(self): db = MySQLDatabase() for product in self.products: db._insert_query(product) for update in self.updates: db._update_query(update) db.close()
return set_numbers db = MySQLDatabase() ps = ProductScanner() set_number = 0 eol_url = 'https://www.stonewars.de/news/lego-end-of-life-eol-2020/' soup = ps._get_soup(eol_url, headers={}) eol_sets_raw = [ _get_set_numbers_from_string(_.text) for _ in soup.find_all('td', {'class': 'column-2'}) ] eol_sets = [item for sublist in eol_sets_raw for item in sublist] for set_number in eol_sets: logging.info( "[EOL] {} has been defined as end of life ...".format(set_number)) update_data = { 'table_name': 'tbl_sets', 'data': { 'is_eol': True }, 'condition': { 'set_number': set_number } } db._update_query(update_data)
from send_mail import send_mail q = Queries() db = MySQLDatabase() for row in q.get_subscriptions(): entries = q.get_current_prices_for_set(row['set_number']) low_prices = [r for r in entries if r['price'] < row['price_treshold']] if low_prices: for d in low_prices: mail_body = "Set: https://svenborer.ch/lego-priisvrgliich/set/{} {}\nThema: {}/{}\nStei/Minifigure: {}/{}\nPriis: {} CHF\nUVP: {} CHF\nTreshold: {} CHF\nRabatt: {}%\nAhbieter: {}\nURL: {}" body = mail_body.format(d['set_number'], d['name'], d['theme'], d['subtheme'], d['pieces'], d['minifigs'], d['price'], d['ch_price'], row['price_treshold'], round(d['save_in_percentage_lp'], 1), d['provider'], d['url']) subject = '[L-PVG-P-S] {}|{}'.format(d['set_number'], d['name']) to = row['email'] send_mail(to, subject, body) payload = { 'table_name': 'tbl_subscriptions', 'data': { 'notified': 1 }, 'condition': { 'id': row['id'] } } db._update_query(payload)