Skip to content

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 21, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

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

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from DAcidSolution March 21, 2022 12:39
Comment on lines -43 to +44
if total == 0:
per = 1
else:
per = 1.0 * chunk * chunk_num / total
if per > 1:
per = 1
per = 1 if total == 0 else 1.0 * chunk * chunk_num / total
per = min(per, 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 py_info.progressbar refactored with the following changes:

Comment on lines -166 to +162
faillist = []

for pyinfo in pylist:
if not pyinfo.download(rootdir=dir):
faillist.append(pyinfo)

return faillist
return [pyinfo for pyinfo in pylist if not pyinfo.download(rootdir=dir)]
Copy link
Author

Choose a reason for hiding this comment

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

Function downloadpy refactored with the following changes:

Comment on lines +191 to -211
# 遍历获得仓库所有py文件信息
github_url = 'https://github.com/JohnWes7/Daily_Nutrition'
while True:
# 遍历获得仓库所有py文件信息
github_url = 'https://github.com/JohnWes7/Daily_Nutrition'
filelist = get_all_githubrepo_py(github_url)

if type(filelist) == list:
break
# 如果获取不到 返回false 重新获取
else:
input('获取仓库信息失败 回车重新尝试连接下载github\n')
continue
Copy link
Author

Choose a reason for hiding this comment

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

Function __main refactored with the following changes:

This removes the following comments ( why? ):

# 如果获取不到 返回false 重新获取
# 成功跳出
# 有失败项目重新尝试
# 打开本地需要替换或者新建的位置

def get_cookie_path():
'''cookie文件路径'''
return os.path.dirname(__file__) + '/data/cookies.json'
return f'{os.path.dirname(__file__)}/data/cookies.json'
Copy link
Author

Choose a reason for hiding this comment

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

Function path.get_cookie_path refactored with the following changes:

def get_download_record_path():
'''下载过的图的记录数据路径'''
return os.path.dirname(__file__) + '/data/downloadrecord.json'
return f'{os.path.dirname(__file__)}/data/downloadrecord.json'
Copy link
Author

Choose a reason for hiding this comment

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

Function path.get_download_record_path refactored with the following changes:

Comment on lines -165 to +159
if newcookies == None:
if newcookies is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function recordcookie.update_cookies refactored with the following changes:

Comment on lines -190 to +184
if oldcookie == None:
if oldcookie is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function recordcookie.update_local_cookies refactored with the following changes:

Comment on lines -210 to +204
if record == None:
if record is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function recordcookie.append_record_pid_local refactored with the following changes:

Comment on lines -226 to +220
if record == None:
if record is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function recordcookie.contrast_with_localrecord refactored with the following changes:

Comment on lines -266 to +259
conf_path = os.path.dirname(__file__) + '/Config.ini'
conf_path = f'{os.path.dirname(__file__)}/Config.ini'
Copy link
Author

Choose a reason for hiding this comment

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

Lines 266-266 refactored with the following changes:

Comment on lines -291 to -293
is_cover = conf.getboolean(
return conf.getboolean(
ads, 'is_cover', fallback=default_setting.get('is_cover'))
return is_cover
Copy link
Author

Choose a reason for hiding this comment

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

Function config.get_is_cover refactored with the following changes:

Comment on lines -308 to -310
forcelogin = conf.getboolean(
return conf.getboolean(
ads, 'forcelogin', fallback=default_setting.get('forcelogin'))
return forcelogin
Copy link
Author

Choose a reason for hiding this comment

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

Function config.get_forcelogin refactored with the following changes:

Comment on lines -318 to +309
if path[path.__len__() - 1].__eq__('/'):
return path
return path + '/'
return path if path[path.__len__() - 1].__eq__('/') else f'{path}/'
Copy link
Author

Choose a reason for hiding this comment

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

Function config.get_ads_download_path refactored with the following changes:

Comment on lines -326 to -328
is_proxies = conf.getboolean(
return conf.getboolean(
link, 'is_proxies', fallback=default_setting.get('is_proxies'))
return is_proxies
Copy link
Author

Choose a reason for hiding this comment

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

Function config.get_is_proxies refactored with the following changes:

Comment on lines -336 to -340
proxies_dict = {
return {
'http': http,
'https': https
}
return proxies_dict
Copy link
Author

Choose a reason for hiding this comment

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

Function config.get_proxies_dict refactored with the following changes:

Comment on lines -220 to +212
result = filename, headers
bs = 1024*8
size = -1
read = 0
blocknum = 0
if "content-length" in headers:
size = int(headers["Content-Length"])

result = filename, headers
size = int(headers["Content-Length"]) if "content-length" in headers else -1
bs = 1024*8
Copy link
Author

Choose a reason for hiding this comment

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

Function custom_urlretrieve refactored with the following changes:

Comment on lines -254 to +239
if head == None:
if head is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function dicovery_json refactored with the following changes:

Comment on lines -286 to +274
if opener == None:
if _opener == None:
if opener is None:
if _opener is None:
opener = _opener = request.build_opener()
else:
opener = _opener
if head == None:
if head is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function download_idlist refactored with the following changes:

Comment on lines -318 to +306
if opener == None:
if _opener == None:
if opener is None:
if _opener is None:
opener = _opener = request.build_opener()
else:
opener = _opener
if headers == None:
if headers is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function download_id refactored with the following changes:

Comment on lines -451 to +435
id_list = []

re_list = jsondata.get('body').get('recommendedIllusts')
for item in re_list:
id_list.append(item.get('illustId'))

return id_list
return [item.get('illustId') for item in re_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 parsing_tutu_data2 refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 21, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.70%.

Quality metrics Before After Change
Complexity 13.37 🙂 13.70 🙂 0.33 👎
Method Length 64.26 🙂 62.84 🙂 -1.42 👍
Working memory 9.08 🙂 9.16 🙂 0.08 👎
Quality 58.72% 🙂 58.02% 🙂 -0.70% 👎
Other metrics Before After Change
Lines 1489 1420 -69
Changed files Quality Before Quality After Quality Change
check_update.py 53.45% 🙂 52.99% 🙂 -0.46% 👎
config.py 83.03% ⭐ 83.72% ⭐ 0.69% 👍
discovery.py 50.85% 🙂 49.63% 😞 -1.22% 👎
downloads.py 46.60% 😞 46.05% 😞 -0.55% 👎
src/custom_driver.py 78.43% ⭐ 81.77% ⭐ 3.34% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
downloads.py download_id 47 ⛔ 547 ⛔ 20 ⛔ 8.18% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
check_update.py __main 25 😞 304 ⛔ 10 😞 31.91% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
discovery.py analysis_log 21 😞 214 ⛔ 12 😞 35.17% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
downloads.py illustration.download 16 🙂 195 😞 13 😞 38.72% 😞 Try splitting into smaller methods. Extract out complex expressions
downloads.py custom_urlretrieve 15 🙂 184 😞 11 😞 43.73% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Comment on lines -543 to +521
if dicovery_json == None:
if dicovery_json is None:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 543-543 refactored with the following changes:

'desired_capabilities' : desired_capabilities\n
'options' : options\n
'''
od_dict = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function options_desired_capabilities_chrome refactored with the following changes:

Comment on lines -56 to +55
od_dict = {}
caps = None
opt = webdriver.FirefoxOptions()

if is_proxy:
pass

if is_getlog:
pass

od_dict['desired_capabilities'] = caps
od_dict['options'] = opt

return od_dict
return {'desired_capabilities': caps, 'options': opt}
Copy link
Author

Choose a reason for hiding this comment

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

Function options_desired_capabilities_firefox refactored with the following changes:

'desired_capabilities' : desired_capabilities\n
'options' : options\n
'''
od_dict = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function options_desired_capabilities_edge refactored with the following changes:

Comment on lines -131 to -133
driver = webdriver.Chrome(executable_path=driver_path,
return webdriver.Chrome(executable_path=driver_path,
options=options, desired_capabilities=desired_capabilities)
return driver
Copy link
Author

Choose a reason for hiding this comment

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

Function custom_chrome refactored with the following changes:

Comment on lines -142 to +128
driver = webdriver.Firefox(executable_path=driver_path,
options=options, desired_capabilities=desired_capabilities)
return driver
return webdriver.Firefox(
executable_path=driver_path,
options=options,
desired_capabilities=desired_capabilities,
)

Copy link
Author

Choose a reason for hiding this comment

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

Function custom_firefox refactored with the following changes:

Comment on lines -153 to +142
driver = webdriver.Edge(executable_path=driver_path, options=options, capabilities=desired_capabilities)
return driver
return webdriver.Edge(
executable_path=driver_path,
options=options,
capabilities=desired_capabilities,
)

Copy link
Author

Choose a reason for hiding this comment

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

Function custom_edge refactored with the following changes:

Comment on lines -166 to +154
driver = name_driver_func.get(name)(options, desired_capabilities)
return driver
return name_driver_func.get(name)(options, desired_capabilities)
Copy link
Author

Choose a reason for hiding this comment

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

Function get_custom_driver refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants