记录#
百日学习挑战
今天是最后一天了,在最开始的时候也没有想到自己能坚持完成这 100 天的学习,最终还是完成了,中间因为各种事情耽误了不少时间,否则还能再快一些。
从 4 月到 9 月,大约 150 天左右的时间,我收获了一个基础的 python 编程知识。总的感觉下来还是很初级的内容,对 python 的基本操作有了不少认识。如果想要做一些事情,还是需要再继续深入学习,下一步该怎么进行还没有头绪。
总之,这个学习阶段告一段落了,给自己点一个大大的赞,继续加油!我已经证明了自己有恒心和毅力,相信通过持续努力,你、我一定能达到更高的目标!
最后一个学习项目是抓取电商网站的商品价格,如果实际价格低于目标价格,那就发送邮件提醒。
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)