Skip to content

Commit

Permalink
Removed some not available apps, added auto icons and some other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nimafanniasl committed Apr 10, 2024
1 parent 3bb221b commit 93b449f
Show file tree
Hide file tree
Showing 16 changed files with 1,621 additions and 1,076 deletions.
32 changes: 6 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@ permissions:
contents: write

jobs:
# auto_screenshot_from_fdroid:
# runs-on: ubuntu-latest
# name: Automatically Get Screenshots From F-Droid

# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2

# - name: Set up Python
# uses: actions/setup-python@v2
# with:
# python-version: 3.x

# - name: Install Dependencies
# run: pip install -r Scripts/requirements.txt # If you have any dependencies

# - name: Run the Script
# run: python Scripts/auto_screenshot_from_fdroid.py

# - name: Commit and Push Changes
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git commit -m "دریافت خودکار نماگرفت ها از اف دروید"
# git push
deploy:
runs-on: ubuntu-latest
steps:
Expand All @@ -45,6 +19,12 @@ jobs:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV

- name: Install Dependencies
run: pip install -r Scripts/requirements.txt

- name: Run the Auto icon Script
run: python Scripts/auto_icons.py

- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore_dir/
83 changes: 83 additions & 0 deletions Scripts/auto_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import re
import requests
import json
import os

# --------------------------------------------------- #

ICON_WIDTH = "30px"

SCREENSHOTS_WIDTH = "25%"
SCREENSHOTS_HEIGHT = "auto"

# --------------------------------------------------- #

api_content = json.loads(
requests.get(f"https://f-droid.org/repo/index-v2.json").content
)["packages"]

# api_content = json.loads(open("ignore_dir/index-v2.json", "r").read())["packages"]

# Define a function to get the package name from the F-Droid URL
def get_package_name(url: str):
return url.split("/")[-2].replace("/", "")


def generate_img_tag(img_url):
img_tag = f'<img data-src="{img_url}" class="lazy app-icon" width="{ICON_WIDTH}">'
return img_tag

def get_icon(package_name):
package = api_content[package_name]["metadata"]
try:
icon = package["icon"]
except KeyError:
return None

try:
try:
icon_link = "https://f-droid.org/repo" + icon["fa-IR"]["name"]
except KeyError:
icon_link = "https://f-droid.org/repo" + icon["en-US"]["name"]
except:
return None

return generate_img_tag(icon_link)

def process_file(file_path):
# Open the file for reading
with open(file_path, "r", encoding="utf-8") as file:
lines = file.readlines()

# Regular expression pattern to match F-Droid links
fdroid_pattern = re.compile(r"https?://(?:www\.)?f-droid\.org/.*/(.*?)\)")
img_pattern = re.compile(r"<img data-src=\".*\" class=\".*app-icon\".*>")

# Create a new list to store modified lines
new_lines = []

# Iterate through the lines
for line in lines:
if img_pattern.search(line) or "<!-- NoIcon -->" in line:
new_lines.append(line) # Add unchanged line to new list
continue

match = fdroid_pattern.search(line)
if match:
package_name = match.group(1)
img_tag = get_icon(package_name)
if img_tag is None:
img_tag = "<!-- NoIcon -->"
new_lines.append(f"{img_tag}{line}") # Add modified line to new list
else:
new_lines.append(line) # Add unchanged line to new list

# Write the modified content back to the file
with open(file_path, "w", encoding="utf-8") as file:
file.writelines(new_lines)

if __name__ == "__main__":
folder = "docs/android"
files = os.listdir(folder)
for file in files:
process_file(f"{folder}/{file}")
88 changes: 0 additions & 88 deletions Scripts/auto_screenshot_from_fdroid.py

This file was deleted.

1 change: 0 additions & 1 deletion Scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
bs4
requests
Loading

0 comments on commit 93b449f

Please sign in to comment.