# $Id: openurl.sf 4091 2010-12-05 22:18:15Z place $ # $URL: https://svn.non-gnu.uvt.nl/uvt-dev/trunk/sources/meresco/bzv/html/dynamic/openurl.sf $ import search def main(headers={}, arguments={}, *args, **kwargs): openurl = '' if 'url_ver' in arguments and arguments.get('url_ver')[0] == "Z39.88-2004": if 'rft.atitle' in arguments: arguments['atitle'] = arguments['rft.atitle'] openurl += "atitle=" + arguments['atitle'][0] + "&" if 'rft.btitle' in arguments: arguments['title'] = arguments['rft.btitle'] openurl += "title=" + arguments['title'][0] + "&" elif 'rft.jtitle' in arguments: arguments['title'] = arguments['rft.jtitle'] openurl += "title=" + arguments['title'][0] + "&" elif 'rft.title' in arguments: arguments['title'] = arguments['rft.title'] openurl += "title=" + arguments['title'][0] + "&" if 'rft.genre' in arguments: arguments['genre'] = arguments['rft.genre'] openurl += "genre=" + arguments['genre'][0] + "&" elif 'rft_val_fmt' in arguments: genre = arguments['rft_val_fmt'][0].split(':')[-1:] if genre == "journal": genre = "article" arguments['genre'] = genre openurl += "genre=" + arguments['genre'][0] + "&" if 'rft.au' in arguments: arguments['au'] = arguments['rft.au'] au = arguments['au'][0] arguments['aulast'] = [au.split(',')[0]] arguments['aufirst'] = [au.split(',')[1]] openurl += "aulast=" + arguments['aulast'][0] + "&" openurl += "aufirst=" + arguments['aufirst'][0] + "&" if 'rft.volume' in arguments: arguments['volume'] = arguments['rft.volume'] openurl += "volume=" + arguments['volume'][0] + "&" if 'rft.issue' in arguments: arguments['issue'] = arguments['rft.issue'] openurl += "issue=" + arguments['issue'][0] + "&" if 'rft.date' in arguments: arguments['date'] = arguments['rft.date'] openurl += "date=" + arguments['date'][0] + "&" if 'rft.spage' in arguments: arguments['spage'] = arguments['rft.spage'] openurl += "spage=" + arguments['spage'][0] + "&" if 'rft.epage' in arguments: arguments['epage'] = arguments['rft.epage'] openurl += "epage=" + arguments['epage'][0] + "&" if 'rft.issn' in arguments: arguments['issn'] = arguments['rft.issn'] openurl += "issn=" + arguments['issn'][0] + "&" if 'rft.isbn' in arguments: arguments['isbn'] = arguments['rft.isbn'] openurl += "isbn=" + arguments['isbn'][0] + "&" else: openurl = kwargs['RequestURI'].split('?')[1] matches = re.match('(^.*?date=).*?(\d\d\d\d)[^&]*(.*)', openurl) if matches: openurl = matches.group(1) + matches.group(2) + matches.group(3) arguments['openurl'] = openurl if 'query' not in arguments: if 'genre' in arguments and arguments['genre'][0] == "bookitem": query = '' if 'atitle' in arguments: query = arguments['atitle'][0].replace(':', ' ') if 'title' in arguments: if query: query = '''"%s" or "%s"''' %(query, arguments['title'][0].replace(':', ' ')) else: query = arguments['title'][0].replace(':', ' ') if query: arguments['query'] = [query] if 'query' not in arguments: if 'atitle' in arguments: arguments['query'] = [arguments['atitle'][0].replace(':', ' ')] elif 'title' in arguments: arguments['query'] = [arguments['title'][0].replace(':', ' ')] elif 'issn' in arguments: arguments['query'] = [arguments['issn'][0].replace('-', '')] elif 'isbn' in arguments: arguments['query'] = arguments['isbn'] if 'sortKeys' not in arguments: arguments['sortKeys'] = [',,'] arguments['queryisforresolver'] = [''] yield search.main(headers=headers, arguments=arguments, *args, **kwargs)