Add readme and final improvements

This commit is contained in:
2024-01-30 20:36:32 +01:00
parent 849a076b51
commit e8a4b83843
4 changed files with 25 additions and 4 deletions

20
README.md Normal file
View File

@@ -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
```

View File

@@ -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")

View File

@@ -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)

View File

@@ -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)