def parse_file(filename): """ parse a file and create a set of authors :param filename: file to parse :return: set of author elements """ authors = set() firstline = True # ignore the first line with open(filename, 'r') as f: for l in f: if firstline: firstline = False continue p = l.rstrip().split("\t") if len(p) < 15: sys.stderr.write("ERROR: Malformed: {}\t{}\n".format(len(p), p)) continue auth = Author(p[2]) try: if p[1]: auth.orcid = p[1] if p[3]: auth.lastname = p[3] auth.lastnamelower = p[3].lower() if p[4]: auth.firstname = p[4] auth.firstnamelower = p[4].lower() if p[5]: auth.middleinitial = p[5] if p[6]: auth.email = p[6].replace(' ', '') if p[14]: auth.order = int(p[14]) if p[15]: auth.contribution = p[15] primary = Address() if p[7]: primary.department = p[7] if p[8]: primary.institution = p[8] if p[9]: primary.street = p[9] if p[10]: primary.city = p[10] if p[11]: primary.state = p[11] if p[12]: primary.zip = p[12] if p[13]: primary.country = p[13] auth.primaryaddress = primary secondary = Address() if len(p) > 17 and p[17]: secondary.department = p[17] if len(p) > 18 and p[18]: secondary.institution = p[18] if len(p) > 19 and p[19]: secondary.street = p[19] if len(p) > 20 and p[20]: secondary.city = p[20] if len(p) > 21 and p[21]: secondary.state = p[21] if len(p) > 22 and p[22]: secondary.zip = p[22] if len(p) > 23 and p[23]: secondary.country = p[23] if secondary.is_valid(): auth.secondaryaddress = secondary except Exception as err: sys.stderr.write("Error parsing {}: {}\n".format(p[2], err)) continue authors.add(auth) return authors
def parse_file(filename): """ parse a file and create a set of authors :param filename: file to parse :return: set of author elements """ authors = set() firstline = True # ignore the first line with open(filename, 'r') as f: for l in f: if firstline: firstline = False continue p = l.rstrip().split("\t") if len(p) < 15: sys.stderr.write("ERROR: Malformed: {}\t{}\n".format( len(p), p)) continue auth = Author(p[2]) try: if p[1]: auth.orcid = p[1] if p[3]: auth.lastname = p[3] auth.lastnamelower = p[3].lower() if p[4]: auth.firstname = p[4] auth.firstnamelower = p[4].lower() if p[5]: auth.middleinitial = p[5] if p[6]: auth.email = p[6].replace(' ', '') if p[14]: auth.order = int(p[14]) if p[15]: auth.contribution = p[15] primary = Address() if p[7]: primary.department = p[7] if p[8]: primary.institution = p[8] if p[9]: primary.street = p[9] if p[10]: primary.city = p[10] if p[11]: primary.state = p[11] if p[12]: primary.zip = p[12] if p[13]: primary.country = p[13] auth.primaryaddress = primary secondary = Address() if len(p) > 17 and p[17]: secondary.department = p[17] if len(p) > 18 and p[18]: secondary.institution = p[18] if len(p) > 19 and p[19]: secondary.street = p[19] if len(p) > 20 and p[20]: secondary.city = p[20] if len(p) > 21 and p[21]: secondary.state = p[21] if len(p) > 22 and p[22]: secondary.zip = p[22] if len(p) > 23 and p[23]: secondary.country = p[23] if secondary.is_valid(): auth.secondaryaddress = secondary except Exception as err: sys.stderr.write("Error parsing {}: {}\n".format(p[2], err)) continue authors.add(auth) return authors