Esempio n. 1
0
    def orcid_author_get_parser(orcid):
        """
        Method to parse the author details from ORCID website into a dictionary object, given the orcid of the author
        """

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

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

        author = {'othernames': [], 'urls': [], 'identifiers': []}

        for child1 in root_element:
            if (child1.tag == ns + 'orcid-profile'):
                for child2 in child1:
                    if (child2.tag == ns + 'orcid-identifier'):
                        for child3 in child2:
                            if (child3.tag == ns + 'path'):
                                author['orcid'] = child3.text
                    elif (child2.tag == ns + 'orcid-bio'):
                        for child3 in child2:
                            if (child3.tag == ns + 'personal-details'):
                                for child4 in child3:
                                    if (child4.tag == ns + 'given-names'):
                                        author['firstname'] = child4.text
                                    elif (child4.tag == ns + 'family-name'):
                                        author['lastname'] = child4.text
                                    elif (child4.tag == ns + 'other-names'):
                                        for child5 in child4:
                                            if (child5.tag == ns +
                                                    'other-name'):
                                                author['othernames'].append(
                                                    child5.text)
                            elif (child3.tag == ns + 'researcher-urls'):
                                for child4 in child3:
                                    if (child4.tag == ns + 'researcher-url'):
                                        for child5 in child4:
                                            if (child5.tag == ns + 'url'):
                                                author['urls'].append(
                                                    child5.text)
                            elif (child3.tag == ns + 'contact-details'):
                                for child4 in child3:
                                    if (child4.tag == ns + 'email'):
                                        author['email'] = child4.text
                            elif (child3.tag == ns + 'external-identifiers'):
                                for child4 in child3:
                                    if (child4.tag == ns +
                                            'external-identifier'):
                                        identifier = {}
                                        for child5 in child4:
                                            if (child5.tag == ns +
                                                    'external-id-common-name'):
                                                key = None
                                                if (child5.text ==
                                                        'ResearcherID'):
                                                    key = 'ResearcherID'
                                                elif (child5.text ==
                                                      'Scopus Author ID'):
                                                    key = 'ScopusID'
                                            elif (child5.tag == ns +
                                                  'external-id-reference'):
                                                value = child5.text
                                        if key is not None:
                                            identifier[key] = value
                                        author['identifiers'].append(
                                            identifier)

        return author
from lookup.ORCID import ORCID
import json

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

def banner(msg):
    print >> fout, 70 * "="
    print >> fout, msg
    print >> fout, 70 * "=" 
    
banner("orcid author details xml")
print >> fout, ORCID.orcid_author_get("0000-0001-9558-179X", kind="xml").encode('utf-8')

banner("orcid author details json")
print >> fout, json.dumps(ORCID.orcid_author_get("0000-0001-9558-179X", kind="json"), indent=2).encode('utf-8')

banner("orcid author works xml")
print >> fout, ORCID.orcid_author_works_get("0000-0001-9558-179X", kind="xml").encode('utf-8')

banner("orcid author works json")
print >> fout, json.dumps(ORCID.orcid_author_works_get("0000-0001-9558-179X", kind="json"), indent=2).encode('utf-8')
Esempio n. 3
0
 def orcid_author_get_parser(orcid):
     """
     Method to parse the author details from ORCID website into a dictionary object, given the orcid of the author
     """
     
     out_file = "data/orcid_author_get.xml"
     fout = open(out_file, "w")
     print >> fout, ORCID.orcid_author_get(orcid, kind="xml").encode('utf-8')
     fout.close()
     
     tree = ET.parse(out_file)
     root_element = tree.getroot()
     ns = '{http://www.orcid.org/ns/orcid}'
     
     author = {'othernames': [], 'urls': [], 'identifiers': []}
     
     for child1 in root_element:
         if(child1.tag == ns + 'orcid-profile'):
             for child2 in child1:
                 if(child2.tag == ns + 'orcid-identifier'):
                     for child3 in child2:
                         if(child3.tag == ns + 'path'):
                             author['orcid'] = child3.text
                 elif(child2.tag == ns + 'orcid-bio'):
                     for child3 in child2:
                         if(child3.tag == ns + 'personal-details'):
                             for child4 in child3:
                                 if(child4.tag == ns + 'given-names'):
                                     author['firstname'] = child4.text
                                 elif(child4.tag == ns + 'family-name'):
                                     author['lastname'] = child4.text
                                 elif(child4.tag == ns + 'other-names'):
                                     for child5 in child4:
                                         if(child5.tag == ns + 'other-name'):
                                             author['othernames'].append(child5.text)
                         elif(child3.tag == ns + 'researcher-urls'):
                             for child4 in child3:
                                 if(child4.tag == ns + 'researcher-url'):
                                     for child5 in child4:
                                         if(child5.tag == ns + 'url'):
                                             author['urls'].append(child5.text)
                         elif(child3.tag == ns + 'contact-details'):
                             for child4 in child3:
                                 if(child4.tag == ns + 'email'):
                                     author['email'] = child4.text
                         elif(child3.tag == ns + 'external-identifiers'):
                             for child4 in child3:
                                 if(child4.tag == ns + 'external-identifier'):
                                     identifier = {}
                                     for child5 in child4:
                                         if(child5.tag == ns + 'external-id-common-name'):
                                             key = None
                                             if(child5.text == 'ResearcherID'):
                                                 key = 'ResearcherID'
                                             elif(child5.text == 'Scopus Author ID'):
                                                 key = 'ScopusID'
                                         elif(child5.tag == ns + 'external-id-reference'):
                                             value = child5.text
                                     if key is not None:
                                         identifier[key] = value
                                     author['identifiers'].append(identifier)
     
     return author