Hi all!<br><br>After a few days I&#39;ve created a python plugin for getting informatin from Isi-web of science<br><br>First of all, PYTHON IS AMAZING! Simple, powerful...I&#39;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&#39;t know how to create a new window<br>
<br>Until next version, enjoy it!<br><br><br>#!/usr/bin/env python<br>&nbsp;<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 ([&quot;longname&quot;, _(&quot;Get info from ISI Web of Science&quot;)])<br>
referencer_plugin_info.append ([&quot;action&quot;, _(&quot;Get info from ISI Web&quot;)])<br>referencer_plugin_info.append ([&quot;tooltip&quot;, _(&quot;Get info from ISI Web of Science&quot;)])<br>referencer_plugin_capabilities = []<br>
referencer_plugin_capabilities.append (&quot;document_action&quot;)<br><br><br>def get_fields (doc, field, separator):<br>&nbsp;&nbsp;&nbsp; value = doc.getElementsByTagName(field)<br>&nbsp;&nbsp;&nbsp; output=&#39;&#39;<br>&nbsp;&nbsp;&nbsp; if len(value) == 0:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; length=len(value)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (len(value[0].childNodes) == 0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; #for items in value:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for index in range(length-1):<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; output+=value[index].childNodes[0].data.encode(&quot;utf-8&quot;)+separator<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return output+value[length-1].childNodes[0].data.encode(&quot;utf-8&quot;)<br><br>def get_last_field (doc, field):<br>
&nbsp;&nbsp;&nbsp; value = doc.getElementsByTagName(field)<br>&nbsp;&nbsp;&nbsp; if len(value) == 0:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (len(value[0].childNodes) == 0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for items in value:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; last=items.childNodes[0].data.encode(&quot;utf-8&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return last<br><br>def get_field (doc, field):<br>&nbsp;&nbsp;&nbsp; value = doc.getElementsByTagName(field)<br>&nbsp;&nbsp;&nbsp; if len(value) == 0:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>
&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (len(value[0].childNodes) == 0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return &quot;&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return value[0].childNodes[0].data.encode(&quot;utf-8&quot;)<br><br><br>def get_attribute_from_field (doc, field, attr):<br>
&nbsp;&nbsp;&nbsp; value = doc.getElementsByTagName(field)<br>&nbsp;&nbsp;&nbsp; return value[0].getAttribute(attr)<br><br>def getNumberOfRecords (document):<br>&nbsp;&nbsp;&nbsp; title = document.get_field(&quot;title&quot;)<br>&nbsp;&nbsp;&nbsp; year = document.get_field (&quot;year&quot;)<br>
&nbsp;&nbsp;&nbsp; author= document.get_field (&quot;author&quot;)<br><br>&nbsp;&nbsp;&nbsp; ti=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+title+&#39;)&#39;)])<br>&nbsp;&nbsp;&nbsp; ye=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+year+&#39;)&#39;)])<br>&nbsp;&nbsp;&nbsp; au=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+author+&#39;)&#39;)])<br>
<br>&nbsp;&nbsp;&nbsp; url0=&#39;<a href="http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&amp;rspType=xml&amp;method=search&amp;firstRec=1&amp;numRecs=1&amp;query=TI&#39;+ti+&#39;&amp;PY&#39;+ye+&#39;&amp;AU&#39;+au">http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&amp;rspType=xml&amp;method=search&amp;firstRec=1&amp;numRecs=1&amp;query=TI&#39;+ti+&#39;&amp;PY&#39;+ye+&#39;&amp;AU&#39;+au</a><br>
&nbsp;&nbsp;&nbsp; data0 = referencer.download (_(&quot;Obtaining data from ISI-WebOfScience&quot;), _(&quot;Fetching number of ocurrences for %s/%s/%s&quot;) % (author,title,year), url0);<br>&nbsp;&nbsp;&nbsp; xmldoc0 = minidom.parseString(data0)<br>
&nbsp;&nbsp;&nbsp; recordsFound=get_field(xmldoc0,&quot;recordsFound&quot;)<br>&nbsp;&nbsp;&nbsp; return recordsFound<br><br>def getAndSetFields(document):<br><br>&nbsp;&nbsp;&nbsp; title = document.get_field(&quot;title&quot;)<br>&nbsp;&nbsp;&nbsp; year = document.get_field (&quot;year&quot;)<br>
&nbsp;&nbsp;&nbsp; author= document.get_field (&quot;author&quot;)<br><br>&nbsp;&nbsp;&nbsp; page_orig=document.get_field(&quot;pages&quot;)<br>&nbsp;&nbsp;&nbsp; journal_orig=document.get_field(&quot;journal&quot;)<br>&nbsp;&nbsp;&nbsp; volume=document.get_field(&quot;volume&quot;)<br>
<br>&nbsp;&nbsp;&nbsp; ti=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+title+&#39;)&#39;)])<br>&nbsp;&nbsp;&nbsp; ye=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+year+&#39;)&#39;)])<br>&nbsp;&nbsp;&nbsp; au=urllib.urlencode([(&#39;&#39;,&#39;(&#39;+author+&#39;)&#39;)])<br>
<br>&nbsp;&nbsp;&nbsp; url=&#39;<a href="http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&amp;SID=Q1mNFhCECOk6c8aELLh&amp;rspType=xml&amp;method=searchRetrieve&amp;firstRec=1&amp;numRecs=1&amp;query=TI&#39;+ti+&#39;&amp;PY&#39;+ye+&#39;&amp;AU&#39;+au">http://estipub.isiknowledge.com/esti/cgi?databaseID=WOS&amp;SID=Q1mNFhCECOk6c8aELLh&amp;rspType=xml&amp;method=searchRetrieve&amp;firstRec=1&amp;numRecs=1&amp;query=TI&#39;+ti+&#39;&amp;PY&#39;+ye+&#39;&amp;AU&#39;+au</a><br>
&nbsp;&nbsp;&nbsp; data = referencer.download (_(&quot;Obtaining data from ISI-WebOfScience&quot;), _(&quot;Fetching data for %s/%s/%s&quot;) % (author,title,year), url);<br>&nbsp;&nbsp;&nbsp; xmldoc = minidom.parseString(data)<br>&nbsp;&nbsp;&nbsp; authors=get_field(xmldoc,&quot;primaryauthor&quot;)<br>
&nbsp;&nbsp;&nbsp; more_authors=get_fields(xmldoc,&quot;author&quot;,&#39; and &#39;)<br>&nbsp;&nbsp;&nbsp; if(len(more_authors)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; authors+=&#39; and &#39;+more_authors<br>&nbsp;&nbsp;&nbsp; abstract=get_field(xmldoc,&quot;p&quot;)<br>&nbsp;&nbsp;&nbsp; keywords=get_fields(xmldoc,&quot;keyword&quot;,&#39;, &#39;)<br>
&nbsp;&nbsp;&nbsp; journal=get_field(xmldoc,&quot;source_title&quot;)<br>&nbsp;&nbsp;&nbsp; doi=get_last_field(xmldoc,&quot;article_no&quot;)<br>&nbsp;&nbsp;&nbsp; pages=get_field(xmldoc,&quot;bib_pages&quot;)<br>&nbsp;&nbsp;&nbsp; title_isi=get_field(xmldoc,&quot;item_title&quot;)<br>
&nbsp;&nbsp;&nbsp; year_isi=get_attribute_from_field(xmldoc,&quot;bib_issue&quot;,&quot;year&quot;)<br>&nbsp;&nbsp;&nbsp; volume_isi=get_attribute_from_field(xmldoc,&quot;bib_issue&quot;,&quot;vol&quot;)<br><br>&nbsp;&nbsp;&nbsp; if (len(year)==0 and len(year_isi)&gt;0):<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;year&quot;,year_isi)<br>&nbsp;&nbsp;&nbsp; if (len(volume)==0 and len(volume_isi)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;volume&quot;,volume_isi)<br>&nbsp;&nbsp;&nbsp; if (len(title)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;title&quot;,title_isi)<br>
&nbsp;&nbsp;&nbsp; if (len(authors)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;author&quot;,authors)<br>&nbsp;&nbsp;&nbsp; if (len(doi)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;doi&quot;,doi)<br>&nbsp;&nbsp;&nbsp; if (len(journal_orig)==0 and len(journal)&gt;0):<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;journal&quot;,journal)<br>&nbsp;&nbsp;&nbsp; if (len(page_orig)&lt;len(pages) and pages!=&#39;-&#39;):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;pages&quot;,pages)<br>&nbsp;&nbsp;&nbsp; if (len(abstract)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;abstract&quot;,abstract)<br>
&nbsp;&nbsp;&nbsp; if (len(keywords)&gt;0):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; document.set_field(&quot;keywords&quot;,keywords)<br><br>def do_action (documents):<br>&nbsp;&nbsp;&nbsp; empty = True<br>&nbsp;&nbsp;&nbsp; s = &quot;&quot;<br>&nbsp;&nbsp;&nbsp; assigned_keys = {}<br>&nbsp;&nbsp;&nbsp; for document in documents:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rec=getNumberOfRecords(document)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (rec==&#39;1&#39;):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; getAndSetFields(document)<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return True<br><br><br><br>