Ejemplo n.º 1
0
    def orcid_author_search_parser(author_name):
        """
        Method to parse the list of matching authors from ORCID website into an array object, given the name of the author
        """

        out_file = "data/orcid_author_search.xml"
        fout = open(out_file, "w")
        print >> fout, ORCID.orcid_author_search(author_name,
                                                 kind="xml").encode('utf-8')
        fout.close()

        tree = ET.parse(out_file)
        root_element = tree.getroot()
        ns = '{http://www.orcid.org/ns/orcid}'

        authors = []

        for child1 in root_element:
            if (child1.tag == ns + 'orcid-search-results'):
                for child2 in child1:
                    if (child2.tag == ns + 'orcid-search-result'):
                        author = {'othernames': []}
                        for child3 in child2:
                            if (child3.tag == ns + 'orcid-profile'):
                                for child4 in child3:
                                    if (child4.tag == ns + 'orcid-identifier'):
                                        for child5 in child4:
                                            if (child5.tag == ns + 'path'):
                                                author['orcid'] = child5.text
                                    elif (child4.tag == ns + 'orcid-bio'):
                                        for child5 in child4:
                                            if (child5.tag == ns +
                                                    'personal-details'):
                                                for child6 in child5:
                                                    if (child6.tag == ns +
                                                            'given-names'):
                                                        author[
                                                            'firstname'] = child6.text
                                                    elif (child6.tag == ns +
                                                          'family-name'):
                                                        author[
                                                            'lastname'] = child6.text
                                                    elif (child6.tag == ns +
                                                          'other-names'):
                                                        for child7 in child6:
                                                            if (child7.tag ==
                                                                    ns +
                                                                    'other-name'
                                                                ):
                                                                author[
                                                                    'othernames'].append(
                                                                        child7.
                                                                        text)

                        author = ORCID_Parser.generate_author_other_names(
                            author)
                        authors.append(author)

        return authors
Ejemplo n.º 2
0
 def orcid_author_search_parser(author_name):
     """
     Method to parse the list of matching authors from ORCID website into an array object, given the name of the author
     """
     
     out_file = "data/orcid_author_search.xml"
     fout = open(out_file, "w")
     print >> fout, ORCID.orcid_author_search(author_name, kind="xml").encode('utf-8')
     fout.close()
     
     tree = ET.parse(out_file)
     root_element = tree.getroot()
     ns = '{http://www.orcid.org/ns/orcid}'
     
     authors = []
     
     for child1 in root_element:
         if(child1.tag == ns + 'orcid-search-results'):
             for child2 in child1:
                 if(child2.tag == ns + 'orcid-search-result'):
                     author = {'othernames': []}
                     for child3 in child2:
                         if(child3.tag == ns + 'orcid-profile'):
                             for child4 in child3:
                                 if(child4.tag == ns + 'orcid-identifier'):
                                     for child5 in child4:
                                         if(child5.tag == ns + 'path'):
                                             author['orcid'] = child5.text
                                 elif(child4.tag == ns + 'orcid-bio'):
                                     for child5 in child4:
                                         if(child5.tag == ns + 'personal-details'):
                                             for child6 in child5:
                                                 if(child6.tag == ns + 'given-names'):
                                                     author['firstname'] = child6.text
                                                 elif(child6.tag == ns + 'family-name'):
                                                     author['lastname'] = child6.text
                                                 elif(child6.tag == ns + 'other-names'):
                                                     for child7 in child6:
                                                         if(child7.tag == ns + 'other-name'):
                                                             author['othernames'].append(child7.text)
                     
                     author = ORCID_Parser.generate_author_other_names(author)
                     authors.append(author)
     
     return authors
from lookup.ORCID import ORCID
import json

fout = open("orcid_author_details_by_name.txt", "w")

def banner(msg):
    print >> fout, 70 * "="
    print >> fout, msg
    print >> fout, 70 * "=" 
    
banner("orcid author details xml")
print >> fout, ORCID.orcid_author_search("gregor von laszewski", kind="xml").encode('utf-8')

banner("orcid author details json")
print >> fout, json.dumps(ORCID.orcid_author_search("gregor von laszewski", kind="json"), indent=2).encode('utf-8')