#! /usr/bin/env python2.7 """ TeX authors affiliations aggregation script Script accepts input files in the following format: Oleg ; EPFL Andrew ; Leiden Andrew ; Kiev Alexey ; Leiden Alexey ; EPFL Alexey ; MIT And produces the output in stdout: \author[1]{Oleg} \author[2,3]{Andrew} \author[2,1,4]{Alexey} \affiliation[1]{EPFL} \affiliation[2]{Leiden} \affiliation[3]{Kiev} \affiliation[4]{MIT} Empty lines are skipped, malformed lines are reported without interruption. """ __author__ = "Andrii Magalich" __version__ = "1.0" __date__ = "17th Dec 2014" if __name__ == '__main__': import sys from collections import defaultdict if len(sys.argv) == 1: input_file = "authors.csv" else: input_file = sys.argv[1] output_file = "ship_authors.tex" input = open(input_file, 'r').read() lines = input.split("\n") authors_order = [] authors = defaultdict(lambda: []) affiliations = [] for line in lines: if not line: continue try: author, affiliation = line.split(";") except ValueError: print("////Error processing line:\n {}".format(line)) else: author = author.strip() affiliation = affiliation.strip() if not affiliation in affiliations: affiliations.append(affiliation) if not author in authors_order: authors_order.append(author) authors[author].append(str(affiliations.index(affiliation)+1)) print("-"*80) for author in authors_order: print("\\author[{}]{{{},}}".format(",".join(authors[author]), author)) print("") for i, affiliation in enumerate(affiliations): print("\\affiliation[{}]{{{}}}".format(i+1, affiliation))