Add readme and final improvements
This commit is contained in:
20
README.md
Normal file
20
README.md
Normal 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
|
||||
```
|
||||
@@ -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")
|
||||
|
||||
@@ -50,5 +50,6 @@ if __name__ == "__main__":
|
||||
|
||||
products_on_sale = [product for product in product_info if product["discount"] > 0]
|
||||
|
||||
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)
|
||||
|
||||
2
utils.py
2
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)
|
||||
|
||||
Reference in New Issue
Block a user