forked from lilydjwg/swapview-rosetta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrankchange
More file actions
executable file
·36 lines (30 loc) · 780 Bytes
/
rankchange
File metadata and controls
executable file
·36 lines (30 loc) · 780 Bytes
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
#!/usr/bin/python3
import re
import sys
color_esc_re = re.compile(r'\x1b[\[0-9;]*[mK]')
def get_rank(path):
ret = {}
with open(path) as f:
for i, l in enumerate(f):
l = color_esc_re.sub('', l)
lang = l.split(None, 1)[0].strip()
ret[lang] = i
return ret
def show_changes(a, b):
for lang, cur_rank in b.items():
old_rank = a.get(lang)
if not old_rank:
change = '*'
elif cur_rank < old_rank:
change = f'↑ {old_rank - cur_rank}'
elif cur_rank > old_rank:
change = f'↓ {cur_rank - old_rank}'
else:
change = '='
print('%30s %-4s' % (lang, change))
def main(filea, fileb):
a = get_rank(filea)
b = get_rank(fileb)
show_changes(a, b)
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])