forked from cycz/jdBuyMask
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# -*- coding=utf-8 -*- | ||
from log.jdlogger import logger | ||
from jdlogger import logger | ||
|
||
''' | ||
找一条第一个版本的url | ||
''' | ||
url = 'https://c0.3.cn/stock?skuId=1336984&area=19_1607_4773_0&venderId=1000078145&buyNum=1&choseSuitSkuIds=&cat=9192,12190,1517&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=jd_7c3992aa27d1a&pduid=1580535906442142991701&ch=1&callback=jQuery6715489' | ||
url = 'https://c0.3.cn/stock?skuId=100003406321&area=19_1607_4773_0&venderId=1000000946&buyNum=1&choseSuitSkuIds=&cat=9192,9197,12588&extraParam={%22originid%22:%221%22}&fqsp=0&pdpin=jd_7c3992aa27d1a&pduid=1580535906442142991701&ch=1&callback=jQuery4291064' | ||
skuId = url.split('skuId=')[1].split('&')[0] | ||
area = url.split('area=')[1].split('&')[0] | ||
logger.info('你的area是[ %s ],链接的商品id是[ %s ]', area, skuId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
import configparser | ||
|
||
|
||
class Config(object): | ||
def __init__(self, config_file='configDemo.ini'): | ||
self._path = os.path.join(os.getcwd(), config_file) | ||
if not os.path.exists(self._path): | ||
raise FileNotFoundError("No such file: config.ini") | ||
self._config = configparser.ConfigParser() | ||
self._config.read(self._path, encoding='utf-8-sig') | ||
self._configRaw = configparser.RawConfigParser() | ||
self._configRaw.read(self._path, encoding='utf-8-sig') | ||
|
||
def get(self, section, name): | ||
return self._config.get(section, name) | ||
|
||
def getRaw(self, section, name): | ||
return self._configRaw.get(section, name) | ||
|
||
|
||
global_config = Config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding=utf-8 -*- | ||
''' | ||
发送邮件模块 | ||
''' | ||
import traceback | ||
|
||
|
||
def sendMail(mail, msgtext): | ||
try: | ||
import smtplib | ||
from email.mime.text import MIMEText | ||
# email 用于构建邮件内容 | ||
from email.header import Header | ||
|
||
# 用于构建邮件头 | ||
# 发信方的信息:发信邮箱,QQ 邮箱授权码 | ||
from_addr = '[email protected]' | ||
password = 'alpsneahcyz123' | ||
|
||
# 收信方邮箱 | ||
to_addr = mail | ||
# 发信服务器 | ||
smtp_server = 'smtp.163.com' | ||
# 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码 | ||
msg = MIMEText(msgtext, 'plain', 'utf-8') | ||
# 邮件头信息 | ||
# msg['From'] = Header(from_addr) | ||
msg['From'] = Header(u'from Mark<{}>'.format(from_addr), 'utf-8') | ||
msg['To'] = Header(to_addr) | ||
msg['Subject'] = Header('京东口罩监控','utf-8') | ||
# 开启发信服务,这里使用的是加密传输 | ||
server = smtplib.SMTP_SSL(host=smtp_server) | ||
server.connect(smtp_server, 465) | ||
# 登录发信邮箱 | ||
server.login(from_addr, password) | ||
# 发送邮件 | ||
server.sendmail(from_addr, to_addr, msg.as_string()) | ||
# 关闭服务器 | ||
server.quit() | ||
except Exception as e: | ||
print(traceback.format_exc()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding=utf-8 -*- | ||
import logging | ||
import logging.handlers | ||
''' | ||
日志模块 | ||
''' | ||
LOG_FILENAME = 'jdBuyMask.log' | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
def set_logger(): | ||
logger.setLevel(logging.INFO) | ||
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s') | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
logger.addHandler(console_handler) | ||
|
||
file_handler = logging.handlers.RotatingFileHandler( | ||
LOG_FILENAME, maxBytes=10485760, backupCount=5, encoding="utf-8") | ||
file_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
|
||
|
||
set_logger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- encoding=utf8 -*- | ||
from jdEmail import sendMail | ||
from wechat_ftqq import sendWechat | ||
|
||
|
||
class message(object): | ||
"""消息推送类""" | ||
|
||
def __init__(self, messageTtpe, sc_key, mail): | ||
if messageTtpe == '2': | ||
if not sc_key: | ||
raise Exception('sc_key can not be empty') | ||
self.sc_key = sc_key | ||
elif messageTtpe == '1': | ||
if not mail: | ||
raise Exception('mail can not be empty') | ||
self.mail = mail | ||
self.messageTtpe = messageTtpe | ||
|
||
def send(self, desp='', isOrder=False): | ||
desp = str(desp) | ||
if isOrder: | ||
msg = desp + ' 类型口罩,已经下单了。24小时内付款' | ||
else: | ||
msg = desp + ' 类型口罩,下单失败了,快去抢购!' | ||
if self.messageTtpe == '1': | ||
sendMail(self.mail, msg) | ||
if self.messageTtpe == '2': | ||
sendWechat(sc_key=self.sc_key, desp=msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python | ||
# -*- encoding=utf8 -*- | ||
import datetime | ||
import json | ||
|
||
import requests | ||
|
||
from jdlogger import logger | ||
|
||
|
||
def sendWechat(sc_key, text='京东商品监控', desp=''): | ||
if not text.strip(): | ||
logger.error('Text of message is empty!') | ||
return | ||
|
||
now_time = str(datetime.datetime.now()) | ||
desp = '[{0}]'.format(now_time) if not desp else '{0} [{1}]'.format(desp, now_time) | ||
|
||
try: | ||
resp = requests.get( | ||
'https://sc.ftqq.com/{}.send?text={}&desp={}'.format(sc_key, text, desp) | ||
) | ||
resp_json = json.loads(resp.text) | ||
if resp_json.get('errno') == 0: | ||
logger.info('Message sent successfully [text: %s, desp: %s]', text, desp) | ||
else: | ||
logger.error('Fail to send message, reason: %s', resp.text) | ||
except requests.exceptions.RequestException as req_error: | ||
logger.error('Request error: %s', req_error) | ||
except Exception as e: | ||
logger.error('Fail to send message [text: %s, desp: %s]: %s', text, desp, e) |