-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
self.name = name | ||
if password != None: | ||
self.password = generate_password_hash(password) | ||
else: | ||
self.password = None | ||
self.profilePicture = profilePicture | ||
self.accountType = accountType | ||
self.name = name | ||
self.password = generate_password_hash(password) if password != None else None | ||
self.profilePicture = profilePicture | ||
self.accountType = accountType |
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 Users.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if self.password == None: | ||
return True | ||
return check_password_hash(self.password, pwd) | ||
if self.password is None: | ||
return True | ||
return check_password_hash(self.password, pwd) |
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 Users.verify_password
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
game["first_release_date"] = "Unknown" | ||
if "cover" not in game: | ||
game["cover"] = {"url": "//images.igdb.com/igdb/image/upload/t_cover_big/nocover.png"} | ||
|
||
game["summary"] = translate(game["summary"]) | ||
game["genres"][0]["name"] = translate(game["genres"][0]["name"]) | ||
|
||
|
||
genres = [] | ||
for genre in game["genres"]: | ||
genres.append(genre["name"]) | ||
genres = ", ".join(genres) | ||
|
||
gameData = { | ||
"title": game["name"], "cover": game["cover"]["url"].replace("//", "https://"), "description": game["summary"], "note": game["total_rating"], "date": game["first_release_date"], "genre": genres, "id": game["id"] | ||
} | ||
return gameData | ||
except: | ||
continue | ||
return None | ||
customHeaders = { | ||
'User-Agent': 'Mozilla/5.0 (X11; UwUntu; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0', | ||
'Accept': '*/*', | ||
'X-Requested-With': 'XMLHttpRequest', | ||
'Origin': url, | ||
'DNT': '1', | ||
'Sec-Fetch-Dest': 'empty', | ||
'Sec-Fetch-Mode': 'cors', | ||
'Sec-Fetch-Site': 'same-origin', | ||
'Referer': url, | ||
'Connection': 'keep-alive', | ||
'Pragma': 'no-cache', | ||
'Cache-Control': 'no-cache', | ||
} | ||
response = requests.request("GET", url, headers=customHeaders) | ||
|
||
if response.status_code == 403: | ||
return None | ||
elif response.json() != {}: | ||
grantType = "client_credentials" | ||
getAccessToken = f"https://id.twitch.tv/oauth2/token?client_id={clientID}&client_secret={clientSecret}&grant_type={grantType}" | ||
token = requests.request("POST", getAccessToken) | ||
token = token.json() | ||
token = token["access_token"] | ||
|
||
headers = { | ||
"Accept": "application/json", "Authorization": f"Bearer {token}", "Client-ID": clientID | ||
} | ||
|
||
games = response.json()["game_suggest"] | ||
for i in games: | ||
game=i | ||
gameId = game["id"] | ||
url = "https://api.igdb.com/v4/games" | ||
body = f"fields name, cover.*, summary, total_rating, first_release_date, genres.*, platforms.*; where id = {gameId};" | ||
response = requests.request("POST", url, headers=headers, data=body) | ||
if len(response.json())==0: | ||
break | ||
game = response.json()[0] | ||
if "platforms" in game: | ||
gamePlatforms = game["platforms"] | ||
try: | ||
platforms = [i["abbreviation"] for i in gamePlatforms] | ||
|
||
realConsoleName = { | ||
"GB": "Game Boy", "GBA": "Game Boy Advance", "GBC": "Game Boy Color", "N64": "Nintendo 64", "NES": "Nintendo Entertainment System", "NDS": "Nintendo DS", "SNES": "Super Nintendo Entertainment System", "Sega Master System": "Sega Master System", "Sega Mega Drive": "Sega Mega Drive", "PS1": "PS1" | ||
} | ||
|
||
if realConsoleName[console] not in platforms and console not in platforms: | ||
continue | ||
if "total_rating" not in game: | ||
game["total_rating"] = "Unknown" | ||
if "genres" not in game: | ||
game["genres"] = [{"name": "Unknown"}] | ||
if "summary" not in game: | ||
game["summary"] = "Unknown" | ||
if "first_release_date" not in game: | ||
game["first_release_date"] = "Unknown" | ||
if "cover" not in game: | ||
game["cover"] = {"url": "//images.igdb.com/igdb/image/upload/t_cover_big/nocover.png"} | ||
|
||
game["summary"] = translate(game["summary"]) | ||
game["genres"][0]["name"] = translate(game["genres"][0]["name"]) | ||
|
||
|
||
genres = [genre["name"] for genre in game["genres"]] | ||
genres = ", ".join(genres) | ||
|
||
return { | ||
"title": game["name"], | ||
"cover": game["cover"]["url"].replace("//", "https://"), | ||
"description": game["summary"], | ||
"note": game["total_rating"], | ||
"date": game["first_release_date"], | ||
"genre": genres, | ||
"id": game["id"], | ||
} | ||
except: | ||
continue | ||
return None |
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 IGDBRequest
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
language = config["ChocolateSettings"]["language"] | ||
if language == "EN": | ||
return string | ||
translated = GoogleTranslator(source='english', target=language.lower()).translate(string) | ||
return translated | ||
language = config["ChocolateSettings"]["language"] | ||
if language == "EN": | ||
return string | ||
return GoogleTranslator(source='english', | ||
target=language.lower()).translate(string) |
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 translate
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
CHUNK_LENGTH = int(CHUNK_LENGTH) | ||
CHUNK_LENGTH = CHUNK_LENGTH |
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.
Lines 506-506
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
|
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 detectIntro
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool [×3] (
remove-unnecessary-cast
) - Move assignments closer to their usage (
move-assign
) - Merge dictionary assignment with declaration [×3] (
merge-dict-assign
)
This removes the following comments ( why? ):
# if both are 0.0, then it's not set
# if introEnd is 0.0, then it's not set
# if introStart is 0.0, then it's not set
episodes = [] | ||
for episode in os.listdir(seasonPath): | ||
if episode.endswith(".mp4") or episode.endswith(".mkv") or episode.endswith(".avi") or episode.endswith(".mov") or episode.endswith(".wmv"): | ||
episodes.append(episode) | ||
return episodes | ||
return [ | ||
episode | ||
for episode in os.listdir(seasonPath) | ||
if episode.endswith(".mp4") | ||
or episode.endswith(".mkv") | ||
or episode.endswith(".avi") | ||
or episode.endswith(".mov") | ||
or episode.endswith(".wmv") | ||
] |
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 listAllVideoFiles
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for compare_element in allIndexes: | ||
if compare_element - element <= 4: | ||
indexes.append(compare_element) | ||
|
||
indexes.extend( | ||
compare_element | ||
for compare_element in allIndexes | ||
if compare_element - element <= 4 | ||
) |
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 compare_audio
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
audio_file_1 = os.path.splitext(video_file_1)[0] + ".wav" | ||
audio_file_2 = os.path.splitext(video_file_2)[0] + ".wav" | ||
audio_file_1 = f"{os.path.splitext(video_file_1)[0]}.wav" | ||
audio_file_2 = f"{os.path.splitext(video_file_2)[0]}.wav" |
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 main
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
if not useImage: | ||
with app.app_context(): | ||
with app.app_context(): | ||
if not useImage: |
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.
Lines 331-352
refactored with the following changes:
- Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if
)
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:Help us improve this pull request!