mirror of
https://github.com/inventree/inventree-website.git
synced 2025-05-15 13:33:10 +00:00
Add translations to state section (#79)
* add option for auth * get crowdin data * factor out project name * add dep * add secret to env * fix step name
This commit is contained in:
parent
6ef25cf8f0
commit
0977b97b1b
25
.github/get_stats.py
vendored
25
.github/get_stats.py
vendored
@ -1,18 +1,24 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.request import urlopen, Request
|
from urllib.request import urlopen, Request
|
||||||
|
|
||||||
file_name = Path('_data/general/stats.yml')
|
file_name = Path('_data/general/stats.yml')
|
||||||
|
github_project = "inventree/inventree"
|
||||||
|
crowdin_projet_id = 452300
|
||||||
|
|
||||||
class ReturnMode(Enum):
|
class ReturnMode(Enum):
|
||||||
data = 0
|
data = 0
|
||||||
header = 1
|
header = 1
|
||||||
|
|
||||||
def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
|
def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data, auth=None):
|
||||||
"""Fetches data from remote endpoint"""
|
"""Fetches data from remote endpoint"""
|
||||||
httprequest = Request(url, headers={"Accept": "application/json"})
|
httprequest = Request(url, headers={"Accept": "application/json"})
|
||||||
|
|
||||||
|
if auth:
|
||||||
|
httprequest.add_header("Authorization", f"Bearer {auth}")
|
||||||
|
|
||||||
with urlopen(httprequest) as response:
|
with urlopen(httprequest) as response:
|
||||||
if mode == ReturnMode.data:
|
if mode == ReturnMode.data:
|
||||||
data = response.read().decode()
|
data = response.read().decode()
|
||||||
@ -26,13 +32,17 @@ def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
docker = get_data('https://hub.docker.com/v2/repositories/inventree/inventree', 'pull_count')
|
docker = get_data(f'https://hub.docker.com/v2/repositories/{github_project}', 'pull_count')
|
||||||
gh_data = get_data('https://api.github.com/repos/inventree/inventree')
|
gh_data = get_data(f'https://api.github.com/repos/{github_project}')
|
||||||
stars = gh_data.get('stargazers_count', 0)
|
stars = gh_data.get('stargazers_count', 0)
|
||||||
forks = gh_data.get('forks_count', 0)
|
forks = gh_data.get('forks_count', 0)
|
||||||
# See https://stackoverflow.com/a/60458265/17860466 # to enabble anon add `&anon=true`
|
# See https://stackoverflow.com/a/60458265/17860466 # to enabble anon add `&anon=true`
|
||||||
link = get_data('https://api.github.com/repos/inventree/inventree/contributors?per_page=1', mode=ReturnMode.header).get('Link')
|
link = get_data(f'https://api.github.com/repos/{github_project}/contributors?per_page=1', mode=ReturnMode.header).get('Link')
|
||||||
contributors = link.split('page=')[-1].split('>')[0]
|
contributors = link.split('page=')[-1].split('>')[0]
|
||||||
|
# Crowdin
|
||||||
|
crowdin_data = get_data(f'https://api.crowdin.com/api/v2/projects/{crowdin_projet_id}?limit=1000', 'data', auth=os.environ.get('CROWDIN_TOKEN'))
|
||||||
|
languages = len(crowdin_data.get('targetLanguageIds', []))
|
||||||
|
#translators = get_data(f'https://api.crowdin.com/api/v2/projects/{crowdin_projet_id}/members', 'data', auth=crowdin_token)
|
||||||
|
|
||||||
# Write data
|
# Write data
|
||||||
file_name.write_text(
|
file_name.write_text(
|
||||||
@ -44,4 +54,9 @@ f"""stats:
|
|||||||
- name: Forks
|
- name: Forks
|
||||||
number: {forks}
|
number: {forks}
|
||||||
- name: Contributors
|
- name: Contributors
|
||||||
number: {contributors}""")
|
number: {contributors}
|
||||||
|
- name: Languages
|
||||||
|
number: {languages}""")
|
||||||
|
#- name: Translators
|
||||||
|
# number: {translators}
|
||||||
|
# """)
|
||||||
|
4
.github/workflows/get_stats.yml
vendored
4
.github/workflows/get_stats.yml
vendored
@ -12,8 +12,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set selected color
|
- name: Get Stats
|
||||||
run: python .github/get_stats.py
|
run: python .github/get_stats.py
|
||||||
|
env:
|
||||||
|
CROWDIN_TOKEN: ${{ secrets.CROWDIN_TOKEN }}
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v4
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
with:
|
with:
|
||||||
commit_message: "[Bot] Updated the stats"
|
commit_message: "[Bot] Updated the stats"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user