forked from daadoonet/digikala-advertising
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsource.py
96 lines (80 loc) · 3.69 KB
/
source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import requests
import re
from bs4 import BeautifulSoup
from unidecode import unidecode
import smtplib
'''
def email(receivers,price):
sender = '[email protected]'
#receivers = ['[email protected]']
message = """From: From Person <[email protected]>
To: To Person <%s>
Subject: digikala advertising
Hello you use my use my program to now when yuor product is fewer than your intended price.
now the price of your protect is %i toman.
let's go and buy it.
""" %(receivers,price)
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print ("Successfully sent email")
except SMTPException:
print ("Error: unable to send email")
'''
def send_email(receivers):
my_email = '[email protected]'
my_email_password = input('please enter password: ')
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(my_email, my_email_password)
message = 'wow the price of this product is fewer than you whant \n it is good time to buy it \n its cost "%s" now !' % (price)
server.sendmail(my_email , receivers , message)
server.quit()
url = input('please enter url of your product page on digikala: ')
if url == '-1':
url = 'https://www.digikala.com/product/dkp-2105089/%DA%AF%D9%88%D8%B4%DB%8C-%D9%85%D9%88%D8%A8%D8%A7%DB%8C%D9%84-%D8%B3%D8%A7%D9%85%D8%B3%D9%88%D9%86%DA%AF-%D9%85%D8%AF%D9%84-galaxy-a30s-sm-a307fnds-%D8%AF%D9%88-%D8%B3%DB%8C%D9%85-%DA%A9%D8%A7%D8%B1%D8%AA-%D8%B8%D8%B1%D9%81%DB%8C%D8%AA-64-%DA%AF%DB%8C%DA%AF%D8%A7%D8%A8%D8%A7%DB%8C%D8%AA'
intended = '4000000'
receivers = '[email protected]'
else:
intended = input('please enter intended price: ')
receivers = input('please enter resivers email: ')
#url = 'https://www.digikala.com/product/dkp-2105089/%DA%AF%D9%88%D8%B4%DB%8C-%D9%85%D9%88%D8%A8%D8%A7%DB%8C%D9%84-%D8%B3%D8%A7%D9%85%D8%B3%D9%88%D9%86%DA%AF-%D9%85%D8%AF%D9%84-galaxy-a30s-sm-a307fnds-%D8%AF%D9%88-%D8%B3%DB%8C%D9%85-%DA%A9%D8%A7%D8%B1%D8%AA-%D8%B8%D8%B1%D9%81%DB%8C%D8%AA-64-%DA%AF%DB%8C%DA%AF%D8%A7%D8%A8%D8%A7%DB%8C%D8%AA'
#url = 'https://www.digikala.com/product/dkp-2172577/%DA%AF%D9%88%D8%B4%DB%8C-%D9%85%D9%88%D8%A8%D8%A7%DB%8C%D9%84-%D8%B3%D8%A7%D9%85%D8%B3%D9%88%D9%86%DA%AF-%D9%85%D8%AF%D9%84-galaxy-a30s-sm-a307fnds-%D8%AF%D9%88-%D8%B3%DB%8C%D9%85-%DA%A9%D8%A7%D8%B1%D8%AA-%D8%B8%D8%B1%D9%81%DB%8C%D8%AA-128-%DA%AF%DB%8C%DA%AF%D8%A7%D8%A8%D8%A7%DB%8C%D8%AA'
try:
json = requests.get(url)
soup = BeautifulSoup(json.text, 'html.parser')
prisehtml = soup.find_all('div',attrs={"class":"c-product__seller-price-raw js-price-value"})
#print(prisehtml)
except:
print('sorry I can not connect to digikala' )
try:
regex = r"^.*>\n(.*)"
test_str = (str(prisehtml))
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
price = match.groups()
#print(price)
price = unidecode(price[0])
price = price.strip()
print('the price of this product is %s' %(price) )
price = price.replace(',','')
#print(price)
except:
print("sory digikala don't have this product")
try:
if price <= intended:
print('wow the price of this product is fewer than you whant \n it is good time to buy it')
send_email(receivers)
print('thank for use my app \n have fun')
#email(receivers,price)
else:
print('sorry it is too expensive yet')
except:
pass
#TODO find some server to run program evry half-hour
#TODO must enter valide info
#TODO make graphical interface