From e8a4b83843e5658fb14c1f934d4045b947659b1f Mon Sep 17 00:00:00 2001 From: Jakub Knetl Date: Tue, 30 Jan 2024 20:36:32 +0100 Subject: [PATCH] Add readme and final improvements --- README.md | 20 ++++++++++++++++++++ mail_sender.py | 2 +- scrape.py | 5 +++-- utils.py | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5aebe4b --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# Lidl price scraper + +Simple app which checks a price of selected items and prints their current price and discount. + +It also sends a notification of items via email any items is on sale and following env variables are defined: + +``` +SCRAPER_SMTP_USER +SCRAPER_SMTP_PASSWORD +SCRAPER_SMTP_USER +``` + +It uses Google SMTP server (you have to provide google app credentials). + + +Run with: + +``` +python scrape.py +``` \ No newline at end of file diff --git a/mail_sender.py b/mail_sender.py index b51c377..bdc5aae 100644 --- a/mail_sender.py +++ b/mail_sender.py @@ -13,7 +13,7 @@ class EmailSender: msg = MIMEMultipart() msg['From'] = self.from_email msg['To'] = to_email - msg['Subject'] = 'Items in action' + msg['Subject'] = f'Lidl has your {len(product_info)} items on sale' body = format_product_table(product_info, tablefmt="html") diff --git a/scrape.py b/scrape.py index ac92095..dfc0681 100644 --- a/scrape.py +++ b/scrape.py @@ -50,5 +50,6 @@ if __name__ == "__main__": products_on_sale = [product for product in product_info if product["discount"] > 0] - sender = EmailSender(os.environ["SCRAPER_SMTP_USER"], os.environ["SCRAPER_SMTP_PASSWORD"]) - sender.send_email(os.environ["SCRAPER_SMTP_USER"], products_on_sale) + if len(products_on_sale) > 0: + sender = EmailSender(os.environ["SCRAPER_SMTP_USER"], os.environ["SCRAPER_SMTP_PASSWORD"]) + sender.send_email(os.environ["SCRAPER_SMTP_USER"], products_on_sale) diff --git a/utils.py b/utils.py index cfe3127..43c1ec6 100644 --- a/utils.py +++ b/utils.py @@ -2,5 +2,5 @@ from tabulate import tabulate def format_product_table(product_info, tablefmt="grid"): headers = ["Product Name", "Price", "Discount", "original price", "URL"] - table_data = [[info["name"], info["price"], info["discount"] + "%", info["originalPrice"], info["url"]] for info in product_info] + table_data = [[info["name"], info["price"], str(info["discount"]) + " %", info["originalPrice"], info["url"]] for info in product_info] return tabulate(table_data, headers=headers, tablefmt=tablefmt)