Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 2ca5dd7

Browse files
committed
clean some api
1 parent ffb61ea commit 2ca5dd7

File tree

2 files changed

+193
-90
lines changed

2 files changed

+193
-90
lines changed

api.py

+192-89
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"""
66

77
__author__ = "yanyongyu"
8-
__all__ = ["cxmooc_tool", "poxiaobbs", "forestpolice", "bankroft",
9-
"jiuaidaikan", "wangke120"]
8+
__all__ = ["cxmooc_tool", "poxiaobbs", "forestpolice", "jiuaidaikan",
9+
"wangke120", "xuanxiu365"]
1010

1111
import sys
1212
import json
1313
import logging
1414
import asyncio
15-
from hashlib import md5
15+
# from hashlib import md5
1616

1717
import requests
1818
from lxml import etree
@@ -179,74 +179,74 @@ async def forestpolice(sess: requests.Session,
179179
raise StopIteration
180180

181181

182-
async def bankroft(sess: requests.Session,
183-
*args: list) -> list:
184-
"""
185-
该接口只有当题目完整时可用!
186-
并且有频率限制!
187-
"""
188-
# 输入参数处理
189-
if not isinstance(sess, requests.Session):
190-
args = list(args)
191-
args.insert(0, sess)
192-
args = tuple(args)
193-
sess = requests.Session()
194-
195-
# 接口
196-
string_enc = "-b?M#JvMg2y3$JMk"
197-
url = "http://123.207.19.72/api/query?"
198-
199-
# 接口参数
200-
index = yield
201-
payload = {}
202-
for i in range(len(args)):
203-
if index and i < index:
204-
continue
205-
md = md5()
206-
md.update((args[i]+string_enc).encode())
207-
208-
payload['title'] = args[i]
209-
payload['enc'] = md.hexdigest()
210-
211-
# post请求
212-
logging.info("Get bankroft api. Question %d" % i)
213-
try:
214-
res = sess.get(url, params=payload, verify=False, timeout=5)
215-
res.raise_for_status()
216-
except requests.exceptions.RequestException as e:
217-
logging.info("Request Exception appeared: %s" % e)
218-
answer = []
219-
answer.append({'topic': str(e),
220-
'correct': ''})
221-
index = yield answer
222-
continue
223-
224-
# 处理结果
225-
logging.info("Processing result")
226-
answer = []
227-
json_text = res.json()
228-
if json_text['code'] == 100:
229-
temp = {}
230-
temp['topic'] = args[i]
231-
temp['correct'] = json_text['data']
232-
answer.append(temp)
233-
elif json_text['code'] == 101:
234-
temp = {}
235-
temp['topic'] = "题目输入不完整!bankroft接口需要除题目类型外完整题目"
236-
temp['correct'] = ""
237-
answer.append(temp)
238-
else:
239-
temp = {}
240-
temp['topic'] = "bankroft接口查询次数已达上限!"
241-
temp['correct'] = ""
242-
answer.append(temp)
243-
244-
logging.info("Yield question %s: %s" % (i+1, answer))
245-
index = yield answer
246-
247-
await asyncio.sleep(0.5)
248-
249-
raise StopIteration
182+
#async def bankroft(sess: requests.Session,
183+
# *args: list) -> list:
184+
# """
185+
# 该接口只有当题目完整时可用!
186+
# 并且有频率限制!
187+
# """
188+
# # 输入参数处理
189+
# if not isinstance(sess, requests.Session):
190+
# args = list(args)
191+
# args.insert(0, sess)
192+
# args = tuple(args)
193+
# sess = requests.Session()
194+
#
195+
# # 接口
196+
# string_enc = "-b?M#JvMg2y3$JMk"
197+
# url = "http://123.207.19.72/api/query?"
198+
#
199+
# # 接口参数
200+
# index = yield
201+
# payload = {}
202+
# for i in range(len(args)):
203+
# if index and i < index:
204+
# continue
205+
# md = md5()
206+
# md.update((args[i]+string_enc).encode())
207+
#
208+
# payload['title'] = args[i]
209+
# payload['enc'] = md.hexdigest()
210+
#
211+
# # post请求
212+
# logging.info("Get bankroft api. Question %d" % i)
213+
# try:
214+
# res = sess.get(url, params=payload, verify=False, timeout=5)
215+
# res.raise_for_status()
216+
# except requests.exceptions.RequestException as e:
217+
# logging.info("Request Exception appeared: %s" % e)
218+
# answer = []
219+
# answer.append({'topic': str(e),
220+
# 'correct': ''})
221+
# index = yield answer
222+
# continue
223+
#
224+
# # 处理结果
225+
# logging.info("Processing result")
226+
# answer = []
227+
# json_text = res.json()
228+
# if json_text['code'] == 100:
229+
# temp = {}
230+
# temp['topic'] = args[i]
231+
# temp['correct'] = json_text['data']
232+
# answer.append(temp)
233+
# elif json_text['code'] == 101:
234+
# temp = {}
235+
# temp['topic'] = "题目输入不完整!bankroft接口需要除题目类型外完整题目"
236+
# temp['correct'] = ""
237+
# answer.append(temp)
238+
# else:
239+
# temp = {}
240+
# temp['topic'] = "bankroft接口查询次数已达上限!"
241+
# temp['correct'] = ""
242+
# answer.append(temp)
243+
#
244+
# logging.info("Yield question %s: %s" % (i+1, answer))
245+
# index = yield answer
246+
#
247+
# await asyncio.sleep(0.5)
248+
#
249+
# raise StopIteration
250250

251251

252252
async def jiuaidaikan(sess: requests.Session,
@@ -273,8 +273,6 @@ async def jiuaidaikan(sess: requests.Session,
273273
res.raise_for_status()
274274
selector = etree.HTML(res.text)
275275
viewstate = selector.xpath('//*[@id="__VIEWSTATE"]/@value')
276-
viewstategenerator = selector.xpath(
277-
'//*[@id="__VIEWSTATEGENERATOR"]/@value')
278276
eventvalidation = selector.xpath(
279277
'//*[@id="__EVENTVALIDATION"]/@value')
280278
except requests.exceptions.RequestException as e:
@@ -291,7 +289,6 @@ async def jiuaidaikan(sess: requests.Session,
291289

292290
data = {}
293291
data['__VIEWSTATE'] = viewstate
294-
data['__VIEWSTATEGENERATOR'] = viewstategenerator
295292
data['__EVENTVALIDATION'] = eventvalidation
296293
data['ctl00$ContentPlaceHolder1$gen'] = '查询'
297294
for i in range(len(args)):
@@ -379,8 +376,61 @@ async def wangke120(sess: requests.Session,
379376
raise StopIteration
380377

381378

382-
async def fm210(sess: requests.Session,
383-
*args: list) -> list:
379+
#async def fm210(sess: requests.Session,
380+
# *args: list) -> list:
381+
# # 输入参数处理
382+
# if not isinstance(sess, requests.Session):
383+
# args = list(args)
384+
# args.insert(0, sess)
385+
# args = tuple(args)
386+
# sess = requests.Session()
387+
#
388+
# # 接口
389+
# url = "http://api.fm210.cn/wangke/cx.php?"
390+
#
391+
# # 接口参数
392+
# index = yield
393+
# payload = {}
394+
# for i in range(len(args)):
395+
# if index and i < index:
396+
# continue
397+
# payload['w'] = args[i]
398+
#
399+
# # post请求
400+
# logging.info("Post to fm120. Question %d" % i)
401+
# try:
402+
# res = sess.get(url, params=payload, verify=False, timeout=5)
403+
# res.raise_for_status()
404+
# except requests.exceptions.RequestException as e:
405+
# logging.info("Request Exception appeared: %s" % e)
406+
# answer = []
407+
# answer.append({'topic': str(e),
408+
# 'correct': ''})
409+
# index = yield answer
410+
# continue
411+
#
412+
# # 处理结果
413+
# logging.info("Processing result")
414+
# answer = []
415+
# temp = {}
416+
# try:
417+
# temp['topic'] = res.text.split('\n')[1]
418+
# temp['correct'] = res.text.split('\n')[3]
419+
# if temp['correct'] != '':
420+
# answer.append(temp)
421+
# except IndexError:
422+
# pass
423+
#
424+
# logging.info("Yield question %s: %s" % (i+1, answer))
425+
# index = yield answer
426+
#
427+
# await asyncio.sleep(0.5)
428+
#
429+
# raise StopIteration
430+
431+
432+
async def xuanxiu365(sess: requests.Session,
433+
*args: list) -> list:
384434
# 输入参数处理
385435
if not isinstance(sess, requests.Session):
386436
args = list(args)
@@ -389,20 +439,23 @@ async def fm210(sess: requests.Session,
389439
sess = requests.Session()
390440

391441
# 接口
392-
url = "http://api.fm210.cn/wangke/cx.php?"
442+
url = "http://tiku.xuanxiu365.com/admin/admin/api.html"
443+
header = {}
444+
header['X-Requested-With'] = "XMLHttpRequest"
393445

394446
# 接口参数
395447
index = yield
396448
payload = {}
397449
for i in range(len(args)):
398450
if index and i < index:
399451
continue
400-
payload['w'] = args[i]
452+
payload['search'] = args[i]
401453

402454
# post请求
403-
logging.info("Post to fm120. Question %d" % i)
455+
logging.info("Post to xuanxiu365. Question %d" % i)
404456
try:
405-
res = sess.get(url, params=payload, verify=False, timeout=5)
457+
res = sess.get(url, params=payload, headers=header,
458+
verify=False, timeout=5)
406459
res.raise_for_status()
407460
except requests.exceptions.RequestException as e:
408461
logging.info("Request Exception appeared: %s" % e)
@@ -414,16 +467,13 @@ async def fm210(sess: requests.Session,
414467

415468
# 处理结果
416469
logging.info("Processing result")
470+
res = res.json()
417471
answer = []
418-
temp = {}
419-
try:
420-
temp['topic'] = res.text.split('\n')[1]
421-
temp['correct'] = res.text.split('\n')[3]
422-
if temp['correct'] != '':
423-
answer.append(temp)
424-
except IndexError:
425-
pass
426-
472+
if res['data']:
473+
temp = {}
474+
temp['topic'] = res['data']['title']
475+
temp['correct'] = res['data']['content']
476+
answer.append(temp)
427477
logging.info("Yield question %s: %s" % (i+1, answer))
428478
index = yield answer
429479

@@ -432,6 +482,59 @@ async def fm210(sess: requests.Session,
432482
raise StopIteration
433483

434484

485+
#async def www150s(sess: requests.Session,
486+
# *args: list) -> list:
487+
# # 输入参数处理
488+
# if not isinstance(sess, requests.Session):
489+
# args = list(args)
490+
# args.insert(0, sess)
491+
# args = tuple(args)
492+
# sess = requests.Session()
493+
#
494+
# # 接口
495+
# url = "http://www.150s.cn/SearchServlet"
496+
# header = {}
497+
# header['X-Requested-With'] = "XMLHttpRequest"
498+
#
499+
# # 接口参数
500+
# index = yield
501+
# payload = {}
502+
# for i in range(len(args)):
503+
# if index and i < index:
504+
# continue
505+
# payload['text'] = args[i]
506+
#
507+
# # post请求
508+
# logging.info("Post to www150s. Question %d" % i)
509+
# try:
510+
# res = sess.get(url, params=payload, headers=header,
511+
# verify=False, timeout=5)
512+
# res.raise_for_status()
513+
# except requests.exceptions.RequestException as e:
514+
# logging.info("Request Exception appeared: %s" % e)
515+
# answer = []
516+
# answer.append({'topic': str(e),
517+
# 'correct': ''})
518+
# index = yield answer
519+
# continue
520+
#
521+
# # 处理结果
522+
# logging.info("Processing result")
523+
# res = res.json()
524+
# answer = []
525+
# temp = {}
526+
# temp['topic'] = res['title']
527+
# temp['correct'] = res['answer']
528+
# if temp['topic'] != "查无此题,请您换一道题查询!":
529+
# answer.append(temp)
530+
# logging.info("Yield question %s: %s" % (i+1, answer))
531+
# index = yield answer
532+
#
533+
# await asyncio.sleep(0.5)
534+
#
535+
# raise StopIteration
536+
537+
435538
async def cmd():
436539
# 获取所有api
437540
api_list = {}

app.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
__author__ = "yanyongyu"
8-
__version__ = "1.5.3"
8+
__version__ = "1.5.4"
99

1010
import asyncio
1111
import logging

0 commit comments

Comments
 (0)