Hi all!<br><br>After a few days I've created a python plugin for getting informatin from Isi-web of science<br><br>First of all, PYTHON IS AMAZING! Simple, powerful...I'm in love with python :-)<br><br>Here I attach you my plugin (to be placed in $HOME/.referencer/plugins) for referencer version 1.1.1<br>
<br>It can be improved in many ways. For instance if function getNumberOfRecords returns a value equal to zero, a warning window could be open with information about that. similarly, if it returns a number greater than 1, it would be highly interesting to obtain a window with all the possibilities and pick one with the mouse, but I don't know how to create a new window<br>
<br>Until next version, enjoy it!<br><br><br>#!/usr/bin/env python<br> <br># Get info from isi-web of science from title/author/year fields (any or all of them)<br># Mario Castro, 2008<br><br><br>import os<br>import referencer<br>
from referencer import _<br>import sys, urllib2, urllib<br><br>from xml.dom import minidom<br><br>referencer_plugin_info = []<br>referencer_plugin_info.append (["longname", _("Get info from ISI Web of Science")])<br>
referencer_plugin_info.append (["action", _("Get info from ISI Web")])<br>referencer_plugin_info.append (["tooltip", _("Get info from ISI Web of Science")])<br>referencer_plugin_capabilities = []<br>
referencer_plugin_capabilities.append ("document_action")<br><br><br>def get_fields (doc, field, separator):<br> value = doc.getElementsByTagName(field)<br> output=''<br> if len(value) == 0:<br>
return ""<br> else:<br> length=len(value)<br> if (len(value[0].childNodes) == 0):<br> return ""<br> else:<br> #for items in value:<br> for index in range(length-1):<br>
output+=value[index].childNodes[0].data.encode("utf-8")+separator<br> return output+value[length-1].childNodes[0].data.encode("utf-8")<br><br>def get_last_field (doc, field):<br>
value = doc.getElementsByTagName(field)<br> if len(value) == 0:<br> return ""<br> else:<br> if (len(value[0].childNodes) == 0):<br> return ""<br> else:<br> for items in value:<br>
last=items.childNodes[0].data.encode("utf-8")<br> return last<br><br>def get_field (doc, field):<br> value = doc.getElementsByTagName(field)<br> if len(value) == 0:<br> return ""<br>
else:<br> if (len(value[0].childNodes) == 0):<br> return ""<br> else:<br> return value[0].childNodes[0].data.encode("utf-8")<br><br><br>def get_attribute_from_field (doc, field, attr):<br>
value = doc.getElementsByTagName(field)<br> return value[0].getAttribute(attr)<br><br>def getNumberOfRecords (document):<br> title = document.get_field("title")<br> year = document.get_field ("year")<br>
author= document.get_field ("author")<br><br> ti=urllib.urlencode([('','('+title+')')])<br> ye=urllib.urlencode([('','('+year+')')])<br> au=urllib.urlencode([('','('+author+')')])<br>
<br> url0='<a href="http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&rspType=xml&method=search&firstRec=1&numRecs=1&query=TI'+ti+'&PY'+ye+'&AU'+au">http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&rspType=xml&method=search&firstRec=1&numRecs=1&query=TI'+ti+'&PY'+ye+'&AU'+au</a><br>
data0 = referencer.download (_("Obtaining data from ISI-WebOfScience"), _("Fetching number of ocurrences for %s/%s/%s") % (author,title,year), url0);<br> xmldoc0 = minidom.parseString(data0)<br>
recordsFound=get_field(xmldoc0,"recordsFound")<br> return recordsFound<br><br>def getAndSetFields(document):<br><br> title = document.get_field("title")<br> year = document.get_field ("year")<br>
author= document.get_field ("author")<br><br> page_orig=document.get_field("pages")<br> journal_orig=document.get_field("journal")<br> volume=document.get_field("volume")<br>
<br> ti=urllib.urlencode([('','('+title+')')])<br> ye=urllib.urlencode([('','('+year+')')])<br> au=urllib.urlencode([('','('+author+')')])<br>
<br> url='<a href="http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&SID=Q1mNFhCECOk6c8aELLh&rspType=xml&method=searchRetrieve&firstRec=1&numRecs=1&query=TI'+ti+'&PY'+ye+'&AU'+au">http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&SID=Q1mNFhCECOk6c8aELLh&rspType=xml&method=searchRetrieve&firstRec=1&numRecs=1&query=TI'+ti+'&PY'+ye+'&AU'+au</a><br>
data = referencer.download (_("Obtaining data from ISI-WebOfScience"), _("Fetching data for %s/%s/%s") % (author,title,year), url);<br> xmldoc = minidom.parseString(data)<br> authors=get_field(xmldoc,"primaryauthor")<br>
more_authors=get_fields(xmldoc,"author",' and ')<br> if(len(more_authors)>0):<br> authors+=' and '+more_authors<br> abstract=get_field(xmldoc,"p")<br> keywords=get_fields(xmldoc,"keyword",', ')<br>
journal=get_field(xmldoc,"source_title")<br> doi=get_last_field(xmldoc,"article_no")<br> pages=get_field(xmldoc,"bib_pages")<br> title_isi=get_field(xmldoc,"item_title")<br>
year_isi=get_attribute_from_field(xmldoc,"bib_issue","year")<br> volume_isi=get_attribute_from_field(xmldoc,"bib_issue","vol")<br><br> if (len(year)==0 and len(year_isi)>0):<br>
document.set_field("year",year_isi)<br> if (len(volume)==0 and len(volume_isi)>0):<br> document.set_field("volume",volume_isi)<br> if (len(title)>0):<br> document.set_field("title",title_isi)<br>
if (len(authors)>0):<br> document.set_field("author",authors)<br> if (len(doi)>0):<br> document.set_field("doi",doi)<br> if (len(journal_orig)==0 and len(journal)>0):<br>
document.set_field("journal",journal)<br> if (len(page_orig)<len(pages) and pages!='-'):<br> document.set_field("pages",pages)<br> if (len(abstract)>0):<br> document.set_field("abstract",abstract)<br>
if (len(keywords)>0):<br> document.set_field("keywords",keywords)<br><br>def do_action (documents):<br> empty = True<br> s = ""<br> assigned_keys = {}<br> for document in documents:<br>
rec=getNumberOfRecords(document)<br> if (rec=='1'):<br> getAndSetFields(document)<br> <br> return True<br><br><br><br>