mirror of https://github.com/testerSunshine/12306
修改gbk编码错误
parent
034681619d
commit
89ae08d130
|
@ -69,12 +69,19 @@ class proxy:
|
|||
:return: 可用ip文件list
|
||||
"""
|
||||
path = os.path.join(os.path.dirname(__file__), './proxy_list')
|
||||
with open(path, "r") as f:
|
||||
lins = f.readlines()
|
||||
for i in lins:
|
||||
p = i.strip("\n")
|
||||
self.proxy_filter_list.append(p)
|
||||
return self.proxy_filter_list
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
lins = f.readlines()
|
||||
for i in lins:
|
||||
p = i.strip("\n")
|
||||
self.proxy_filter_list.append(p)
|
||||
except TypeError:
|
||||
with open(path, "r", ) as f:
|
||||
lins = f.readlines()
|
||||
for i in lins:
|
||||
p = i.strip("\n")
|
||||
self.proxy_filter_list.append(p)
|
||||
return self.proxy_filter_list
|
||||
|
||||
def main(self):
|
||||
# self.get_proxy()
|
||||
|
|
|
@ -14,6 +14,7 @@ try:
|
|||
except NameError:
|
||||
pass
|
||||
|
||||
|
||||
class CDNProxy:
|
||||
def __init__(self, host=None):
|
||||
self.host = host
|
||||
|
@ -66,12 +67,20 @@ class CDNProxy:
|
|||
# cdn.append(cdn_list[0].split(":")[0])
|
||||
# return cdn
|
||||
path = os.path.join(os.path.dirname(__file__), '../cdn_list')
|
||||
with open(path, "r") as f:
|
||||
for i in f.readlines():
|
||||
# print(i.replace("\n", ""))
|
||||
if i and "kyfw.12306.cn:443" not in i:
|
||||
cdn.append(i.replace("\n", ""))
|
||||
return cdn
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
for i in f.readlines():
|
||||
# print(i.replace("\n", ""))
|
||||
if i and "kyfw.12306.cn:443" not in i:
|
||||
cdn.append(i.replace("\n", ""))
|
||||
return cdn
|
||||
except TypeError:
|
||||
with open(path, "r") as f:
|
||||
for i in f.readlines():
|
||||
# print(i.replace("\n", ""))
|
||||
if i and "kyfw.12306.cn:443" not in i:
|
||||
cdn.append(i.replace("\n", ""))
|
||||
return cdn
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -71,6 +71,21 @@ def decMakeDir(func):
|
|||
def getWorkDir():
|
||||
return os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
#
|
||||
# def fileOpen(path):
|
||||
# """
|
||||
# 文件读取兼容2和3
|
||||
# :param path: 文件读取路径
|
||||
# :return:
|
||||
# """
|
||||
# try:
|
||||
# with open(path, "r", ) as f:
|
||||
# return f
|
||||
# except TypeError:
|
||||
# with open(path, "r", ) as f:
|
||||
# return f
|
||||
|
||||
|
||||
|
||||
@decMakeDir
|
||||
def getTmpDir():
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
# -*- coding: utf8 -*-
|
||||
from config import configCommon
|
||||
|
||||
__author__ = 'MR.wen'
|
||||
import os
|
||||
import yaml
|
||||
|
@ -10,9 +12,12 @@ def _get_yaml():
|
|||
:return: s 字典
|
||||
"""
|
||||
path = os.path.join(os.path.dirname(__file__) + '/ticket_config.yaml')
|
||||
f = open(path)
|
||||
s = yaml.load(f)
|
||||
f.close()
|
||||
try: # 兼容2和3版本
|
||||
with open(path, encoding="utf-8") as f:
|
||||
s = yaml.load(f)
|
||||
except TypeError:
|
||||
with open(path) as f:
|
||||
s = yaml.load(f)
|
||||
return s.decode() if isinstance(s, bytes) else s
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ set:
|
|||
# - 2018-01-06
|
||||
# - 2018-01-07
|
||||
station_dates:
|
||||
- "2019-02-10"
|
||||
- "2019-02-11"
|
||||
- "2019-01-18"
|
||||
|
||||
# 是否根据时间范围 和 乘车类型 购票
|
||||
# 否则将需要手动填写车次
|
||||
|
@ -61,13 +60,12 @@ set:
|
|||
# - "张三"
|
||||
# - "李四"
|
||||
ticke_peoples:
|
||||
- ""
|
||||
- ""
|
||||
- "屈兴明"
|
||||
|
||||
# 12306登录账号(list)
|
||||
12306account:
|
||||
- user: "931128603@qq.com"
|
||||
- pwd: ""
|
||||
- user: "qqxin1011"
|
||||
- pwd: "quxm19861011"
|
||||
|
||||
# 加入小黑屋时间默认为5分钟,此功能为了防止僵尸票导致一直下单不成功错过正常的票,
|
||||
ticket_black_list_time: 5
|
||||
|
@ -81,7 +79,7 @@ auto_code_type: 2
|
|||
# 打码平台账号
|
||||
auto_code_account:
|
||||
user: "931128603"
|
||||
pwd: ""
|
||||
pwd: "wen1995"
|
||||
|
||||
# 邮箱配置,如果抢票成功,将通过邮件配置通知给您
|
||||
# 列举163
|
||||
|
@ -106,8 +104,8 @@ email_conf:
|
|||
|
||||
# 是否开启 pushbear 微信提醒, 使用前需要前往 http://pushbear.ftqq.com 扫码绑定获取 send_key 并关注获得抢票结果通知的公众号
|
||||
pushbear_conf:
|
||||
is_pushbear: False
|
||||
send_key: ""
|
||||
is_pushbear: True
|
||||
send_key: "8635-2e509149e360806feca5b76621c7d219"
|
||||
|
||||
# 是否开启cdn查询,可以更快的检测票票 1为开启,2为关闭
|
||||
is_cdn: 1
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
# -*- coding=utf-8 -*-
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import base64
|
||||
import requests
|
||||
|
||||
from myException.balanceException import balanceException
|
||||
|
||||
|
||||
def md5str(str): # md5加密字符串
|
||||
m = hashlib.md5(str.encode(encoding="utf-8"))
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
def md5(byte): # md5加密byte
|
||||
return hashlib.md5(byte).hexdigest()
|
||||
|
||||
|
||||
class DamatuApi():
|
||||
ID = '40838'
|
||||
KEY = 'ca9507e17e8d5ddf7c57cd18d8d33010'
|
||||
HOST = 'http://api.dama2.com:7766/app/'
|
||||
|
||||
def __init__(self, username, password, file_path=None):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.file_path = file_path
|
||||
|
||||
def getSign(self, param=b''):
|
||||
return (md5(bytes(self.KEY) + bytes(self.username) + param))[:8]
|
||||
|
||||
def getPwd(self):
|
||||
return md5str(self.KEY + md5str(md5str(self.username) + md5str(self.password)))
|
||||
|
||||
def post(self, path, params={}):
|
||||
data = params
|
||||
url = self.HOST + path
|
||||
response = requests.post(url, data)
|
||||
return response.content
|
||||
|
||||
# 查询余额 return 是正数为余额 如果为负数 则为错误码
|
||||
def getBalance(self):
|
||||
data = {'appID': self.ID,
|
||||
'user': self.username,
|
||||
'pwd': self.getPwd(),
|
||||
'sign': self.getSign()
|
||||
}
|
||||
res = self.post('d2Balance', data)
|
||||
res = str(res)
|
||||
jres = json.loads(res)
|
||||
if jres['ret'] == 0:
|
||||
return jres['balance']
|
||||
else:
|
||||
return jres['ret']
|
||||
|
||||
# 上传验证码 参数filePath 验证码图片路径 如d:/1.jpg type是类型,查看http://wiki.dama2.com/index.php?n=ApiDoc.Pricedesc return 是答案为成功 如果为负数 则为错误码
|
||||
def decode(self, type):
|
||||
f = open(self.file_path, 'rb')
|
||||
fdata = f.read()
|
||||
filedata = base64.b64encode(fdata)
|
||||
f.close()
|
||||
data = {'appID': self.ID,
|
||||
'user': self.username,
|
||||
'pwd': self.getPwd(),
|
||||
'type': type,
|
||||
'fileDataBase64': filedata,
|
||||
'sign': self.getSign(fdata)
|
||||
}
|
||||
res = self.post('d2File', data)
|
||||
res = str(res)
|
||||
jres = json.loads(res)
|
||||
if jres['ret'] == 0:
|
||||
# 注意这个json里面有ret,id,result,cookie,根据自己的需要获取
|
||||
return jres['result']
|
||||
else:
|
||||
return jres['ret']
|
||||
|
||||
# url地址打码 参数 url地址 type是类型(类型查看http://wiki.dama2.com/index.php?n=ApiDoc.Pricedesc) return 是答案为成功 如果为负数 则为错误码
|
||||
def decodeUrl(self, url, type):
|
||||
data = {'appID': self.ID,
|
||||
'user': self.username,
|
||||
'pwd': self.getPwd(),
|
||||
'type': type,
|
||||
'url': url,
|
||||
'sign': self.getSign(url.encode(encoding="utf-8"))
|
||||
}
|
||||
res = self.post('d2Url', data)
|
||||
res = str(res,)
|
||||
jres = json.loads(res)
|
||||
if jres['ret'] == 0:
|
||||
# 注意这个json里面有ret,id,result,cookie,根据自己的需要获取
|
||||
return (jres['result'])
|
||||
else:
|
||||
return jres['ret']
|
||||
|
||||
# 报错 参数id(string类型)由上传打码函数的结果获得 return 0为成功 其他见错误码
|
||||
def reportError(self, id):
|
||||
data = {'appID': self.ID,
|
||||
'user': self.username,
|
||||
'pwd': self.getPwd(),
|
||||
'id': id,
|
||||
'sign': self.getSign(id.encode(encoding="utf-8"))
|
||||
}
|
||||
res = self.post('d2ReportError', data)
|
||||
res = str(res)
|
||||
jres = json.loads(res)
|
||||
return jres['ret']
|
||||
|
||||
def main(self):
|
||||
result = self.decode(287)
|
||||
img_code = result.replace('|', ',') if not isinstance(result, int) else ""
|
||||
print("验证码识别坐标为{0}".format(img_code))
|
||||
return img_code
|
||||
|
||||
# # 调用类型实例:
|
||||
# # 1.实例化类型 参数是打码兔用户账号和密码
|
||||
# dmt = DamatuApi("wenxianping", "wen1995")
|
||||
# # 2.调用方法:
|
||||
# print(dmt.getBalance()) # 查询余额
|
||||
# print(dmt.decode('tkcode', 287)) # 上传打码
|
||||
# # print(dmt.decodeUrl('https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=login&rand=sjrand&0.7586344633015405', 310)) # 上传打码
|
||||
# # print(dmt.reportError('894657096')) # 上报错误
|
|
@ -137,8 +137,12 @@ class select:
|
|||
:return:
|
||||
"""
|
||||
path = os.path.join(os.path.dirname(__file__), '../station_name.txt')
|
||||
result = open(path)
|
||||
info = result.read().split('=')[1].strip("'").split('@')
|
||||
try:
|
||||
with open(path, encoding="utf-8") as result:
|
||||
info = result.read().split('=')[1].strip("'").split('@')
|
||||
except TypeError:
|
||||
with open(path) as result:
|
||||
info = result.read().split('=')[1].strip("'").split('@')
|
||||
del info[0]
|
||||
station_name = {}
|
||||
for i in range(0, len(info)):
|
||||
|
|
|
@ -26,7 +26,12 @@ def getPassCodeNewOrderAndLogin(session, imgType):
|
|||
return False
|
||||
else:
|
||||
print(u"下载验证码成功")
|
||||
open(img_path, 'wb').write(result)
|
||||
try:
|
||||
with open(img_path, 'wb', encoding="utf-8") as img:
|
||||
img.write(result)
|
||||
except TypeError:
|
||||
with open(img_path, 'wb') as img:
|
||||
img.write(result)
|
||||
return result
|
||||
except OSError:
|
||||
print (u"验证码下载失败,可能ip被封,确认请手动请求: {0}".format(codeImgUrl))
|
||||
|
|
Loading…
Reference in New Issue