'Refactored by Sourcery'

This commit is contained in:
Sourcery AI
2023-08-08 03:36:41 +00:00
parent b1668a96a1
commit 6b1cefadf4
7 changed files with 43 additions and 53 deletions
+17 -19
View File
@@ -59,11 +59,9 @@ def apkmirror_scrapper(package_name: str) -> str:
# regular expression pattern to match w=xx&h=xx&q=xx # regular expression pattern to match w=xx&h=xx&q=xx
pattern = r"(w=\d+&h=\d+&q=\d+)" pattern = r"(w=\d+&h=\d+&q=\d+)"
# Replace the matched patterns with the new dimensions and q value return apk_mirror_base_url + re.sub(
apk_mirror_url = apk_mirror_base_url + re.sub(
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
) )
return apk_mirror_url
raise APKMirrorScrapperFailure() raise APKMirrorScrapperFailure()
@@ -88,12 +86,13 @@ def gplay_icon_scrapper(package_name: str) -> str:
def generate_markdown_table(data: List[List[str]]) -> str: def generate_markdown_table(data: List[List[str]]) -> str:
"""Generate table.""" """Generate table."""
if len(data) == 0: if not data:
return "No data to generate table." return "No data to generate table."
table = "| Package Name | App Icon | PlayStore link | APKMirror link|APKCombo Link| Supported?|\n" table = (
table += "|-------------|----------|----------------|---------------|------------------|----------|\n" "| Package Name | App Icon | PlayStore link | APKMirror link|APKCombo Link| Supported?|\n"
+ "|-------------|----------|----------------|---------------|------------------|----------|\n"
)
for row in data: for row in data:
if len(row) != 6: if len(row) != 6:
raise ValueError("Each row must contain 4 columns of data.") raise ValueError("Each row must contain 4 columns of data.")
@@ -119,18 +118,17 @@ def main() -> None:
supported_app = set(Patches.support_app().keys()) supported_app = set(Patches.support_app().keys())
missing_support = sorted(possible_apps.difference(supported_app)) missing_support = sorted(possible_apps.difference(supported_app))
output = "New app found which aren't supported or outdated.\n\n" output = "New app found which aren't supported or outdated.\n\n"
data = [] data = [
for index, app in enumerate(missing_support): [
data.append( app,
[ f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>',
app, f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})",
f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>', f"[APKMirror Link](https://www.apkmirror.com/?s={app})",
f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})", f"[APKCombo Link](https://apkcombo.com/genericApp/{app})",
f"[APKMirror Link](https://www.apkmirror.com/?s={app})", "<li>- [ ] </li>",
f"[APKCombo Link](https://apkcombo.com/genericApp/{app})", ]
"<li>- [ ] </li>", for app in missing_support
] ]
)
table = generate_markdown_table(data) table = generate_markdown_table(data)
output += table output += table
with open("status.md", "w", encoding="utf_8") as status: with open("status.md", "w", encoding="utf_8") as status:
+1 -2
View File
@@ -56,8 +56,7 @@ class ApkMirror(Downloader):
f"Unable to find any apk on apkmirror_specific_version on {main_page}" f"Unable to find any apk on apkmirror_specific_version on {main_page}"
) )
raise AppNotFound("Unable to find apk on apkmirror site.") raise AppNotFound("Unable to find apk on apkmirror site.")
download_url = self.config.apk_mirror + sub_url return self.config.apk_mirror + sub_url
return download_url
def specific_version(self, app: str, version: str) -> None: def specific_version(self, app: str, version: str) -> None:
"""Function to download the specified version of app from apkmirror. """Function to download the specified version of app from apkmirror.
+1 -3
View File
@@ -45,9 +45,7 @@ class Downloader(object):
headers = {} headers = {}
if self.config.personal_access_token and "github" in url: if self.config.personal_access_token and "github" in url:
logger.debug("Using personal access token") logger.debug("Using personal access token")
headers.update( headers["Authorization"] = f"token {self.config.personal_access_token}"
{"Authorization": "token " + self.config.personal_access_token}
)
response = self.config.session.get( response = self.config.session.get(
url, url,
stream=True, stream=True,
+1 -1
View File
@@ -24,7 +24,7 @@ class DownloaderFactory(object):
patcher : Patcher patcher : Patcher
config : Config config : Config
""" """
if app == "patches" or app == "microg": if app in {"patches", "microg"}:
return Github(patcher, config) return Github(patcher, config)
if app in config.apk_pure: if app in config.apk_pure:
return ApkPure(patcher, config) return ApkPure(patcher, config)
+1 -3
View File
@@ -31,9 +31,7 @@ class Github(Downloader):
} }
if self.config.personal_access_token: if self.config.personal_access_token:
logger.debug("Using personal access token") logger.debug("Using personal access token")
headers.update( headers["Authorization"] = f"token {self.config.personal_access_token}"
{"Authorization": "token " + self.config.personal_access_token}
)
response = requests.get(repo_url, headers=headers) response = requests.get(repo_url, headers=headers)
handle_response(response) handle_response(response)
if repo_name == "revanced-patches": if repo_name == "revanced-patches":
+2 -4
View File
@@ -81,7 +81,7 @@ class Parser(object):
"-jar", "-jar",
app.resource["cli"], app.resource["cli"],
"-a", "-a",
app.app_name + ".apk", f"{app.app_name}.apk",
"-b", "-b",
app.resource["patches"], app.resource["patches"],
"-m", "-m",
@@ -104,9 +104,7 @@ class Parser(object):
if app.app_name in self.config.rip_libs_apps: if app.app_name in self.config.rip_libs_apps:
excluded = set(possible_archs) - set(app.archs_to_build) excluded = set(possible_archs) - set(app.archs_to_build)
for arch in excluded: for arch in excluded:
args.append("--rip-lib") args.extend(("--rip-lib", arch))
args.append(arch)
start = perf_counter() start = perf_counter()
logger.debug( logger.debug(
f"Sending request to revanced cli for building with args java {args}" f"Sending request to revanced cli for building with args java {args}"
+20 -21
View File
@@ -16,27 +16,26 @@ possible_archs = ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
def update_changelog(name: str, response: Dict[str, str]) -> None: def update_changelog(name: str, response: Dict[str, str]) -> None:
"""Updated Changelog.""" """Updated Changelog."""
parent_repo = "https://github.com/nikhilbadyal/docker-py-revanced" parent_repo = "https://github.com/nikhilbadyal/docker-py-revanced"
file1 = open("changelog.md", "a", encoding="utf_8") with open("changelog.md", "a", encoding="utf_8") as file1:
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n" collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
release_version = ( release_version = (
f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>" f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
) )
change_log = f"**Changelog** -<br> {response['body']}" change_log = f"**Changelog** -<br> {response['body']}"
publish_time = f"**Published at** -<br> {response['published_at']}" publish_time = f"**Published at** -<br> {response['published_at']}"
footer = ( footer = (
f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n" f"<br><sub>Change logs generated by [Docker Py Revanced]({parent_repo})</sub>\n"
) )
collapse_end = "</details>" collapse_end = "</details>"
change_log = ( change_log = (
collapse_start collapse_start
+ release_version + release_version
+ change_log + change_log
+ publish_time + publish_time
+ footer + footer
+ collapse_end + collapse_end
) )
file1.write(change_log) file1.write(change_log)
file1.close()
class AppNotFound(ValueError): class AppNotFound(ValueError):