🎨 use scripts to extract icons

This commit is contained in:
Nikhil Badyal
2023-08-06 21:04:14 +05:30
parent 3a6f35f59c
commit b8c8983de8
2 changed files with 16 additions and 12 deletions
+1
View File
@@ -1,5 +1,6 @@
beautifulsoup4==4.12.2 beautifulsoup4==4.12.2
environs==9.5.0 environs==9.5.0
google-play-scraper==1.2.4
lastversion==3.0.1 lastversion==3.0.1
loguru==0.7.0 loguru==0.7.0
pre-commit==3.3.3 pre-commit==3.3.3
+15 -12
View File
@@ -2,7 +2,7 @@
from typing import List from typing import List
import requests import requests
from bs4 import BeautifulSoup from google_play_scraper import app as gplay_app
from src.patches import Patches from src.patches import Patches
from src.utils import handle_response from src.utils import handle_response
@@ -14,13 +14,12 @@ def gplay_icon_scrapper(package_name: str) -> str:
"""Scrap Icon from Gplay.""" """Scrap Icon from Gplay."""
# noinspection PyBroadException # noinspection PyBroadException
try: try:
app_url = ( result = gplay_app(
f"https://play.google.com/store/apps/details?id={package_name}&hl=en&gl=US" package_name,
) )
response = requests.get(app_url) if not result["icon"]:
soup = BeautifulSoup(response.text, "html.parser") raise ValueError()
icon = soup.select_one("div.Il7kR > img") return str(result["icon"])
return str(icon["srcset"].split(" ")[0])
except Exception: except Exception:
return not_found_icon return not_found_icon
@@ -30,14 +29,16 @@ def generate_markdown_table(data: List[List[str]]) -> str:
if len(data) == 0: if len(data) == 0:
return "No data to generate table." return "No data to generate table."
table = "| Package Name | PlayStore link | APKMirror link| Supported ?|\n" table = "| Package Name | App Icon | PlayStore link | APKMirror link| Supported?|\n"
table += "|-------------|----------------|---------------|------------|\n" table += (
"|-------------|----------|----------------|---------------|------------|\n"
)
for row in data: for row in data:
if len(row) != 3: if len(row) != 5:
raise ValueError("Each row must contain 4 columns of data.") raise ValueError("Each row must contain 4 columns of data.")
table += f"| {row[0]} | {row[1]} | {row[2]} | <li>- [ ] </li> |\n" table += f"| {row[0]} | {row[1]} | {row[2]} | {row[3]} |{row[4]} |\n"
return table return table
@@ -57,14 +58,16 @@ def main() -> None:
supported_app = set(Patches.support_app().keys()) supported_app = set(Patches.support_app().keys())
missing_support = possible_apps.difference(supported_app) missing_support = possible_apps.difference(supported_app)
output = "New app found which aren't supported yet.\n\n" output = "New app found which aren't supported or outdated.\n\n"
data = [] data = []
for index, app in enumerate(missing_support): for index, app in enumerate(missing_support):
data.append( data.append(
[ [
app,
f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>', f'<img src="{gplay_icon_scrapper(app)}" width=50 height=50>',
f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})", f"[PlayStore Link](https://play.google.com/store/apps/details?id={app})",
f"[APKMirror Link](https://www.apkmirror.com/?s={app})", f"[APKMirror Link](https://www.apkmirror.com/?s={app})",
"<li>- [ ] </li>",
] ]
) )
table = generate_markdown_table(data) table = generate_markdown_table(data)