Skip to content

Commit

Permalink
Add generate.py and workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
s3tupw1zard committed Aug 6, 2024
1 parent 9bf1a61 commit f810600
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Generate JSON
on:
push:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'

- name: Setup Dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Generate JSON
run: |
export GIT_TOKEN="${{ secrets.AUTH_KEY }}"
python generate.py "${{ secrets.GITHUB_TOKEN }}" > modules.json
- name: Commit Changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "s3tupw1zard"
git add modules.json
git commit -sm "Update modules.json" || true
git push || true
54 changes: 54 additions & 0 deletions generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import sys
import json
import os
from github import Github

# Configuration
REPO_NAME = "smr"
REPO_TITLE = "s3tupw1zard's Magisk Repo"

# Skeleton for the repository
meta = {
"name": REPO_TITLE,
"last_update": "",
"modules": []
}

# Initialize the GitHub objects
g = Github(os.environ['GIT_TOKEN'])
user = g.get_user(REPO_NAME)
repos = user.get_repos()

# Fetch the last repository update
meta["last_update"] = int(user.updated_at.timestamp() * 1000)

# Iterate over all public repositories
for repo in repos:
# It is possible that module.prop does not exist (meta repo)
try:
# Parse module.prop into a python object
moduleprop_raw = repo.get_contents("module.prop").decoded_content.decode("UTF-8")
moduleprop = {}
for line in moduleprop_raw.splitlines():
if "=" not in line:
continue
lhs, rhs = line.split("=", 1)
moduleprop[lhs] = rhs

# Create meta module information
module = {
"id": moduleprop["id"],
"last_update": int(repo.updated_at.timestamp() * 1000),
"prop_url": f"https://raw.githubusercontent.com/{repo.full_name}/{repo.default_branch}/module.prop",
"zip_url": f"https://github.com/{repo.full_name}/archive/{repo.default_branch}.zip",
"notes_url": f"https://raw.githubusercontent.com/{repo.full_name}/{repo.default_branch}/README.md",
"stars": int(repo.stargazers_count)
}

# Append to skeleton
meta["modules"].append(module)
except:
continue

# Return our final skeleton
print(json.dumps(meta, indent=4, sort_keys=True))

0 comments on commit f810600

Please sign in to comment.