Neculai Fântânaru

Everything Depends On The Leader

Python: Notify Me by Email When A Certain Product Appears In The Store Depending On The Lowest Price

On March 16, 2022
, in
Python Scripts Examples by Neculai Fantanaru

You can view the full code here: https://pastebin.com/ND8EYTxA

Install Python

I will take the site as an example https://www.okazii.ro/

Also as an example of a product on this website, I will look for the book: "Studiul desenului, culorii, compozitiei si expresiei in arta eclesiala"

The Python code will have to notify me by email when this book returns to stock, with a price of less than 90 RON.

Mention: If you want this code to run continuously in the background, you will need to change the file extension from .py in .pyw

Before running the script you need to do the following:

From the CMD (command prompt) console, run the command:pip install pythonw

To start the program run the following command in CMD (in the folder where the file is located):

pythonw okazii.pyw

Now the process will run continuously in the background. To stop the process, you must run the command:

TASKKILL /F /IM pythonw.exe

CAREFUL ! ! ! All commands are run from the command line in the folder where the file is located.

If you want to simply run the file with python okazii.pyw, you can do that too, but you should always keep the console open. You can stop the execution with ctrl + C from Command Prompt (CMD)

Do not use GMAIL for default email adress !

#-------------------------------------------------------------------------------
# Author:      Fantanaru Neculai
#
# Created:     16/03/2022
# Copyright:   (c) Fantanaru Neculai 2022
#-------------------------------------------------------------------------------

from bs4 import BeautifulSoup as bs
import pandas as pd
pd.set_option('display.max_colwidth', 500)
import time
import requests
import random
import re

page = requests.get("https://www.okazii.ro/")

soup = bs(page.content)

# Studiul desenului, culorii, compozitiei si expresiei in arta eclesiala
result = requests.get("https://www.okazii.ro/cautare/studiul+desenului%2C+culorii%2C+compozitiei+si+expresiei+in+arta+eclesiala.html")

# preluam text dintre <!-- END SPECIALE IN LISTA--> si <!-- RECENT INTRODUSE -->
produse_sectiune_pattern = re.compile('<!-- END SPECIALE IN LISTA-->([\s\S]*?)<div id=\'div-gpt-ad-15\'>')
produse_sectiune = re.findall(produse_sectiune_pattern, result.text)
produse_sectiune = produse_sectiune[0]

preturi_pattern = re.compile('<span class=\"prSup\"><span>(.*?)</span><span class=\"seo-price-indent\">')
preturi = re.findall(preturi_pattern, produse_sectiune)
print(preturi)

count = 0
for pret in preturi:
    if int(pret) < 90:  # puneti <= daca vreti ca pretul sa fie si egal cu 90 RON
        count += 1
print("Am gasit {} oferte cu pretul sub 90 lei.".format(count))

# soup_cautare = bs(result.text, 'html.parser')
# print(soup_cautare)

#items = soup_cautare.find_all(class_ = 'listing-product ')
#print(items)


# Trimitere email
import sys
import smtplib

from_addr = 'YOUR EMAIL ADRESS'
to_addrs = ['YOUR EMAIL ADRESS']
msg = """From: Sender
To: Recipient
Subject: Okazii

Am gasit 1 oferte cu pretul sub 90 lei.
"""

try:
    s = smtplib.SMTP('mail.neculaifantanaru.com', 26)  # put here your own SMTP PORT and hosting email
    s.login('YOUR EMAIL ADRESS', 'PASSWORD')  # do not use GMAIL !!
    s.sendmail(from_addr, to_addrs, msg)
    s.quit()
except smtplib.SMTPException:
    print("Error: ", sys.exc_info()[0])

That's all folks.

If you like my code, then make me a favor: translate your website into Romanian, "ro".

Also, see this VERSION 2 or VERSION 3 or VERSION 4 or VERSION 5 or VERSION 6 or VERSION 7

Alatura-te Comunitatii Neculai Fantanaru
The 63 Greatest Qualities of a Leader
Cele 63 de calităţi ale liderului

Why read this book? Because it is critical to optimizing your performance. Because it reveals the main coordinates after that are build the character and skills of the leaders, highlighting what it is important for them to increase their influence.

Leadership - Magic of Mastery
Atingerea maestrului

The essential characteristic of this book in comparison with others on the market in the same domain is that it describes through examples the ideal competences of a leader. I never claimed that it's easy to become a good leader, but if people will...

The Master Touch
Leadership - Magia măiestriei

For some leaders, "leading" resembles more to a chess game, a game of cleverness and perspicacity; for others it means a game of chance, a game they think they can win every time risking and betting everything on a single card.

Leadership Puzzle
Leadership Puzzle

I wrote this book that conjoins in a simple way personal development with leadership, just like a puzzle, where you have to match all the given pieces in order to recompose the general image.

Performance in Leading
Leadership - Pe înţelesul tuturor

The aim of this book is to offer you information through concrete examples and to show you how to obtain the capacity to make others see things from the same angle as you.

Leadership for Dummies
Leadership - Pe înţelesul tuturor

Without considering it a concord, the book is representing the try of an ordinary man - the author - who through simple words, facts and usual examples instills to the ordinary man courage and optimism in his own quest to be his own master and who knows... maybe even a leader.