mirror of
				https://github.com/inventree/inventree-website.git
				synced 2025-11-04 07:25:46 +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:
		
							
								
								
									
										25
									
								
								.github/get_stats.py
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								.github/get_stats.py
									
									
									
									
										vendored
									
									
								
							@@ -1,18 +1,24 @@
 | 
			
		||||
from enum import Enum
 | 
			
		||||
import json
 | 
			
		||||
import os
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
from urllib.request import urlopen, Request
 | 
			
		||||
 | 
			
		||||
file_name = Path('_data/general/stats.yml')
 | 
			
		||||
github_project = "inventree/inventree"
 | 
			
		||||
crowdin_projet_id = 452300
 | 
			
		||||
 | 
			
		||||
class ReturnMode(Enum):
 | 
			
		||||
  data = 0
 | 
			
		||||
  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"""
 | 
			
		||||
  httprequest = Request(url, headers={"Accept": "application/json"})
 | 
			
		||||
 | 
			
		||||
  if auth:
 | 
			
		||||
    httprequest.add_header("Authorization", f"Bearer {auth}")
 | 
			
		||||
 | 
			
		||||
  with urlopen(httprequest) as response:
 | 
			
		||||
    if mode == ReturnMode.data:
 | 
			
		||||
      data = response.read().decode()
 | 
			
		||||
@@ -26,13 +32,17 @@ def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data):
 | 
			
		||||
 | 
			
		||||
  return data
 | 
			
		||||
 | 
			
		||||
docker = get_data('https://hub.docker.com/v2/repositories/inventree/inventree', 'pull_count')
 | 
			
		||||
gh_data = get_data('https://api.github.com/repos/inventree/inventree')
 | 
			
		||||
docker = get_data(f'https://hub.docker.com/v2/repositories/{github_project}', 'pull_count')
 | 
			
		||||
gh_data = get_data(f'https://api.github.com/repos/{github_project}')
 | 
			
		||||
stars = gh_data.get('stargazers_count', 0)
 | 
			
		||||
forks = gh_data.get('forks_count', 0)
 | 
			
		||||
# 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]
 | 
			
		||||
# 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
 | 
			
		||||
file_name.write_text(
 | 
			
		||||
@@ -44,4 +54,9 @@ f"""stats:
 | 
			
		||||
  - name: Forks
 | 
			
		||||
    number: {forks}
 | 
			
		||||
  - name: Contributors
 | 
			
		||||
    number: {contributors}""")
 | 
			
		||||
    number: {contributors}
 | 
			
		||||
  - name: Languages
 | 
			
		||||
    number: {languages}""")
 | 
			
		||||
  #- name: Translators
 | 
			
		||||
  #  number: {translators}
 | 
			
		||||
  #  """)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user