-
Notifications
You must be signed in to change notification settings - Fork 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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
@@ -34,7 +34,6 @@ | |||
|
|||
|
|||
@app.get("/api/v1/search") | |||
# @cache(expire=CACHE_EXPIRATION) |
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 call_api
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
This removes the following comments ( why? ):
# @cache(expire=CACHE_EXPIRATION)
@@ -58,7 +57,6 @@ async def call_api( | |||
|
|||
|
|||
@app.get("/api/v1/trending") | |||
# @cache(expire=CACHE_EXPIRATION) |
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 get_trending
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Hoist a repeated condition into a parent condition (
hoist-repeated-if-condition
) - Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# @cache(expire=CACHE_EXPIRATION)
return {"error": "invalid site"} | ||
|
||
|
||
@app.get("/api/v1/category") | ||
# @cache(expire=CACHE_EXPIRATION) |
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 get_category
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use x is None rather than x == None (
none-compare
) - Replace call to format with f-string (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# @cache(expire=CACHE_EXPIRATION)
return {"error": "invalid site"} | ||
|
||
|
||
@app.get("/api/v1/recent") | ||
# @cache(expire=CACHE_EXPIRATION) |
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 get_recent
refactored with the following changes:
- Swap if/else branches [×2] (
swap-if-else-branches
) - Remove unnecessary else after guard condition [×2] (
remove-unnecessary-else
) - Hoist a repeated condition into a parent condition (
hoist-repeated-if-condition
) - Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# @cache(expire=CACHE_EXPIRATION)
if site in all_sites.keys(): | ||
if site in all_sites: |
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 check_if_site_available
refactored with the following changes:
- Remove unnecessary call to keys() (
remove-dict-keys
)
if not category: | ||
url = self.BASE_URL + "/new/" | ||
else: | ||
url = self.BASE_URL + "/{}/".format(category) | ||
url = self.BASE_URL + f"/{category}/" if category else f"{self.BASE_URL}/new/" |
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 Kickass.recent
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Replace if statement with if expression (
assign-if-exp
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
if a.text == "One-filetorrent": | ||
if a["href"] != "#": | ||
obj["torrent"] = self.BASE_URL + a["href"] | ||
poster = soup.find_all("img")[0] | ||
|
||
if poster: | ||
if a.text == "One-filetorrent" and a["href"] != "#": | ||
obj["torrent"] = self.BASE_URL + a["href"] | ||
if poster := soup.find_all("img")[0]: |
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 Libgen._individual_scrap
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
authors = [] | ||
author = td[1].find_all("a") | ||
for a in author: | ||
authors.append(a.text.strip()) | ||
authors = [a.text.strip() for a in author] | ||
name_and_url = td[2].find("a") | ||
name = name_and_url.text | ||
url = self.BASE_URL + "/" + name_and_url["href"] | ||
url = f"{self.BASE_URL}/" + name_and_url["href"] |
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 Libgen._parser
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
+ "/search.php?req={}&lg_topic=libgen&open=0&view=simple&res=100&phrase=1&column=def".format( | ||
query | ||
) | ||
+ f"/search.php?req={query}&lg_topic=libgen&open=0&view=simple&res=100&phrase=1&column=def" | ||
) | ||
|
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 Libgen.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
).group(0) | ||
)[0] | ||
|
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 Limetorrent._individual_scrap
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
url = self.BASE_URL + "/search/all/{}//{}".format(query, page) | ||
url = self.BASE_URL + f"/search/all/{query}//{page}" |
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 Limetorrent.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
url = self.BASE_URL + "/top100" | ||
url = f"{self.BASE_URL}/top100" |
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 Limetorrent.trending
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
url = self.BASE_URL + "/latest100" | ||
url = f"{self.BASE_URL}/latest100" | ||
else: | ||
category = (category).capitalize() | ||
if category == "Apps": | ||
category = "Applications" | ||
elif category == "Tv": | ||
category = "TV-shows" | ||
url = self.BASE_URL + "/browse-torrents/{}/date/{}/".format( | ||
category, page | ||
) | ||
url = (self.BASE_URL + f"/browse-torrents/{category}/date/{page}/") |
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 Limetorrent.recent
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
).group(0), | ||
)[0], | ||
"magnet": magnet, | ||
"url": self.BASE_URL + url, | ||
"date": date, | ||
} | ||
) | ||
|
||
if len(my_dict["data"]) == self.LIMIT: | ||
break | ||
total_results = soup.find("div", id="footer").text.replace(",", "") | ||
current_page = int( | ||
(re.search(r"Page\s\d*", total_results).group(0)).replace( | ||
"Page ", "" | ||
) | ||
re.search(r"Page\s\d*", total_results)[0].replace("Page ", "") | ||
) | ||
|
||
total_pages = ( | ||
int( | ||
( | ||
(re.search(r"Found\s\d*", total_results).group(0)).replace( | ||
"Found ", "" | ||
) | ||
re.search(r"Found\s\d*", total_results)[0].replace( | ||
"Found ", "" | ||
) | ||
) | ||
// 40 | ||
) | ||
|
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 Magnetdl._parser
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
)
url = self.BASE_URL + "/{}/{}/se/desc/{}/".format(query[0], query, page) | ||
url = self.BASE_URL + f"/{query[0]}/{query}/se/desc/{page}/" |
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 Magnetdl.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
url = self.BASE_URL + "/fresh.html" | ||
url = f"{self.BASE_URL}/fresh.html" | ||
else: | ||
if category == "books": | ||
category = "ebooks" | ||
url = self.BASE_URL + "/{}/{}/added/desc.html".format(category, page) | ||
url = self.BASE_URL + f"/{category}/{page}/added/desc.html" |
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 Torlock.recent
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
url = self.BASE_URL + "/?t={}&p={}".format(query, page - 1) | ||
url = self.BASE_URL + f"/?t={query}&p={page - 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 TorrentProject.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
).group(0), | ||
)[0], | ||
"magnet": magnet, | ||
"torrent": torrent, | ||
"url": self.BASE_URL + url, | ||
"date": date, | ||
} | ||
) | ||
|
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 TorrentGalaxy._parser
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
+ "/torrents.php?search=+{}&sort=seeders&order=desc&page={}".format( | ||
query, page - 1 | ||
) | ||
+ f"/torrents.php?search=+{query}&sort=seeders&order=desc&page={page - 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 TorrentGalaxy.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
url = self.BASE_URL + "/latest" | ||
url = f"{self.BASE_URL}/latest" | ||
else: | ||
if category == "documentaries": | ||
category = "Docus" | ||
url = ( | ||
self.BASE_URL | ||
+ "/torrents.php?parent_cat={}&sort=id&order=desc&page={}".format( | ||
str(category).capitalize(), page - 1 | ||
) | ||
+ f"/torrents.php?parent_cat={str(category).capitalize()}&sort=id&order=desc&page={page - 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 TorrentGalaxy.recent
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
"uploader": uploader if uploader else None, | ||
"uploader": uploader or None, | ||
"url": url, | ||
} | ||
) | ||
|
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 TorrentFunk._parser
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
)
url = self.BASE_URL + "/all/torrents/{}/{}.html".format(query, page) | ||
url = self.BASE_URL + f"/all/torrents/{query}/{page}.html" |
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 TorrentFunk.search
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
url = self.BASE_URL + "/movies/recent.html" | ||
url = f"{self.BASE_URL}/movies/recent.html" |
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 TorrentFunk.recent
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
obj["poster"] = "https:" + poster | ||
obj["poster"] = f"https:{poster}" | ||
elif str(poster).startswith("/"): | ||
obj["poster"] = self.BASE_URL + poster | ||
except: | ||
pass | ||
obj["magnet"] = magnet | ||
|
||
obj["hash"] = re.search( | ||
r"([{a-f\d,A-F\d}]{32,40})\b", magnet | ||
).group(0) | ||
obj["hash"] = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet)[ | ||
0 | ||
] | ||
|
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 x1337._individual_scrap
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
name = td[0].find_all("a")[-1].text | ||
if name: | ||
if name := td[0].find_all("a")[-1].text: |
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 x1337._parser
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
hash = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet).group(0) | ||
hash = re.search(r"([{a-f\d,A-F\d}]{32,40})\b", magnet)[0] |
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 Yts._individual_scrap
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
+ "/browse-movies/{}/all/all/0/latest/0/all?page={}".format( | ||
query, page | ||
) | ||
+ f"/browse-movies/{query}/all/all/0/latest/0/all?page={page}" | ||
) | ||
|
||
else: | ||
url = self.BASE_URL + "/browse-movies/{}/all/all/0/latest/0/all".format( | ||
query | ||
) | ||
url = (self.BASE_URL + f"/browse-movies/{query}/all/all/0/latest/0/all") |
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 Yts.search
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
url = self.BASE_URL + "/trending-movies" | ||
url = f"{self.BASE_URL}/trending-movies" |
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 Yts.trending
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
url = self.BASE_URL + "/browse-movies/0/all/all/0/featured/0/all" | ||
url = f"{self.BASE_URL}/browse-movies/0/all/all/0/featured/0/all" |
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 Yts.recent
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
).group(0), | ||
)[0], | ||
"magnet": magnet, | ||
"url": self.BASE_URL + url, | ||
"date": date, | ||
} | ||
) | ||
|
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 Zooqle._parser
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.01%.
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! |
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!