Record#
100-Day Learning Challenge
Today is the last day, and at the beginning, I didn't expect myself to be able to 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, I feel that the content is still 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 a clue about the next steps.
In conclusion, this learning phase has come to an end. I give myself a big thumbs up and keep going! I have proven 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 from an e-commerce website. If the actual price is lower than the target price, an email will be sent.
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)