Skip to content

Sourcery Starbot ⭐ refactored haruo75/WZML#1

Open
SourceryAI wants to merge 1 commit intoharuo75:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored haruo75/WZML#1
SourceryAI wants to merge 1 commit intoharuo75:masterfrom
SourceryAI:master

Conversation

@SourceryAI
Copy link
Copy Markdown

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/WZML master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Copy Markdown
Author

@SourceryAI SourceryAI left a comment

Choose a reason for hiding this comment

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

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread add_to_team_drive.py
batch = drive.new_batch_http_request()

aa = glob.glob('%s/*.json' % acc_dir)
aa = glob.glob(f'{acc_dir}/*.json')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 60-60 refactored with the following changes:

Comment thread gen_sa_accounts.py
Comment on lines -29 to +39
batch.add(service.projects().serviceAccounts().create(name='projects/' + project, body={'accountId': aid,
'serviceAccount': {
'displayName': aid}}))
batch.add(
service.projects()
.serviceAccounts()
.create(
name=f'projects/{project}',
body={
'accountId': aid,
'serviceAccount': {'displayName': aid},
},
)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _create_accounts refactored with the following changes:

Comment thread gen_sa_accounts.py
Comment on lines -37 to +45
print('Creating accounts in %s' % project)
print(f'Creating accounts in {project}')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _create_remaining_accounts refactored with the following changes:

Comment thread gen_sa_accounts.py
Comment on lines -61 to +69
print(str(exception))
print(exception)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _def_batch_resp refactored with the following changes:

Comment thread gen_sa_accounts.py
Comment on lines -68 to +76
print(str(exception))
print(exception)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _pc_resp refactored with the following changes:

Comment on lines -384 to +383
if bool(url1) == True:
if bool(url1):
return bool(url1)
elif bool(url) == True:
elif bool(url):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function is_unified_link refactored with the following changes:

Comment on lines -394 to +392
else:
url = re_match(r'https?://(hubdrive|katdrive|kolop|drivefire|drivebuzz)\.\S+', url)
return bool(url)
url = re_match(r'https?://(hubdrive|katdrive|kolop|drivefire|drivebuzz)\.\S+', url)
return bool(url)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function is_udrive_link refactored with the following changes:

Comment on lines -482 to +480
LOGGER.info("Remname : "+file_)
if PREFIX:
if not file_.startswith(PREFIX):
file_ = f"{PREFIX}{file_}"
LOGGER.info(f"Remname : {file_}")
if PREFIX and not file_.startswith(PREFIX):
file_ = f"{PREFIX}{file_}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function change_filename refactored with the following changes:

Comment on lines -537 to +529
if user_id in user_data:
return user_data[user_id].get('is_sudo')
return False
return user_data[user_id].get('is_sudo') if user_id in user_data else False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function is_sudo refactored with the following changes:

Comment on lines -542 to +543
if user_id in user_data and user_data[user_id].get('is_paid'):
ex_date = user_data[user_id].get('expiry_date')
if ex_date:
odate = datetime.strptime(ex_date, '%d-%m-%Y')
ndate = datetime.today()
if odate.year <= ndate.year:
if odate.month <= ndate.month:
if odate.day < ndate.day:
return False
return True
else: return False
if user_id not in user_data or not user_data[user_id].get('is_paid'):
return False
if ex_date := user_data[user_id].get('expiry_date'):
odate = datetime.strptime(ex_date, '%d-%m-%Y')
ndate = datetime.now()
if (
odate.year <= ndate.year
and odate.month <= ndate.month
and odate.day < ndate.day
):
return False
return True
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function is_paid refactored with the following changes:

DLs: {num_active} | ULs: {num_upload} | SEEDING: {num_seeding}
ZIP: {num_zip} | UNZIP: {num_unzip} | SPLIT: {num_split}
"""
return stats
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function bot_sys_stats refactored with the following changes:

Comment on lines -601 to +591
CallbackQueryHandler(pop_up_stats, pattern="^" + str(THREE) + "$")
CallbackQueryHandler(pop_up_stats, pattern=f"^{str(THREE)}$")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 601-601 refactored with the following changes:

dbval = value
else:
dbval = False
dbval = value if value is not None else False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function DbManger.update_userval refactored with the following changes:

def get_base_name(orig_path: str):
ext = [ext for ext in ARCH_EXT if orig_path.lower().endswith(ext)]
if ext:
if ext := [ext for ext in ARCH_EXT if orig_path.lower().endswith(ext)]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_base_name refactored with the following changes:

Comment on lines -156 to +197
if not noMap:
listener.suproc = Popen(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(start_time),
"-i", path, "-fs", str(split_size), "-map", "0", "-map_chapters", "-1",
"-c", "copy", out_path])
else:
listener.suproc = Popen(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(start_time),
"-i", path, "-fs", str(split_size), "-map_chapters", "-1", "-c", "copy",
out_path])
listener.suproc = (
Popen(
[
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-ss",
str(start_time),
"-i",
path,
"-fs",
str(split_size),
"-map_chapters",
"-1",
"-c",
"copy",
out_path,
]
)
if noMap
else Popen(
[
"ffmpeg",
"-hide_banner",
"-loglevel",
"error",
"-ss",
str(start_time),
"-i",
path,
"-fs",
str(split_size),
"-map",
"0",
"-map_chapters",
"-1",
"-c",
"copy",
out_path,
]
)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function split_file refactored with the following changes:

Comment on lines -638 to -655
flink = info_parsed["gdrive_link"]
return flink

return info_parsed["gdrive_link"]
elif urlparse(url).netloc == "driveapp.in":
res = client.get(info_parsed["gdrive_link"])
drive_link = etree.HTML(res.content).xpath("//a[contains(@class,'btn')]/@href")[
0
]
flink = drive_link
return flink

return etree.HTML(res.content).xpath(
"//a[contains(@class,'btn')]/@href"
)[0]
else:
res = client.get(info_parsed["gdrive_link"])
drive_link = etree.HTML(res.content).xpath(
return etree.HTML(res.content).xpath(
"//a[contains(@class,'btn btn-primary')]/@href"
)[0]
flink = drive_link
return flink
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function unified refactored with the following changes:

Comment on lines -659 to +656
info_parsed = {}
if 'drivebuzz' in url:
info_chunks = re_findall('<td\salign="right">(.*?)<\/td>', res.text)
else:
info_chunks = re_findall(">(.*?)<\/td>", res.text)
for i in range(0, len(info_chunks), 2):
info_parsed[info_chunks[i]] = info_chunks[i + 1]
return info_parsed
return {
info_chunks[i]: info_chunks[i + 1]
for i in range(0, len(info_chunks), 2)
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function parse_info refactored with the following changes:

Comment on lines -670 to +660
if 'katdrive' or 'hubdrive' in url:
client = requests.Session()
else:
client = cloudscraper.create_scraper(delay=10, browser='chrome')

client = requests.Session()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function udrive refactored with the following changes:

Comment on lines -733 to +731
def sharer_pw_dl(url: str)-> str:
def sharer_pw_dl(url: str) -> str:

client = cloudscraper.create_scraper(delay=10, browser='chrome')
client.cookies["XSRF-TOKEN"] = config_dict['XSRF_TOKEN']
client.cookies["laravel_session"] = config_dict['laravel_session']

res = client.get(url)
token = re_findall("_token\s=\s'(.*?)'", res.text, DOTALL)[0]
data = { '_token': token, 'nl' :1}
headers={ 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'x-requested-with': 'XMLHttpRequest'}

try:
response = client.post(url+'/dl', headers=headers, data=data).json()
response = client.post(f'{url}/dl', headers=headers, data=data).json()
drive_link = response
return drive_link['url']

except:
if drive_link["message"] == "OK":
raise DirectDownloadLinkException("Something went wrong. Could not generate GDrive URL for your Sharer Link")
else:
finalMsg = BeautifulSoup(drive_link["message"], "lxml").text
raise DirectDownloadLinkException(finalMsg)
finalMsg = BeautifulSoup(drive_link["message"], "lxml").text
raise DirectDownloadLinkException(finalMsg)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function sharer_pw_dl refactored with the following changes:

Comment on lines -797 to +783

resp = scrapper.post(f'https://{urlparse(url).netloc}/post', headers=headers, data=data, cookies=cookies)
toJson = resp.json()

if toJson['message'] in successMsgs:
return toJson['redirect']
if directLogin==True:
if toJson['message'] in successMsgs:
driveUrl = toJson['redirect']
return driveUrl
else:
shareDrive(url,directLogin=False)
shareDrive(url,directLogin=False)
else:
if toJson['message'] in successMsgs:
driveUrl = toJson['redirect']
return driveUrl
else:
raise DirectDownloadLinkException("ERROR! File Not Found or User rate exceeded !!")
raise DirectDownloadLinkException("ERROR! File Not Found or User rate exceeded !!")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function shareDrive refactored with the following changes:

Comment on lines -848 to +819
flink = prun(playwright, link)
return flink
return prun(playwright, link)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function filepress refactored with the following changes:

msg += f'\n#Buy Paid Service'
__onDownloadError(msg, client, tor)
return
limit = None
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function __check_limits refactored with the following changes:

except (KeyError, IndexError):
msg = "Google Drive ID could not be found in the provided link"
return msg
return "Google Drive ID could not be found in the provided link"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.deletefile refactored with the following changes:

Comment on lines -292 to +293
LOGGER.info("Created G-Drive Folder:\nName: {}\nID: {} ".format(file.get("name"), file_id))
LOGGER.info(
f'Created G-Drive Folder:\nName: {file.get("name")}\nID: {file_id} '
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.__create_directory refactored with the following changes:

Comment on lines -319 to +320
download_url = self.__G_DRIVE_BASE_DOWNLOAD_URL.format(drive_file.get('id'))
return download_url
return self.__G_DRIVE_BASE_DOWNLOAD_URL.format(drive_file.get('id'))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function GoogleDriveHelper.__upload_file refactored with the following changes:

Comment thread bot/modules/hash.py
size /= power
n += 1
return str(round(size, 2)) + " " + Dic_powerN[n] + "iB"
return f"{str(round(size, 2))} {Dic_powerN[n]}iB"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function HumanBytes refactored with the following changes:

Comment thread bot/modules/hash.py
Comment on lines -21 to +31
seconds, milliseconds = divmod(int(milliseconds), 1000)
seconds, milliseconds = divmod(milliseconds, 1000)
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
tmp = ((str(days) + "d, ") if days else "") + \
((str(hours) + "h, ") if hours else "") + \
((str(minutes) + "m, ") if minutes else "") + \
((str(seconds) + "s, ") if seconds else "") + \
((str(milliseconds) + "ms, ") if milliseconds else "")
tmp = (
(f"{str(days)}d, " if days else "")
+ (f"{str(hours)}h, " if hours else "")
+ (f"{str(minutes)}m, " if minutes else "")
+ (f"{str(seconds)}s, " if seconds else "")
+ (f"{str(milliseconds)}ms, " if milliseconds else "")
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function TimeFormatter refactored with the following changes:

Comment thread bot/modules/hash.py
Comment on lines -39 to +44
file = None
media_array = [mediamessage.document, mediamessage.video, mediamessage.audio, mediamessage.document, \
mediamessage.video, mediamessage.photo, mediamessage.audio, mediamessage.voice, \
mediamessage.animation, mediamessage.video_note, mediamessage.sticker]
for i in media_array:
if i is not None:
file = i
break
file = next((i for i in media_array if i is not None), None)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function hash refactored with the following changes:

This removes the following comments ( why? ):

# hash text

Comment thread bot/modules/imdb.py
Comment on lines -25 to -28
movie = imdb.get_movie(movieid)
if not movie:
if movie := imdb.get_movie(movieid):
buttons.sbutton(f"🎬 {movie.get('title')} ({movie.get('year')})", f"imdb {user_id} movie {movieid}")
else:
return editMessage("<i>No Results Found</i>", k)
buttons.sbutton(f"🎬 {movie.get('title')} ({movie.get('year')})", f"imdb {user_id} movie {movieid}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function imdb_search refactored with the following changes:

Comment thread bot/modules/imdb.py
plot = plot[0]
else:
plot = movie.get('plot outline')
plot = plot[0] if plot and len(plot) > 0 else movie.get('plot outline')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_poster 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.

1 participant