<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.stringwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Micha.Moskovic</id>
	<title>String Theory Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.stringwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Micha.Moskovic"/>
	<link rel="alternate" type="text/html" href="http://www.stringwiki.org/wiki/Special:Contributions/Micha.Moskovic"/>
	<updated>2026-04-17T05:09:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>http://www.stringwiki.org/w/index.php?title=Spires.py&amp;diff=3885</id>
		<title>Spires.py</title>
		<link rel="alternate" type="text/html" href="http://www.stringwiki.org/w/index.php?title=Spires.py&amp;diff=3885"/>
		<updated>2020-03-31T08:51:30Z</updated>

		<summary type="html">&lt;p&gt;Micha.Moskovic: use old API after new INSPIRE release&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Copy the following text into a file called spires.py and save it.&lt;br /&gt;
&lt;br /&gt;
Further usage instructions are available at [[SPIRES_script]].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /usr/bin/python&lt;br /&gt;
&lt;br /&gt;
## SPIRES script version 0.6&lt;br /&gt;
&lt;br /&gt;
## updated for inSPIRE&lt;br /&gt;
&lt;br /&gt;
## Copyright 2015 Tom Brown&lt;br /&gt;
&lt;br /&gt;
## This program is free software; you can redistribute it and/or&lt;br /&gt;
## modify it under the terms of the GNU General Public License as&lt;br /&gt;
## published by the Free Software Foundation; either version 3 of the&lt;br /&gt;
## License, or (at your option) any later version.&lt;br /&gt;
&lt;br /&gt;
## This program is distributed in the hope that it will be useful,&lt;br /&gt;
## but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
## GNU General Public License for more details.&lt;br /&gt;
&lt;br /&gt;
## You should have received a copy of the GNU General Public License&lt;br /&gt;
## along with this program.  If not, see &amp;lt;http://www.gnu.org/licenses/&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
## See http://www.stringwiki.org/wiki/SPIRES_script for more usage&lt;br /&gt;
## instructions&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;SPIRES script&lt;br /&gt;
Usage:&lt;br /&gt;
python spires.py reference [ -hbiatcev ] [ --help ] [ --library library.bib ] [ --download download_path/ ]&lt;br /&gt;
&amp;quot;reference&amp;quot; must be a standard arXiv reference, e.g. hep-th/9711200, 0705.0303, Maldacena:1997re or a SPIRES journal reference, e.g. CMPHA,43,199&lt;br /&gt;
Options:&lt;br /&gt;
-h, --help&lt;br /&gt;
displays this help message&lt;br /&gt;
-b&lt;br /&gt;
displays the BiBTeX entry&lt;br /&gt;
-i&lt;br /&gt;
displays the bibitem entry&lt;br /&gt;
-a&lt;br /&gt;
displays the author(s)&lt;br /&gt;
-t&lt;br /&gt;
displays the title&lt;br /&gt;
-c&lt;br /&gt;
displays the TeX citation key&lt;br /&gt;
-e&lt;br /&gt;
displays everything&lt;br /&gt;
-v&lt;br /&gt;
verbose mode&lt;br /&gt;
&lt;br /&gt;
--download download_path/&lt;br /&gt;
for arXiv references downloads a pdf of the paper from the arXiv to the directory download_path/&lt;br /&gt;
--library library.bib&lt;br /&gt;
if it is not already in library.bib, appends the BiBTeX entry to library.bib; use at your own risk&lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
__version__ = &amp;quot;0.6&amp;quot;&lt;br /&gt;
__author__ = &amp;quot;Tom Brown&amp;quot;&lt;br /&gt;
__copyright__ = &amp;quot;Copyright 2015 Tom Brown, GNU GPL 3&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import sys, os, getopt, re, urllib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#\d is a decimal digit; \D is anything but a decimal digit&lt;br /&gt;
def findRefType(ref):&lt;br /&gt;
    ref = ref.replace(&#039;arxiv:&#039;,&#039;&#039;)&lt;br /&gt;
    if re.search(r&#039;^[a-zA-Z\-\.]+/\d{7}$&#039;,ref):&lt;br /&gt;
        rType = &#039;old-style eprint&#039;&lt;br /&gt;
    elif re.search(r&#039;^\d{7}$&#039;,ref):&lt;br /&gt;
        rType = &#039;old-style eprint&#039;&lt;br /&gt;
        ref = &#039;hep-th/&#039; + ref&lt;br /&gt;
    elif re.search(&#039;^\d{4}\.\d{4,5}$&#039;,ref):&lt;br /&gt;
        rType = &#039;new-style eprint&#039;&lt;br /&gt;
    elif re.search(r&#039;^\D+:\d{4}[a-zA-Z]{2,3}$&#039;,ref):&lt;br /&gt;
        rType = &#039;texkey&#039;&lt;br /&gt;
    else:&lt;br /&gt;
        rType = &#039;journal&#039;&lt;br /&gt;
&lt;br /&gt;
    return rType, ref&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def getBiBTeX(ref,rType):&lt;br /&gt;
    if rType == &#039;old-style eprint&#039;:&lt;br /&gt;
        query = &#039;p=find+eprint+&#039; + ref&lt;br /&gt;
    elif rType == &#039;new-style eprint&#039;:&lt;br /&gt;
        query = &#039;p=find+eprint+&#039; + ref&lt;br /&gt;
    elif rType == &#039;texkey&#039;:&lt;br /&gt;
        query = &#039;texkey=&#039; + ref&lt;br /&gt;
    elif rType == &#039;journal&#039;:&lt;br /&gt;
        query = &#039;j=&#039; + ref&lt;br /&gt;
    else:&lt;br /&gt;
        return &amp;quot;no records were found in SPIRES to match your search, please try again&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    #http://inspirehep.net/search?p=hep-th%2F9711200&amp;amp;of=hx&lt;br /&gt;
    #http://inspirehep.net/search?p=1101.0121&amp;amp;of=hx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    BiBTeX = urllib.urlopen(&#039;http://old.inspirehep.net/search?&#039; + query + &#039;&amp;amp;of=hx&#039;).read()&lt;br /&gt;
&lt;br /&gt;
    if &#039;No records&#039; in BiBTeX:&lt;br /&gt;
        return &amp;quot;no records were found in SPIRES to match your search, please try again&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    BiBTeX = BiBTeX[BiBTeX.find(&#039;&amp;lt;pre&amp;gt;&#039;):]&lt;br /&gt;
    BiBTeX = BiBTeX[BiBTeX.find(&#039;@&#039;):]&lt;br /&gt;
&lt;br /&gt;
    BiBTeX = BiBTeX[:BiBTeX.rfind(&#039;/pre&amp;gt;&#039;)]&lt;br /&gt;
    BiBTeX = BiBTeX[:BiBTeX.rfind(&#039;}&#039;)+1]&lt;br /&gt;
        &lt;br /&gt;
    return BiBTeX&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def getBibitem(ref,rType):&lt;br /&gt;
    if rType == &#039;old-style eprint&#039;:&lt;br /&gt;
        query = &#039;p=find+eprint+&#039; + ref&lt;br /&gt;
    elif rType == &#039;new-style eprint&#039;:&lt;br /&gt;
        query = &#039;p=find+eprint+&#039; + ref&lt;br /&gt;
    elif rType == &#039;texkey&#039;:&lt;br /&gt;
        query = &#039;texkey=&#039; + ref&lt;br /&gt;
    elif rType == &#039;journal&#039;:&lt;br /&gt;
        query = &#039;j=&#039; + ref&lt;br /&gt;
    else:&lt;br /&gt;
        return &amp;quot;no records were found in SPIRES to match your search, please try again&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    bibitem = urllib.urlopen(&#039;http://old.inspirehep.net/search?&#039; + query + &#039;&amp;amp;of=hlxe&#039;).read()&lt;br /&gt;
&lt;br /&gt;
    if &#039;No records&#039; in bibitem:&lt;br /&gt;
        return &amp;quot;no records were found in SPIRES to match your search, please try again&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    bibitem = bibitem[bibitem.find(&#039;&amp;lt;pre&amp;gt;&#039;)+5:bibitem.rfind(&#039;/pre&amp;gt;&#039;)-1]&lt;br /&gt;
&lt;br /&gt;
    #treat newlines correctly&lt;br /&gt;
    bibitem = bibitem.replace(&amp;quot;&amp;lt;br&amp;gt;&amp;quot;,&amp;quot;\n&amp;quot;).replace(&amp;quot;&amp;lt;br /&amp;gt;&amp;quot;,&amp;quot;\n&amp;quot;).replace(&amp;quot;&amp;amp;amp;nbsp;&amp;quot;,&amp;quot; &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    return bibitem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def extractauthor(BiBTeX):&lt;br /&gt;
    # remove excess white space and replace with a single space&lt;br /&gt;
    data = re.sub(r&#039;\s+&#039;,r&#039; &#039;,BiBTeX)&lt;br /&gt;
&lt;br /&gt;
    author = data[data.find(&#039;author&#039;):]&lt;br /&gt;
    author = author[author.find(&#039;\&amp;quot;&#039;)+1:]&lt;br /&gt;
    author = author[:author.find(&#039;\&amp;quot;&#039;)]&lt;br /&gt;
&lt;br /&gt;
    return author&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def extracttitle(BiBTeX):&lt;br /&gt;
    # remove excess white space and replace with a single space&lt;br /&gt;
    data = re.sub(r&#039;\s+&#039;,r&#039; &#039;,BiBTeX)&lt;br /&gt;
&lt;br /&gt;
    title = data[data.find(&#039;title&#039;):]&lt;br /&gt;
    title = title[title.find(&#039;\&amp;quot;&#039;)+2:]&lt;br /&gt;
    title = title[:title.find(&#039;\&amp;quot;&#039;)-1]&lt;br /&gt;
&lt;br /&gt;
    return title&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def extractcite(BiBTeX):&lt;br /&gt;
    cite = BiBTeX[BiBTeX.find(&#039;{&#039;)+1:BiBTeX.find(&#039;,&#039;)]&lt;br /&gt;
    return cite&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def downloadeprint(ref,rType,downloadPath):&lt;br /&gt;
    downloadPath = os.path.expanduser(downloadPath)&lt;br /&gt;
    if rType == &#039;old-style eprint&#039;:&lt;br /&gt;
        urllib.urlretrieve(&#039;http://arxiv.org/pdf/&#039; + ref, downloadPath + ref.replace(&#039;/&#039;,&#039;-&#039;) + &#039;.pdf&#039;)&lt;br /&gt;
    elif rType == &#039;new-style eprint&#039;:&lt;br /&gt;
        urllib.urlretrieve(&#039;http://arxiv.org/pdf/&#039; + ref, downloadPath + ref + &#039;.pdf&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def updatelibrary(cite,BiBTeX,BiBTeXlibraryFileName):&lt;br /&gt;
    BiBTeXlibraryFileName = os.path.expanduser(BiBTeXlibraryFileName)&lt;br /&gt;
    libraryfile = open(BiBTeXlibraryFileName, &#039;r&#039;)&lt;br /&gt;
    library = libraryfile.read()&lt;br /&gt;
    libraryfile.close()&lt;br /&gt;
&lt;br /&gt;
    if library.count(cite) == 0:&lt;br /&gt;
        print &#039;adding BiBTeX entry to &#039; + BiBTeXlibraryFileName&lt;br /&gt;
        #find the end of the file (the second argument means count from&lt;br /&gt;
        #the end of the file&lt;br /&gt;
        libraryfile = open(BiBTeXlibraryFileName, &#039;a&#039;)&lt;br /&gt;
        libraryfile.write(&#039;\n&#039; + BiBTeX + &#039;\n&#039;)&lt;br /&gt;
        libraryfile.close()      &lt;br /&gt;
    else:&lt;br /&gt;
        print &#039;BiBTeX entry already in library&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def listCitations(fileName):&lt;br /&gt;
    fileName = os.path.expanduser(fileName)&lt;br /&gt;
    f=open(fileName, &#039;r&#039;)&lt;br /&gt;
    data = f.read()&lt;br /&gt;
    f.close()&lt;br /&gt;
&lt;br /&gt;
    if data.find(r&#039;\begin{thebibliography}&#039;) &amp;gt;= 0:&lt;br /&gt;
        data = data[:data.find(r&#039;\begin{thebibliography}&#039;)]&lt;br /&gt;
&lt;br /&gt;
    citations = []&lt;br /&gt;
&lt;br /&gt;
    while(data.find(r&#039;\cite{&#039;) &amp;gt;=0):&lt;br /&gt;
        data = data[data.find(r&#039;\cite{&#039;) + 6:]&lt;br /&gt;
        if(data.find(&#039;}&#039;) &amp;gt;=0):&lt;br /&gt;
            citation = data[:data.find(&#039;}&#039;)]&lt;br /&gt;
            data = data[data.find(&#039;}&#039;)+1:]&lt;br /&gt;
            citation = citation + &#039;,&#039;&lt;br /&gt;
            while(citation.find(&#039;,&#039;) &amp;gt;=0):&lt;br /&gt;
                if citation[:citation.find(&#039;,&#039;)] not in citations:&lt;br /&gt;
                    citations.append(citation[:citation.find(&#039;,&#039;)])&lt;br /&gt;
                citation = citation[citation.find(&#039;,&#039;)+1:]&lt;br /&gt;
    return citations&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
    authorOpt = 0&lt;br /&gt;
    titleOpt = 0&lt;br /&gt;
    bibtexOpt = 0&lt;br /&gt;
    bibitemOpt = 0&lt;br /&gt;
    citeOpt = 0&lt;br /&gt;
    verboseOpt = 0&lt;br /&gt;
    libraryOpt = 0&lt;br /&gt;
    downloadOpt = 0&lt;br /&gt;
&lt;br /&gt;
    try:&lt;br /&gt;
        options, arguments = getopt.gnu_getopt(sys.argv[1:], &lt;br /&gt;
        &#039;hbiatcev&#039;, [&#039;help&#039;,&#039;library=&#039;,&#039;download=&#039;])&lt;br /&gt;
    except getopt.error:&lt;br /&gt;
        print &#039;error: you tried to use an unknown option or the argument for an option that requires it was missing; try \&#039;spires.py -h\&#039; for more information&#039;&lt;br /&gt;
        sys.exit(0)&lt;br /&gt;
&lt;br /&gt;
    for o,a in options:&lt;br /&gt;
        if o in  (&#039;-h&#039;,&#039;--help&#039;):&lt;br /&gt;
            print __doc__&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;--library&#039;:&lt;br /&gt;
            if a == &#039;&#039;:&lt;br /&gt;
                print &#039;--library expects an argument&#039;&lt;br /&gt;
                sys.exit(0)&lt;br /&gt;
            libraryOpt = 1&lt;br /&gt;
            BiBTeXlibraryFileName = os.path.expanduser(a)&lt;br /&gt;
            print &#039;library file name is &#039; + BiBTeXlibraryFileName&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;--download&#039;:&lt;br /&gt;
            downloadOpt = 1&lt;br /&gt;
            if a == &#039;&#039;:&lt;br /&gt;
                a = &#039;./&#039;&lt;br /&gt;
            elif a[-1] != &#039;/&#039;:&lt;br /&gt;
                a = a + &#039;/&#039;&lt;br /&gt;
            downloadPath = os.path.expanduser(a)&lt;br /&gt;
            print &#039;download path is &#039; + downloadPath&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-b&#039;:&lt;br /&gt;
            bibtexOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-i&#039;:&lt;br /&gt;
            bibitemOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-a&#039;:&lt;br /&gt;
            authorOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-t&#039;:&lt;br /&gt;
            titleOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-c&#039;:&lt;br /&gt;
            citeOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-e&#039;:&lt;br /&gt;
            bibtexOpt = 1&lt;br /&gt;
            authorOpt = 1&lt;br /&gt;
            titleOpt = 1&lt;br /&gt;
            citeOpt = 1&lt;br /&gt;
&lt;br /&gt;
        elif o == &#039;-v&#039;:&lt;br /&gt;
            verboseOpt = 1&lt;br /&gt;
&lt;br /&gt;
    if len(arguments) != 1:&lt;br /&gt;
        print &#039;you didn\&#039;t specify a SPIRES reference; try \&#039;spires.py -h\&#039; for more information&#039;&lt;br /&gt;
        sys.exit(0)&lt;br /&gt;
    else:&lt;br /&gt;
        ref=arguments[0]&lt;br /&gt;
&lt;br /&gt;
    if len(options) == 0:&lt;br /&gt;
        bibtexOpt = 1&lt;br /&gt;
        authorOpt = 1&lt;br /&gt;
        titleOpt = 1&lt;br /&gt;
        citeOpt = 1&lt;br /&gt;
&lt;br /&gt;
    print ref&lt;br /&gt;
    rType, ref = findRefType(ref)&lt;br /&gt;
    print rType, ref&lt;br /&gt;
&lt;br /&gt;
    if verboseOpt:&lt;br /&gt;
        print &#039;the reference &#039; + ref + &#039; is a(n) &#039; + rType&lt;br /&gt;
&lt;br /&gt;
    if (bibtexOpt + authorOpt + titleOpt + citeOpt + libraryOpt) &amp;gt; 0:&lt;br /&gt;
        BiBTeX = getBiBTeX(ref,rType)&lt;br /&gt;
        if &#039;no records&#039; in BiBTeX:&lt;br /&gt;
            print BiBTeX&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
&lt;br /&gt;
    if bibtexOpt:&lt;br /&gt;
        print BiBTeX&lt;br /&gt;
&lt;br /&gt;
    if bibitemOpt:&lt;br /&gt;
        bibitem = getBibitem(ref,rType)&lt;br /&gt;
        print bibitem&lt;br /&gt;
        if &#039;no records&#039; in bibitem:&lt;br /&gt;
            sys.exit(0)&lt;br /&gt;
&lt;br /&gt;
    if authorOpt:&lt;br /&gt;
        author = extractauthor(BiBTeX)&lt;br /&gt;
        print author&lt;br /&gt;
&lt;br /&gt;
    if titleOpt:&lt;br /&gt;
        title = extracttitle(BiBTeX)&lt;br /&gt;
        print title&lt;br /&gt;
&lt;br /&gt;
    if (citeOpt + libraryOpt) &amp;gt; 0:&lt;br /&gt;
        cite = extractcite(BiBTeX)&lt;br /&gt;
&lt;br /&gt;
    if citeOpt:&lt;br /&gt;
        print &#039;\cite{&#039; + cite + &#039;}&#039;&lt;br /&gt;
&lt;br /&gt;
    if libraryOpt:&lt;br /&gt;
        updatelibrary(cite,BiBTeX,BiBTeXlibraryFileName)&lt;br /&gt;
&lt;br /&gt;
    if downloadOpt:&lt;br /&gt;
        downloadeprint(ref,rType,downloadPath)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Micha.Moskovic</name></author>
	</entry>
</feed>