Conversation
| 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) |
There was a problem hiding this comment.
Function py_info.progressbar refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Replace comparison with min/max call (
min-max-identity)
| 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)] |
There was a problem hiding this comment.
Function downloadpy refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Convert for loop into list comprehension (
list-comprehension)
| # 遍历获得仓库所有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 |
There was a problem hiding this comment.
Function __main refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop) - Remove redundant continue statement (
remove-redundant-continue) - Remove unnecessary else after guard condition (
remove-unnecessary-else) - Use
withwhen opening file to ensure closure (ensure-file-closed) - Simplify sequence comparison (
simplify-len-comparison)
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' |
There was a problem hiding this comment.
Function path.get_cookie_path refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| def get_download_record_path(): | ||
| '''下载过的图的记录数据路径''' | ||
| return os.path.dirname(__file__) + '/data/downloadrecord.json' | ||
| return f'{os.path.dirname(__file__)}/data/downloadrecord.json' |
There was a problem hiding this comment.
Function path.get_download_record_path refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if newcookies == None: | ||
| if newcookies is None: |
There was a problem hiding this comment.
Function recordcookie.update_cookies refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| if oldcookie == None: | ||
| if oldcookie is None: |
There was a problem hiding this comment.
Function recordcookie.update_local_cookies refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| if record == None: | ||
| if record is None: |
There was a problem hiding this comment.
Function recordcookie.append_record_pid_local refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| if record == None: | ||
| if record is None: |
There was a problem hiding this comment.
Function recordcookie.contrast_with_localrecord refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| conf_path = os.path.dirname(__file__) + '/Config.ini' | ||
| conf_path = f'{os.path.dirname(__file__)}/Config.ini' |
There was a problem hiding this comment.
Lines 266-266 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| is_cover = conf.getboolean( | ||
| return conf.getboolean( | ||
| ads, 'is_cover', fallback=default_setting.get('is_cover')) | ||
| return is_cover |
There was a problem hiding this comment.
Function config.get_is_cover refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| forcelogin = conf.getboolean( | ||
| return conf.getboolean( | ||
| ads, 'forcelogin', fallback=default_setting.get('forcelogin')) | ||
| return forcelogin |
There was a problem hiding this comment.
Function config.get_forcelogin refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if path[path.__len__() - 1].__eq__('/'): | ||
| return path | ||
| return path + '/' | ||
| return path if path[path.__len__() - 1].__eq__('/') else f'{path}/' |
There was a problem hiding this comment.
Function config.get_ads_download_path refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| is_proxies = conf.getboolean( | ||
| return conf.getboolean( | ||
| link, 'is_proxies', fallback=default_setting.get('is_proxies')) | ||
| return is_proxies |
There was a problem hiding this comment.
Function config.get_is_proxies refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| proxies_dict = { | ||
| return { | ||
| 'http': http, | ||
| 'https': https | ||
| } | ||
| return proxies_dict |
There was a problem hiding this comment.
Function config.get_proxies_dict refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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 |
There was a problem hiding this comment.
Function custom_urlretrieve refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Move setting of default value for variable into
elsebranch (introduce-default-else) - Move assignment closer to its usage within a block (
move-assign-in-block)
| if head == None: | ||
| if head is None: |
There was a problem hiding this comment.
Function dicovery_json refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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: |
There was a problem hiding this comment.
Function download_idlist refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| 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: |
There was a problem hiding this comment.
Function download_id refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| 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] |
There was a problem hiding this comment.
Function parsing_tutu_data2 refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Move assignment closer to its usage within a block (
move-assign-in-block) - Convert for loop into list comprehension (
list-comprehension)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.70%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
| if dicovery_json == None: | ||
| if dicovery_json is None: |
There was a problem hiding this comment.
Lines 543-543 refactored with the following changes:
- Use x is None rather than x == None (
none-compare)
| 'desired_capabilities' : desired_capabilities\n | ||
| 'options' : options\n | ||
| ''' | ||
| od_dict = {} |
There was a problem hiding this comment.
Function options_desired_capabilities_chrome refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Move assignment closer to its usage within a block (
move-assign-in-block)
| 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} |
There was a problem hiding this comment.
Function options_desired_capabilities_firefox refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Move assignment closer to its usage within a block (
move-assign-in-block) - Remove redundant conditional (
remove-redundant-if)
| 'desired_capabilities' : desired_capabilities\n | ||
| 'options' : options\n | ||
| ''' | ||
| od_dict = {} |
There was a problem hiding this comment.
Function options_desired_capabilities_edge refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Move assignment closer to its usage within a block (
move-assign-in-block)
| driver = webdriver.Chrome(executable_path=driver_path, | ||
| return webdriver.Chrome(executable_path=driver_path, | ||
| options=options, desired_capabilities=desired_capabilities) | ||
| return driver |
There was a problem hiding this comment.
Function custom_chrome refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function custom_firefox refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function custom_edge refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| driver = name_driver_func.get(name)(options, desired_capabilities) | ||
| return driver | ||
| return name_driver_func.get(name)(options, desired_capabilities) |
There was a problem hiding this comment.
Function get_custom_driver refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!