-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bf1a61
commit f810600
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |