Skip to content

Commit 8e5e449

Browse files
committed
contributors.py: Compress years list into single string
1 parent 1ff9206 commit 8e5e449

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

scripts/contributors.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,44 @@
5353
print(" " + author)
5454
print('')
5555

56+
57+
def compress_years(years):
58+
"""
59+
Given a list of years like [2003, 2004, 2007],
60+
compress it into string like '2003-2004, 2007'
61+
"""
62+
years = sorted(years)
63+
# compress years into string
64+
comma = ', '
65+
yearstr = ''
66+
for i in range(0,len(years)-1):
67+
if years[i+1]-years[i] == 1:
68+
if not yearstr or yearstr.endswith(comma):
69+
yearstr += '%s' % years[i]
70+
if yearstr.endswith('-'):
71+
pass
72+
else:
73+
yearstr += '-'
74+
else:
75+
yearstr += '%s, ' % years[i]
76+
77+
if len(years) == 1:
78+
yearstr += str(years[0])
79+
else:
80+
yearstr += '%s' % years[-1]
81+
return yearstr
82+
83+
5684
if years_for_contributors:
5785
if verbose:
5886
print("Years for each contributor...")
5987
print('')
6088
for author in sorted(names):
61-
years = sorted(names[author])
62-
print(years, author)
89+
years = list(names[author])
90+
yearstr = compress_years(years)
91+
92+
if 1: #DEBUG
93+
print(years, yearstr, author)
94+
else:
95+
print(yearstr, author)
6396
print('')

0 commit comments

Comments
 (0)