Skip to content

Commit

Permalink
优化部分文件
Browse files Browse the repository at this point in the history
  • Loading branch information
heima committed Jan 2, 2021
1 parent 3facb33 commit 7cf1049
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fp = ""
# 商品id
# 已经是茅台的sku_id了
sku_id = 100012043978
# 设定时间 # 2020-12-09 10:00:00.100000
# 修改成每天的几点几分几秒几毫秒
# 设定时间
# 修改成几点几分几秒几毫秒 以下时间根据jd抢购时间修改
buy_time = 09:59:59.500
# 每天的最后购买时间
last_purchase_time = 10:00:03.000
Expand Down
6 changes: 6 additions & 0 deletions error/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Created on 2021/01/02 21:45
"""
File renamed without changes.
6 changes: 6 additions & 0 deletions helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Created on 2021/01/02 21:39
"""
8 changes: 4 additions & 4 deletions util.py → helper/jd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import time

from config import global_config
from maotai.config import global_config

USER_AGENTS = [
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
Expand Down Expand Up @@ -57,7 +57,7 @@
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15",
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.14 (KHTML, like Gecko) Chrome/24.0.1292.0 Safari/537.14"
]
]


def parse_json(s):
Expand All @@ -81,11 +81,11 @@ def send_wechat(message):
"""推送信息到微信"""
url = 'http://sc.ftqq.com/{}.send'.format(global_config.getRaw('messenger', 'sckey'))
payload = {
"text":'抢购结果',
"text": '抢购结果',
"desp": message
}
headers = {
'User-Agent':global_config.getRaw('config', 'DEFAULT_USER_AGENT')
'User-Agent': global_config.getRaw('config', 'DEFAULT_USER_AGENT')
}
requests.get(url, params=payload, headers=headers)

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from jd_spider_requests import JdSeckill

from maotai.jd_spider_requests import JdSeckill

if __name__ == '__main__':
a = """
Expand Down
6 changes: 6 additions & 0 deletions maotai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# !/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Created on 2021/01/02 21:39
"""
File renamed without changes.
6 changes: 4 additions & 2 deletions jd_logger.py → maotai/jd_logger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging
import logging.handlers

'''
日志模块
'''
LOG_FILENAME = 'jd_seckill.log'
LOG_FILENAME = '../jd_seckill.log'
logger = logging.getLogger()


Expand All @@ -19,4 +20,5 @@ def set_logger():
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)

set_logger()

set_logger()
17 changes: 11 additions & 6 deletions jd_spider_requests.py → maotai/jd_spider_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import pickle

from lxml import etree
from jd_logger import logger
from timer import Timer
from config import global_config

from error.exception import SKException
from maotai.jd_logger import logger
from maotai.timer import Timer
from maotai.config import global_config
from concurrent.futures import ProcessPoolExecutor
from exception import SKException
from util import (
from helper.jd_helper import (
parse_json,
send_wechat,
wait_some_time,
Expand All @@ -26,6 +27,7 @@ class SpiderSession:
"""
Session相关操作
"""

def __init__(self):
self.cookies_dir_path = "./cookies/"
self.user_agent = global_config.getRaw('config', 'DEFAULT_USER_AGENT')
Expand Down Expand Up @@ -101,6 +103,7 @@ class QrLogin:
"""
扫码登录
"""

def __init__(self, spider_session: SpiderSession):
"""
初始化扫码登录
Expand All @@ -110,7 +113,7 @@ def __init__(self, spider_session: SpiderSession):
3、校验票据
:param spider_session:
"""
self.qrcode_img_file = 'qr_code.png'
self.qrcode_img_file = '../qr_code.png'

self.spider_session = spider_session
self.session = self.spider_session.get_session()
Expand Down Expand Up @@ -302,12 +305,14 @@ def check_login(func):
"""
用户登陆态校验装饰器。若用户未登陆,则调用扫码登陆
"""

@functools.wraps(func)
def new_func(self, *args, **kwargs):
if not self.qrlogin.is_login:
logger.info("{0} 需登陆后调用,开始扫码登陆".format(func.__name__))
self.login_by_qrcode()
return func(self, *args, **kwargs)

return new_func

@check_login
Expand Down
4 changes: 2 additions & 2 deletions timer.py → maotai/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import json

from datetime import datetime
from jd_logger import logger
from config import global_config
from maotai.jd_logger import logger
from maotai.config import global_config


class Timer(object):
Expand Down

0 comments on commit 7cf1049

Please sign in to comment.