"""Status check.""" import json import re from typing import List import requests from bs4 import BeautifulSoup from google_play_scraper import app as gplay_app from google_play_scraper.exceptions import GooglePlayScraperException from src.patches import Patches from src.utils import handle_response not_found_icon = "https://img.icons8.com/bubbles/500/android-os.png" def apkmirror_scrapper(package_name: str) -> str: """Apkmirror URL.""" apk_mirror_base_url = "https://www.apkmirror.com" check_if_exist = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/" body = {"pnames": [package_name]} check_header = { "User-Agent": "APKUpdater-v" + "3.0.1", "Authorization": "Basic YXBpLWFwa3VwZGF0ZXI6cm01cmNmcnVVakt5MDRzTXB5TVBKWFc4", "Content-Type": "application/json", } response = json.loads( requests.post( check_if_exist, data=json.dumps(body), headers=check_header ).content ) if response["data"][0]["exists"]: headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko)" " Chrome/96.0.4664.93 Safari/537.36" } search_url = f"{apk_mirror_base_url}/?s={package_name}" r = requests.get(search_url, headers=headers) soup = BeautifulSoup(r.text, "html.parser") sub_url = soup.select_one("div.bubble-wrap > img")["src"] new_width = 500 new_height = 500 new_quality = 100 # regular expression pattern to match w=xx&h=xx&q=xx pattern = r"(w=\d+&h=\d+&q=\d+)" # Replace the matched patterns with the new dimensions and q value apk_mirror_url = apk_mirror_base_url + re.sub( pattern, f"w={new_width}&h={new_height}&q={new_quality}", sub_url ) return apk_mirror_url return not_found_icon def gplay_icon_scrapper(package_name: str) -> str: """Scrap Icon from Gplay.""" # noinspection PyBroadException try: result = gplay_app( package_name, ) if result["icon"]: return str(result["icon"]) raise GooglePlayScraperException() except GooglePlayScraperException: return apkmirror_scrapper(package_name) except Exception: return not_found_icon def generate_markdown_table(data: List[List[str]]) -> str: """Generate table.""" if len(data) == 0: return "No data to generate table." table = "| Package Name | App Icon | PlayStore link | APKMirror link| Supported?|\n" table += ( "|-------------|----------|----------------|---------------|------------|\n" ) for row in data: if len(row) != 5: raise ValueError("Each row must contain 4 columns of data.") table += f"| {row[0]} | {row[1]} | {row[2]} | {row[3]} |{row[4]} |\n" return table def main() -> None: repo_url = "https://api.revanced.app/v2/patches/latest" response = requests.get(repo_url) handle_response(response) parsed_data = response.json() compatible_packages = parsed_data["patches"] possible_apps = set() for package in compatible_packages: for compatible_package in package["compatiblePackages"]: possible_apps.add(compatible_package["name"]) supported_app = set(Patches.support_app().keys()) missing_support = sorted(possible_apps.difference(supported_app)) output = "New app found which aren't supported or outdated.\n\n" data = [] for index, app in enumerate(missing_support): data.append( [ app, f'', f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})", f"[APKMirror Link](https://www.apkmirror.com/?s={app})", "
  • - [ ]
  • ", ] ) table = generate_markdown_table(data) output += table with open("status.md", "w", encoding="utf_8") as status: status.write(output) print(output) if __name__ == "__main__": main()