Skip to content

Commit

Permalink
Merge pull request #4 from Vulpeus-Server/modrinth-readme-updater
Browse files Browse the repository at this point in the history
Modrinth readme updater
  • Loading branch information
topi-banana authored Oct 1, 2024
2 parents 8f8012d + 73352bc commit adaa40f
Show file tree
Hide file tree
Showing 3 changed files with 487 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/scripts/update_modrinth_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Update Modrinth Readme
"""
__author__ = 'topi_banana'

import os
import sys
import json
import requests
from rich import print

def throw_api(id: str, body: str = "") -> int:

res = requests.patch(
f"https://api.modrinth.com/v2/project/{id}",
data=json.dumps({
"body": body
}),
headers={
"Content-Type": "application/json",
"Authorization": os.environ['SECRET'],
},
)

if res.status_code != 204:
body = res.json()
print(body["error"])
print(body["description"])
sys.exit(1)

def main(id: str, path: str):
with open(path, encoding="utf_8") as f:
body = f.read()
throw_api(id, body)

if __name__ == '__main__':
args = sys.argv
main(id=args[1], path=args[2])
22 changes: 22 additions & 0 deletions .github/workflows/update_modrinth_readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Update Modrinth Readme

on:
push:
branches:
- master
jobs:
update_modrinth_readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
architecture: 'x64'
- name: Install dependencies
run: pip install requests rich
- name: Run Python Script
run: python .github/workflows/scripts/update_modrinth_readme.py aZhtZo3k Modrinth.md
env:
SECRET: ${{ secrets.MODRINTH_API_TOKEN }}
Loading

0 comments on commit adaa40f

Please sign in to comment.