Created
October 27, 2015 22:20
-
-
Save ryanlayer/7f10b2df09e83af97e25 to your computer and use it in GitHub Desktop.
Convert the spread sheet to an author list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import re | |
| from operator import itemgetter | |
| char_map = { '0': u'\u2070', \ | |
| '1': u'\u00B9', \ | |
| '2': u'\u00B2', \ | |
| '3': u'\u00B3', \ | |
| '4': u'\u2074', \ | |
| '5': u'\u2075', \ | |
| '6': u'\u2076', \ | |
| '7': u'\u2077', \ | |
| '8': u'\u2078', \ | |
| '9': u'\u2079' } | |
| def to_super(num): | |
| out = '' | |
| for c in str(num): | |
| out += char_map[c] | |
| return out | |
| start_affil = int(sys.argv[1]) | |
| affiliations = {} | |
| for l in open(sys.argv[2]): | |
| d = l.rstrip().split('\t') | |
| if d[0] == 'Code' or len(d) < 6: | |
| continue | |
| affiliations[d[0]] = (d[1] + ', ' if len(d[1]) > 0 else '') + \ | |
| (d[2]+ ', ' if len(d[2]) > 0 else '') + \ | |
| d[3] + ', ' + \ | |
| (d[4] + ', ' if len(d[4]) > 0 else '') + \ | |
| d[5] | |
| affil_order = {} | |
| authors = [] | |
| for l in open(sys.argv[3]): | |
| d = l.rstrip().split('\t') | |
| if d[0] == 'LastName' or len(d) < 5: | |
| continue | |
| author_affils = [] | |
| for author_affil in re.split(', ',d[4]): | |
| if not author_affil in affil_order: | |
| affil_order[author_affil] = len(affil_order) | |
| author_affils.append(str(affil_order[author_affil]+ start_affil)) | |
| authors.append( d[1] + ' ' + \ | |
| (d[2] + ' ' if len(d[2]) > 0 else '') + \ | |
| d[0] + \ | |
| ','.join(author_affils) ) | |
| print ', '.join(authors) | |
| affil_out = [] | |
| for a in affiliations: | |
| if a in affil_order: | |
| affil_out.append( [affil_order[a],affiliations[a]]) | |
| for affil in sorted(affil_out, key=itemgetter(0)): | |
| print affil[0]+start_affil,affil[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment