Record#
100 Days Learning Challenge
Today is the last day. At the beginning, I didn't expect that I could persist and complete this 100-day learning challenge, but in the end, I did it. I was delayed by various things in the middle, otherwise I could have been faster.
From April to September, about 150 days, I gained a basic knowledge of Python programming. Overall, it still feels very basic, but I have gained a lot of understanding of the basic operations of Python. If I want to do something, I still need to continue learning in depth. I don't have any idea about the next steps.
In short, this learning phase has come to an end. Give myself a big thumbs up and keep going! I have proven to myself that I have perseverance and determination. I believe that through continuous efforts, you and I will definitely achieve higher goals!
The last learning project is to scrape the prices of products on e-commerce websites and send email reminders if the actual price is lower than the target price.
CODE#
main.py#
from replit import db
import schedule, time, os, smtplib, requests
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from bs4 import BeautifulSoup
password = os.environ['p']
username = os.environ['u']
def addinfo():
#url = "https://www.wexphotovideo.com/canon-imageprograf-pro-300-printer-1745230/"
url = input("URL: ")
target_price = input("Target Price: ")
db[time.time()] = {"url": url, "target_price": target_price}
def sendMail(text):
server = "smtp.gmail.com"
port = 587
s = smtplib.SMTP(host=server, port=port)
s.starttls()
s.login(username, password)
msg = MIMEMultipart()
msg['To'] = "[email protected]"
msg['From'] = username
msg['Subject'] = "Take a BREAK"
msg.attach(MIMEText(text, 'html'))
s.send_message(msg)
del msg
def shop():
if db.keys():
for key in db.keys():
url = key["url"]
target_price=key["target_price"]
else:
addinfo()
respone = requests.get(url)
html = respone.text
soup = BeautifulSoup(html, 'html.parser')
price = soup.find("span", {"class", "price"}).text
original_price = price.replace("£", "")
if original_price < target_price:
text = f" GOGOGO! <a href={url}>BUY</a>"
sendMail(text)
schedule.day(1).hours.do(shop) # Changed the interval to every 1 hour
while True:
schedule.run_pending()
#print(searchkey())
time.sleep(1)