77from fuzzywuzzy import fuzz , process
88import subprocess as sp
99
10- CREATORS_LAST_ORCID = '0000-0002-5312-6729' # This ORCID should go last
10+ # These ORCIDs should go last
11+ CREATORS_LAST_ORCIDS = ['0000-0002-5312-6729' , '0000-0003-3321-7583' ]
1112# for entries not found in line-contributions
1213MISSING_ENTRIES = [
1314 {"name" : "Varada, Jan" },
3031 {"name" : "Lai, Jeff" }
3132]
3233
33-
34- def fix_position (creators ):
35- """Place Satra last."""
36- # position first / last authors
37- l_authr = None
38-
39- for info in creators :
40- if 'orcid' in info and info ['orcid' ] == CREATORS_LAST_ORCID :
41- l_authr = info
42-
43- if l_authr is None :
44- raise AttributeError ('Missing important people' )
45-
46- creators .remove (l_authr )
47- creators .append (l_authr )
48- return creators
49-
50-
5134if __name__ == '__main__' :
5235 contrib_file = Path ('line-contributors.txt' )
5336 lines = []
@@ -71,8 +54,10 @@ def fix_position(creators):
7154 zenodo = json .loads (zenodo_file .read_text ())
7255 zen_names = [' ' .join (val ['name' ].split (',' )[::- 1 ]).strip ()
7356 for val in zenodo ['creators' ]]
57+ total_names = len (zen_names ) + len (MISSING_ENTRIES )
7458
7559 name_matches = []
60+ position = 1
7661 for ele in data :
7762 matches = process .extract (ele , zen_names , scorer = fuzz .token_sort_ratio ,
7863 limit = 2 )
@@ -85,10 +70,22 @@ def fix_position(creators):
8570 continue
8671
8772 if val not in name_matches :
73+ if 'orcid' not in val or val ['orcid' ] not in CREATORS_LAST_ORCIDS :
74+ val ['position' ] = position
75+ position += 1
76+ else :
77+ val ['position' ] = total_names + list (reversed (
78+ CREATORS_LAST_ORCIDS )).index (val ['orcid' ])
8879 name_matches .append (val )
8980
90- for entry in MISSING_ENTRIES :
91- name_matches .append (entry )
81+ for missing in MISSING_ENTRIES :
82+ missing ['position' ] = position
83+ position += 1
84+ name_matches .append (missing )
85+
86+ zenodo ['creators' ] = sorted (name_matches , key = lambda k : k ['position' ])
87+ # Remove position
88+ for creator in zenodo ['creators' ]:
89+ del creator ['position' ]
9290
93- zenodo ['creators' ] = fix_position (name_matches )
94- zenodo_file .write_text (json .dumps (zenodo , indent = 2 , sort_keys = True ))
91+ zenodo_file .write_text ('%s\n ' % json .dumps (zenodo , indent = 2 , sort_keys = True ))
0 commit comments