Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 135f6fb

Browse files
committed
接口开卡
1 parent e676449 commit 135f6fb

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

远程文件传输/register_3_24.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# @Time : 2020/3/24 16:42
2+
# @Author : Libuda
3+
# @FileName: register_3_24.py
4+
# @Software: PyCharm
5+
6+
import requests
7+
import xlrd
8+
from xlutils.copy import copy
9+
import time
10+
from 远程文件传输.config import get_config
11+
import pandas as pd
12+
from pandas import DataFrame
13+
from copy import deepcopy
14+
15+
config = get_config()
16+
17+
user_list = ['1364826576@qq.com']
18+
19+
wait_time = 0.5 # 各个阶段等待时间
20+
time_jiange = 30 # 时间间隔 隔多长时间执行脚本一次
21+
22+
ding_num = 5 # 链接条数报警阈值
23+
24+
link_file_path = config['link_file_path']
25+
26+
link_ecel = xlrd.open_workbook(link_file_path)
27+
link_tables = link_ecel.sheet_by_index(0)
28+
link_get_col = 2
29+
link_write_col = 3
30+
31+
link_can_use_index = int(config['start_link_index'])
32+
totle_break_set = set()
33+
34+
35+
def logger(msg):
36+
"""
37+
日志信息
38+
"""
39+
now = time.ctime()
40+
print("[%s] %s" % (now, msg))
41+
42+
43+
def get_keywords_data(tables, row, col):
44+
actual_data = tables.cell_value(row, col)
45+
return actual_data
46+
47+
48+
def write_to_excel(file_path, row, col, value):
49+
work_book = xlrd.open_workbook(file_path, formatting_info=False)
50+
write_to_work = copy(work_book)
51+
sheet_data = write_to_work.get_sheet(0)
52+
sheet_data.write(row, col, str(value))
53+
write_to_work.save(file_path)
54+
55+
56+
def register_by_phone(link, phone):
57+
logger("开卡中:链接:{},手机号{}".format(link, phone))
58+
res = "领取失败"
59+
link_id = link.split("=")[1]
60+
base_url = "https://cardapi.dushu.io/WebRedeem/RedeemCard"
61+
base_data = {
62+
"id": link_id,
63+
"name": phone,
64+
"mobile": phone,
65+
"positioning": ""
66+
}
67+
headers = {
68+
"user-agent": "Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20"}
69+
try:
70+
response = requests.post(base_url, data=base_data, headers=headers).json()
71+
print(response)
72+
status = str(response['status'])
73+
print("status", status)
74+
if status == "0":
75+
print("message", response['message'])
76+
if response['message'] == "操作成功":
77+
res = "开卡成功 \n " \
78+
"会员截止日期:{} \n ".format(response['userInfo']['endTimeStr'])
79+
else:
80+
res = "开卡失败"
81+
if status == "7":
82+
res = "同一类型的读书卡不可重复使用"
83+
elif status == "2" or status == "6":
84+
res = "您已经是樊登读书书友"
85+
elif status == "5":
86+
res = "该卡仅限首次开通VIP的书友使用"
87+
elif status == "1":
88+
res = "该读书卡已被使用"
89+
elif status == "3":
90+
res = "无效的读书卡"
91+
elif status == "4":
92+
res = "实体卡已过期"
93+
elif status == "8":
94+
res = "手机号码格式不正确"
95+
elif status == "9":
96+
res = "用户异常,领取失败"
97+
98+
return res
99+
except Exception as e:
100+
print(e)
101+
return res
102+
103+
104+
def register(phone):
105+
df = pd.read_excel(link_file_path)
106+
link_data = []
107+
for i in df.index.values: # 获取行号的索引,并对其进行遍历:
108+
# 根据i来获取每一行指定的数据 并利用to_dict转成字典
109+
row_data = df.loc[i, ['id', 'link']].to_dict()
110+
link_data.append(row_data)
111+
link_data_tem = deepcopy(link_data)
112+
writer = pd.ExcelWriter(link_file_path, cell_overwrite_ok=True)
113+
dataframe = DataFrame()
114+
115+
for index, data in enumerate(link_data):
116+
link = data['link']
117+
res = register_by_phone(link, phone)
118+
if res.startswith("开卡成功"):
119+
link_data_tem.pop(0)
120+
res += "请添加客服微信:95499954,另外最新整理的完整书单。"
121+
else:
122+
if res == "该读书卡已被使用":
123+
link_data_tem.pop(0)
124+
print("该卡已被使用,换卡中")
125+
continue
126+
res += "请添加客服微信:95499954"
127+
if len(link_data_tem) <= 0:
128+
link_data_tem = [{"id": "", "link": ""}]
129+
if res == "该读书卡已被使用":
130+
link_data_tem.pop(0)
131+
dataframe = dataframe.append(DataFrame(link_data_tem))
132+
dataframe.to_excel(writer, index=0)
133+
writer.save()
134+
135+
return res, len(link_data_tem)
136+
137+
link_data_tem = [{"id": "", "link": ""}]
138+
dataframe = dataframe.append(DataFrame(link_data_tem))
139+
dataframe.to_excel(writer, index=0)
140+
writer.save()
141+
142+
return "链接数不足,请添加客服微信:95499954", 0
143+
144+
145+
if __name__ == '__main__':
146+
# 开卡成功的返回结果
147+
dic = {'userInfo':
148+
{'EndTime': 1586258246255, 'UserId': 'kxdiid8vw8io9i8f', 'endTimeStr': '2020.04.07', 'newUser': True,
149+
'StartTime': 1585048647255, 'startTimeStr': '2020.03.24', 'IsNewUser': True},
150+
'systemTimeSpan': 1585048647891, 'success': True, 'orderCompletePopupType': 0, 'message': '操作成功',
151+
'redeemCodeType': 1, 'status': 0, 'statusCode': 200, 'timeUnit': 2}
152+
153+
res, l = register("15735656018")
154+
print(res, l)
155+
156+
# test("https://card.dushu.io/generalize/entityCard/card.html?id=e28ef30a1bbbe013108","15735656005")

0 commit comments

Comments
 (0)