-
Notifications
You must be signed in to change notification settings - Fork 23
Sourcery Starbot ⭐ refactored yanyongyu/CXmoocSearchTool #5
base: master
Are you sure you want to change the base?
Conversation
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]}") |
There was a problem hiding this comment.
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:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Hoist statements out of for/while loops (
hoist-statement-from-loop
) - Merge append into list declaration (
merge-list-append
) - Replace unused for index with underscore (
for-index-underscore
) - Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace assignment with augmented assignment (
aug-assign
)
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}") |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Merge append into list declaration (
merge-list-append
) - Merge dictionary assignment with declaration (
merge-dict-assign
)
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': '查询', | ||
} | ||
|
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Merge append into list declaration (
merge-list-append
) - Inline variable that is immediately yielded (
inline-immediately-yielded-variable
) - Merge dictionary assignment with declaration (
merge-dict-assign
)
header = {} | ||
header['X-Requested-With'] = "XMLHttpRequest" | ||
|
||
header = {'X-Requested-With': "XMLHttpRequest"} |
There was a problem hiding this comment.
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:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Merge append into list declaration (
merge-list-append
)
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': ''}] |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Merge append into list declaration (
merge-list-append
)
elif len(self.text) > 3: | ||
else: |
There was a problem hiding this comment.
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:
- Remove redundant conditional (
remove-redundant-if
)
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 | ||
] |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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 | ||
] |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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: |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Remove unnecessary call to keys() (
remove-dict-keys
)
logging.info("Request Exception appeared: %s" % e) | ||
logging.info(f"Request Exception appeared: {e}") |
There was a problem hiding this comment.
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:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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: