-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadidas_orginal_price_monitor.py
60 lines (46 loc) · 1.52 KB
/
adidas_orginal_price_monitor.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
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from settings import (SMTP_SERVER,
PORT,
SENDER,
CODE,
RECEIVER,
URL,
MSGTEMP)
import requests
from bs4 import BeautifulSoup
import click
@click.command()
@click.option('--exprice', default=800,
prompt='expected_price', help='期望价格')
@click.argument('artnos', nargs=-1)
def get_price(artnos, exprice):
article_nos = artnos
expected_price = exprice
for article_no in article_nos:
res = requests.get(URL+article_no)
bea = BeautifulSoup(res.content)
divs = bea.find_all('div', class_='pdpInfo')
price = divs[0].div.div.div.p.span.contents[0]
price = price[1:].replace(',', '')
price = float(price)
if price < expected_price:
print(price)
send_mail(article_no, expected_price, price)
def send_mail(article_no, expected_price, now_price):
server = smtplib.SMTP(SMTP_SERVER, PORT)
msg = MIMEText(
MSGTEMP.format(article_no, expected_price, now_price),
'plain',
'utf-8'
)
msg['From'] = SENDER
msg['To'] = RECEIVER
msg['Subject'] = Header('降价监控', 'utf-8').encode()
server.starttls()
server.login(SENDER, CODE)
server.sendmail(SENDER, RECEIVER, msg.as_string())
server.quit()
if __name__ == '__main__':
get_price()