From 802c4247b786a706d76f3eee81fe45af4908fe41 Mon Sep 17 00:00:00 2001 From: keyiflerolsun Date: Wed, 27 Apr 2022 16:46:36 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🕊 --- CONFIG.py | 5 +++ app.py | 93 +++++++++++++++++++++++++++--------------------- requirements.txt | 3 ++ 3 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 CONFIG.py create mode 100644 requirements.txt diff --git a/CONFIG.py b/CONFIG.py new file mode 100644 index 0000000..09e242a --- /dev/null +++ b/CONFIG.py @@ -0,0 +1,5 @@ +HEADER = {'User-Agent' : 'my user agent(google)'} +MAIL_ADDR = "gonderen@gmail.com" +MAIL_PASS = "cokomellisifre" + +RECIEVER = "alici@gmail.com" \ No newline at end of file diff --git a/app.py b/app.py index 52599a7..cd2699d 100644 --- a/app.py +++ b/app.py @@ -1,46 +1,57 @@ -import requests -from bs4 import BeautifulSoup -import smtplib -import time - -url = input('Urun linkini giriniz ') - -headers= {'User-Agent' : 'my user agent(google)'} -def check_price(): - page = requests.get(url,headers=headers) - soup =BeautifulSoup(page.content,'html.parser') - title = soup.find(id ='product-name').get_text().strip() - print(title) - span = soup.find(id ='offering-price') - content = span.attrs.get('content') - price = float(content) +from requests import get +from parsel import Selector +from smtplib import SMTP, SMTPException +from CONFIG import HEADER, MAIL_ADDR, MAIL_PASS, RECIEVER +from schedule import every, run_pending + +URL = None +DEGER = None + +def check_price() -> None: + global URL, DEGER + + if not URL: + URL = input('Urun linkini giriniz : ') + + product_page = get(URL, headers=HEADER) + select = Selector(product_page.text) + + title = select.xpath("normalize-space(//*[contains(@id, 'product-name')])").get() + print(f"\n{title}") + + price = float(select.xpath("//*[contains(@id, 'offering-price')]/@content").get()) print(price) - deger = float(input('Hangi fiyattan asagi dusmesini istiyorsunuz ')) - - if(price None: + try: - server = smtplib.SMTP('smtp.gmail.com',587) - server.ehlo() - server.starttls() - server.login(sender,'gmail app password') - subject = title + ' ' + 'Urun Fiyat Dustu. Yeni Fiyat :' + ' ' + content - body = 'Urune bu linkten gidebilirsin' + ' => ' +url - mailContent = f"To:{reciever}\nFrom:{sender}\nSubject:{subject}\n\n{body}" - server.sendmail(sender,reciever,mailContent) - print('Mail Gonderildi') - except smtplib.SMTPException as e: + mail_server = SMTP('smtp.gmail.com', 587, timeout=60) + mail_server.ehlo() + mail_server.starttls() + mail_server.login(MAIL_ADDR, MAIL_PASS) + + subject = f"{product} Urun Fiyat Dustu. Yeni Fiyat : {price}" + body = f"Urune bu linkten gidebilirsin => {URL}" + content = f"To:{RECIEVER}\nFrom:{MAIL_ADDR}\nSubject:{subject}\n\n{body}" + + mail_server.sendmail(MAIL_ADDR, RECIEVER, content) + + print('Mail Gonderildi!') + except SMTPException as e: print(e) - finally: - server.quit() - -while(1): + mail_server.quit() + +if __name__ == '__main__': check_price() - time.sleep(60*60) \ No newline at end of file + + every(1).hours.do(check_price) + + while True: + run_pending() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..12dde5c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +requests +parsel +schedule \ No newline at end of file