🚨 Updated lints (#308)

This commit is contained in:
Nikhil Badyal
2023-08-25 15:36:50 +05:30
committed by GitHub
parent 09b815cb21
commit 77377cdd48
26 changed files with 404 additions and 487 deletions
+26 -26
View File
@@ -1,5 +1,6 @@
"""Status check."""
import re
from pathlib import Path
from typing import List
import requests
@@ -7,30 +8,26 @@ from bs4 import BeautifulSoup
from google_play_scraper import app as gplay_app
from google_play_scraper.exceptions import GooglePlayScraperException
from src.exceptions import APKMirrorIconScrapFailure
from src.exceptions import APKComboIconScrapError, APKMirrorIconScrapError, UnknownError
from src.patches import Patches
from src.utils import (
apk_mirror_base_url,
apkmirror_status_check,
bs4_parser,
handle_request_response,
request_header,
)
from src.utils import apk_mirror_base_url, apkmirror_status_check, bs4_parser, handle_request_response, request_header
not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png"
no_of_col = 6
def apkcombo_scrapper(package_name: str) -> str:
"""Apkcombo scrapper."""
try:
apkcombo_url = f"https://apkcombo.com/genericApp/{package_name}"
r = requests.get(
apkcombo_url, headers=request_header, allow_redirects=True, timeout=10
)
r = requests.get(apkcombo_url, headers=request_header, allow_redirects=True, timeout=10)
soup = BeautifulSoup(r.text, bs4_parser)
url = soup.select_one("div.avatar > img")["data-src"]
return re.sub(r"=.*$", "", url)
except Exception:
icon_element = soup.select_one("div.bubble-wrap > img")
if not icon_element:
raise APKComboIconScrapError(url=apkcombo_url)
url = icon_element["data-src"]
return re.sub(r"=.*$", "", url) # type: ignore[arg-type]
except UnknownError:
return not_found_icon
@@ -40,13 +37,16 @@ def apkmirror_scrapper(package_name: str) -> str:
search_url = f"{apk_mirror_base_url}/?s={package_name}"
if response["data"][0]["exists"]:
return _extracted_from_apkmirror_scrapper(search_url)
raise APKMirrorIconScrapFailure(url=search_url)
raise APKMirrorIconScrapError(url=search_url)
def _extracted_from_apkmirror_scrapper(search_url: str) -> str:
r = requests.get(search_url, headers=request_header, timeout=60)
soup = BeautifulSoup(r.text, bs4_parser)
sub_url = soup.select_one("div.bubble-wrap > img")["src"]
icon_element = soup.select_one("div.bubble-wrap > img")
if not icon_element:
raise APKMirrorIconScrapError(url=search_url)
sub_url = str(icon_element["src"])
new_width = 500
new_height = 500
new_quality = 100
@@ -54,9 +54,7 @@ def _extracted_from_apkmirror_scrapper(search_url: str) -> str:
# regular expression pattern to match w=xx&h=xx&q=xx
pattern = r"(w=\d+&h=\d+&q=\d+)"
return apk_mirror_base_url + re.sub(
pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url
)
return apk_mirror_base_url + re.sub(pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url)
def gplay_icon_scrapper(package_name: str) -> str:
@@ -68,13 +66,13 @@ def gplay_icon_scrapper(package_name: str) -> str:
)
if result["icon"]:
return str(result["icon"])
raise GooglePlayScraperException()
raise GooglePlayScraperException
except GooglePlayScraperException:
try:
return apkmirror_scrapper(package_name)
except APKMirrorIconScrapFailure:
except APKMirrorIconScrapError:
return apkcombo_scrapper(package_name)
except Exception:
except UnknownError:
return not_found_icon
@@ -85,11 +83,12 @@ def generate_markdown_table(data: List[List[str]]) -> str:
table = (
"| Package Name | App Icon | PlayStore link | APKMirror link|APKCombo Link| Supported?|\n"
+ "|-------------|----------|----------------|---------------|------------------|----------|\n"
"|-------------|----------|----------------|---------------|------------------|----------|\n"
)
for row in data:
if len(row) != 6:
raise ValueError("Each row must contain 6 columns of data.")
if len(row) != no_of_col:
msg = "Each row must contain 6 columns of data."
raise ValueError(msg)
table += f"| {row[0]} | {row[1]} | {row[2]} | {row[3]} |{row[4]} |{row[5]} |\n"
@@ -97,6 +96,7 @@ def generate_markdown_table(data: List[List[str]]) -> str:
def main() -> None:
"""Entrypoint."""
repo_url = "https://releases.revanced.app/patches"
response = requests.get(repo_url, timeout=10)
handle_request_response(response)
@@ -124,7 +124,7 @@ def main() -> None:
]
table = generate_markdown_table(data)
output += table
with open("status.md", "w", encoding="utf_8") as status:
with Path("status.md").open("w", encoding="utf_8") as status:
status.write(output)
print(output)