forked from Klomgor/online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweblate-leader-board-parser.py
69 lines (61 loc) · 2.07 KB
/
weblate-leader-board-parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/env python
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# Copyright the Collabora Online contributors.
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#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)
# vim: set shiftwidth=4 softtabstop=4 expandtab: