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

Sourcery Starbot ⭐ refactored yanyongyu/CXmoocSearchTool #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/CXmoocSearchTool master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -36 to +62
data = {}
for i in range(len(args)):
data['topic[%d]' % i] = args[i]

data = {'topic[%d]' % i: args[i] for i in range(len(args))}
# post请求
logging.info("Post to cxmooc_tool api.")
try:
res = sess.post(url, data=data, verify=False, timeout=5)
res.raise_for_status()
except requests.exceptions.RequestException as e:
logging.info("Request Exception appeared: %s" % e)
logging.info(f"Request Exception appeared: {e}")
answer = [{'topic': str(e), 'correct': ''}]
for each in args:
answer = []
answer.append({'topic': str(e),
'correct': ''})
yield answer
raise StopIteration

# 处理结果
logging.info("Processing result")
result = [[] for i in range(len(args))]
result = [[] for _ in range(len(args))]
for each in res.json():
for answ in each['result']:
temp = {}
temp['topic'] = answ['topic']
temp['correct'] = ''
temp = {'topic': answ['topic'], 'correct': ''}
for option in answ['correct']:
temp['correct'] = temp['correct'] + str(option['option'])
temp['correct'] += str(option['option'])
result[each['index']].append(temp)

for i in range(len(result)):
if index and i < index:
continue
logging.info("Yield question %s: %s" % (i+1, result[i]))
logging.info(f"Yield question {i + 1}: {result[i]}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function cxmooc_tool refactored with the following changes:

Comment on lines -102 to +107
logging.info("Request Exception appeared: %s" % e)
answer = []
answer.append({'topic': str(e),
'correct': ''})
logging.info(f"Request Exception appeared: {e}")
answer = [{'topic': str(e), 'correct': ''}]
index = yield answer
continue

# 处理结果
logging.info("Processing result")
answer = []
temp = {}
temp['topic'] = args[i]
temp['correct'] = res.json()['data']
temp = {'topic': args[i], 'correct': res.json()['data']}
if temp['correct'] != '未找到答案':
answer.append(temp)

logging.info("Yield question %s: %s" % (i+1, answer))
logging.info(f"Yield question {i + 1}: {answer}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function forestpolice refactored with the following changes:

Comment on lines -153 to +155
logging.info("Request Exception appeared: %s" % e)
logging.info(f"Request Exception appeared: {e}")
index = yield
for i in range(len(args)):
if index and i < index:
continue
answer = []
answer.append({'topic': str(e),
'correct': ''})
yield answer
yield [{'topic': str(e), 'correct': ''}]
raise StopIteration

data = {}
data['__VIEWSTATE'] = viewstate
data['__EVENTVALIDATION'] = eventvalidation
data['ctl00$ContentPlaceHolder1$gen'] = '查询'
data = {
'__VIEWSTATE': viewstate,
'__EVENTVALIDATION': eventvalidation,
'ctl00$ContentPlaceHolder1$gen': '查询',
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function jiuaidaikan refactored with the following changes:

Comment on lines -215 to +203
header = {}
header['X-Requested-With'] = "XMLHttpRequest"

header = {'X-Requested-With': "XMLHttpRequest"}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function xuanxiu365 refactored with the following changes:

Comment on lines -287 to +270
logging.info("Request Exception appeared: %s" % e)
answer = []
answer.append({'topic': str(e),
'correct': ''})
logging.info(f"Request Exception appeared: {e}")
answer = [{'topic': str(e), 'correct': ''}]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function www150s refactored with the following changes:

elif len(self.text) > 3:
else:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.show._configure_frame refactored with the following changes:

Comment on lines -442 to +446
raw_question = [each[each.index("】") + 1:]
for each in question if each.find("】") != -1]
return raw_question
return [
each[each.index("】") + 1 :]
for each in question
if each.find("】") != -1
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.scan_cx refactored with the following changes:

Comment on lines -457 to +464
raw_question = [question[i + 1]
for i in range(len(question) - 1)
if question[i].find("】") != -1
if question[i].find(r")") != -1]
return raw_question
return [
question[i + 1]
for i in range(len(question) - 1)
if question[i].find("】") != -1
if question[i].find(r")") != -1
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.scan_zhs refactored with the following changes:

Comment on lines -535 to +545
logging.info("Active generator %s" % api)
logging.info(f"Active generator {api}")
await generator_list[api].asend(None)

# 查询答案
for i in range(len(text)):
label = frame_list[i].children['!text']
label.configure(state="normal")
for generator in generator_list.keys():
for generator in generator_list:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.search refactored with the following changes:

Comment on lines -664 to +667
logging.info("Request Exception appeared: %s" % e)
logging.info(f"Request Exception appeared: {e}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function App.scan_release refactored with the following changes:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant