261e8cac30
Used for translators leader-board in the forum Signed-off-by: Pedro Pinto Silva <pedro.silva@collabora.com> Change-Id: I04a557c3beaa109b0ab010ca32ec749b585d07cc
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
#!/bin/env python
|
|
#coding: utf8
|
|
import json
|
|
import sys
|
|
|
|
# This script is used in the forum for weblate montly stats
|
|
|
|
if len(sys.argv) > 1:
|
|
json_filename = sys.argv[1]
|
|
else:
|
|
print('''
|
|
JSON file missing
|
|
Please run this script with the translation file path as a parameter\n
|
|
Generate a json file from "Contributor Stats"
|
|
https://hosted.weblate.org/projects/collabora-online/#reports\n
|
|
Then run the script, example:
|
|
python3 weblate-translation-count-parser.py april-translations-count.json
|
|
''')
|
|
sys.exit(0)
|
|
|
|
if len(sys.argv) == 3:
|
|
use_markdown = bool(sys.argv[2])
|
|
else:
|
|
use_markdown = False
|
|
|
|
with open(sys.argv[1], 'r') as json_data:
|
|
data = json.load(json_data)
|
|
|
|
# Or from string
|
|
# data = json.loads('[{"name" : "1", "two" : "2", "three" : "3"}]')
|
|
|
|
def print_parsed(msg, markdowned):
|
|
if markdowned is False:
|
|
print(msg)
|
|
l_r_separator = ''
|
|
m_separator = ': '
|
|
else:
|
|
print(msg + '\n| Translator | Number of strings |\n| --- | --- |')
|
|
l_r_separator = '|'
|
|
m_separator = '|'
|
|
medal_it = 1
|
|
for weblate_user in data:
|
|
if medal_it is 1:
|
|
medal_str = ':1st_place_medal: '
|
|
elif medal_it is 2:
|
|
medal_str = ':2nd_place_medal: '
|
|
elif medal_it is 3:
|
|
medal_str = ':3rd_place_medal: '
|
|
else:
|
|
medal_str = ''
|
|
weblate_row = l_r_separator + medal_str + weblate_user['name'] + m_separator + str(weblate_user['count']) + l_r_separator
|
|
print (weblate_row)
|
|
medal_it +=1
|
|
|
|
# print_parsed('\nOriginal:\n')
|
|
data.sort(key=lambda x: x['count'], reverse=True)
|
|
print_parsed('\nParsed from ' + json_filename + ':\n', use_markdown)
|