Esempio n. 1
0
 def test_pmid(self):
     """
     Make sure the ILL url has the pubmed ID in the notes field.
     """
     ourl = 'rft.eissn=1531-6564&rft.aulast=Schlenker&rft.au=Schlenker%2C+J+D&rft.atitle=Three+complications+of+untreated+partial+laceration+of+flexor+tendon--entrapment%2C+rupture%2C+and+triggering&rft.volume=6&rft.jtitle=The+Journal+of+hand+surgery+%28American+ed.%29&rft.aufirst=J&rft.date=1981-07&rft.auinitm=D&rft.spage=392&rft.issue=4&pmid=7252116&rft_id=info%3Apmid%2F7252116&rft.issn=0363-5023&url_ver=Z39.88-2004&version=1.0&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.genre=article'
     ill = make_illiad_url(ourl)
     ill_dict = urlparse.parse_qs(ill)
     note = ill_dict['Notes'][0]
     self.assertTrue(note.rfind('7252116') > -1)
Esempio n. 2
0
 def test_date(self):
     """ Checks that raw dates are returned.
         See delivery.utils.illiad_date() for policy. """
     orig_ourl = 'rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.auinitm=D&rft.spage=392&rft.au=Schlenker%2C+J+D&rft.aulast=Schlenker&sid=bul_easy_article&rft_id=info%3Apmid%2F7252116&rft.date=1981-07&rft.issn=0363-5023&rft.aufirst=J&rft.volume=6&version=1.0&url_ver=Z39.88-2004&rft.atitle=Three+complications+of+untreated+partial+laceration+of+flexor+tendon--entrapment%2C+rupture%2C+and+triggering&rft.eissn=1531-6564&pmid=7252116&rft.jtitle=The+Journal+of+hand+surgery+%28American+ed.%29&rft.issue=4&rft.genre=article'
     ill_ourl = make_illiad_url( orig_ourl )
     # ilog.debug( 'ill_ourl, `%s`' % ill_ourl )
     ill_ourl_dct = urlparse.parse_qs( ill_ourl )  # all dct values are lists
     # ilog.debug( 'ill_ourl_dct, `%s`' % pprint.pformat(ill_ourl_dct) )
     date = ill_ourl_dct['rft.date'][0]
     self.assertEqual( '1981-07', date )
Esempio n. 3
0
 def test_referrer(self):
     ourl = 'rft_id%3Dinfo%253Adoi%252F10.1603%252F0022-2585-38.3.446%26rft.atitle%3DToxic%2BEffect%2Bof%2BGarlic%2BExtracts%2Bon%2Bthe%2BEggs%2Bof%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2528Diptera%253A%2BCulicidae%2529%253A%2BA%2BScanning%2BElectron%2BMicroscopic%2BStudy%26rft.issue%3D3%26rft.aulast%3DJarial%26rft.volume%3D38%26rft.jtitle%3DJournal%2Bof%2Bmedical%2Bentomology%26rft.aufirst%3DMohinder%26rft.date%3D2001-05%26rft.auinitm%3DS.%26rft.eissn%3D1938-2928%26rft.au%3DJarial%252C%2BMohinder%2BS.%26rft.spage%3D446%26rft.issn%3D0022-2585%26url_ver%3DZ39.88-2004%26version%3D1.0%26rft_val_fmt%3Dinfo%253Aofi%252Ffmt%253Akev%253Amtx%253Ajournal%26rft.genre%3Darticle'
     #with pmid
     ourl = 'rft.issn%3D0742-2822%26rft.au%3DDalby%20Kristensen%2C%20Steen%26rft.aulast%3DDalby%20Kristensen%26rft.volume%3D13%26rft.jtitle%3DEchocardiography%20(Mount%20Kisco%2C%20N.Y.)%26rft.aufirst%3DSteen%26rft.date%3D1996-07%26rft.atitle%3DRupture%20of%20Aortic%20Dissection%20During%20Attempted%20Transesophageal%20Echocardiography%26pmid%3D11442947%26rft_id%3Dinfo%3Apmid%2F11442947%26rft.eissn%3D1540-8175%26rft.issue%3D4%26rft.spage%3D405%26url_ver%3DZ39.88-2004%26version%3D1.0%26rft_val_fmt%3Dinfo%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal%26rft.genre%3Darticle'
     #dvd from oclc
     ourl = 'sid=FirstSearch:WorldCat&title=Einstein on the beach&date=1993&aulast=Glass&aufirst=Philip&id=doi:&pid=<accession number>29050194</accession number><fssessid>0</fssessid>&url_ver=Z39.88-2004&rfr_id=info:sid/firstsearch.oclc.org:WorldCat&rft_val_fmt=info:ofi/fmt:kev:mtx:book&req_dat=<sessionid>0</sessionid>&rfe_dat=<accessionnumber>29050194</accessionnumber>&rft_id=info:oclcnum/29050194&rft.aulast=Glass&rft.aufirst=Philip&rft.title=Einstein on the beach&rft.date=1993&rft.aucorp=Philip Glass Ensemble.&rft.place=New York, NY :&rft.pub=Elektra Nonesuch,&rft.genre=unknown'
     ourl = 'rfr_id%3DFirstSearch%253AWorldCat%26isbn%3D9780767853569%26title%3DA%2Bfew%2Bgood%2Bmen%26date%3D2001%26aulast%3DReiner%26aufirst%3DRob%26id%3Ddoi%253A%26pid%3D%253Caccession%2Bnumber%253E47247051%253C%252Faccession%2Bnumber%253E%253Cfssessid%253E0%253C%252Ffssessid%253E%26url_ver%3DZ39.88-2004%26rfr_id%3Dinfo%253Asid%252Ffirstsearch.oclc.org%253AWorldCat%26rft_val_fmt%3Dinfo%253Aofi%252Ffmt%253Akev%253Amtx%253Abook%26req_dat%3D%253Csessionid%253E0%253C%252Fsessionid%253E%26rfe_dat%3D%253Caccessionnumber%253E47247051%253C%252Faccessionnumber%253E%26rft_id%3Dinfo%253Aoclcnum%252F47247051%26rft_id%3Durn%253AISBN%253A9780767853569%26rft.aulast%3DReiner%26rft.aufirst%3DRob%26rft.title%3DA%2Bfew%2Bgood%2Bmen%26rft.date%3D2001%26rft.isbn%3D9780767853569%26rft.aucorp%3DColumbia%2BPictures.%253BCastle%2BRock%2BEntertainment%2B%2528Firm%2529%253BColumbia%2BTriStar%2BHome%2BVideo%2B%2528Firm%2529%26rft.place%3DCulver%2BCity%252C%2BCA%2B%253A%26rft.pub%3DColumbia%2BTriStar%2BHome%2BVideo%252C%26rft.genre%3Dunknown%26checksum%3D065b7cc8e6abf86e89b5639ee3939c09&title=Brown+University&linktype=openurl&detail=RBN'
     ill = make_illiad_url(ourl)
     ill_dict = urlparse.parse_qs(ill)
     #pprint(ill_dict)
     self.assertTrue('FirstSearch:WorldCat' in ill_dict['sid'])
    def handle(self, **options):
        from findit.models import Request
        count = 0
        new_requests = Request.objects.filter(illiad_tn='new')
        for request in new_requests:
            user = request.user
            profile = user.libraryprofile
            illiad_profile = profile.illiad()
            tries = 0
            while tries < 3:
                try:
                    sersol = get_sersol_data(request.item.query, key=sersol_key)
                    break
                except urllib2.URLError:
                    print>>sys.stderr, "360Link timeout.  Trying again."
                    tries += 1
            resolved = Resolved(sersol)
            illiad_request_url = "%s&sid=%s" % (make_illiad_url(resolved.openurl), request.item.referrer)
            #print bib
            #print illiad_request_url
            #print illiad_request_url
            ill_username = illiad_profile['username']
            #Get the OpenURL we will submit.
            ill_url = illiad_request_url
            ilog.info('User %s posted %s for request.' % (ill_username,
                                                           ill_url))
            out = {}
            #Get an illiad instance
            illiad = IlliadSession(ILLIAD_REMOTE_AUTH_URL,
                                   ILLIAD_REMOTE_AUTH_HEADER,
                                   ill_username)
            illiad_session = illiad.login()
            ilog.info('User %s established Illiad session: %s.' % (ill_username,
                                                                  illiad_session['session_id']))
            out['session'] = illiad_session

            if not illiad_session['authenticated']:
                out['session_error'] = 'Failed login.'
                ilog.error("Illiad login failed for %s" % ill_username)
            else:
                #Register users if neccessary.
                if not illiad.registered:
                    ilog.info('Will register %s with illiad.' % (ill_username))
                    ilog.info('Registering %s with Illiad as %s.' % (ill_username,
                                                                     illiad_profile['status'])
                              )
                    reg = illiad.register_user(illiad_profile)
                    ilog.info('%s registration response: %s' % (ill_username, reg))

                illiad_post_key = illiad.get_request_key(ill_url)
                #If blocked comes back in the post key, stop here with appropriate status.
                blocked = illiad_post_key.get('blocked', None)
                errors = illiad_post_key.get('errors', None)
                if blocked:
                    out['blocked'] = blocked
                    ilog.info("%s is blocked in Illiad." % ill_username)
                    self.send_message('blocked', resource=resource)
                elif errors:
                    out['errors'] = True
                    msg = illiad_post_key['message']
                    ilog.info("Request errors during Illiad submission: %s %s" %\
                                (ill_username,
                                 self.msg))
                    out['message'] = msg
                else:
                    #Submit this
                    submit_status = illiad.make_request(illiad_post_key)
                    out['submit_status'] = submit_status
                    #Write the request to the requests table.
                    if submit_status['submitted']:
                        illiad_tn = submit_status['transaction_number']
                        request.illiad_tn = illiad_tn
                        print request.user, request.id, request.item.id, illiad_tn
                        request.save()
                        count += 1
                    else:
                        ilog.error("%s request failed with message %s." %\
                                   (ill_username,
                                   submit_status['message']))

            illiad.logout()