[Surfraw-devel] New arXiv elvi

John Gruenenfelder johng at as.arizona.edu
Tue Jun 3 23:53:29 UTC 2008


Hello,

I recently discovered surfraw and now have a wonderful new command line tool.

However, I found that the existing arXiv elvi, xxx, doesn't actually do
anything other than display the arXiv website.  Basically just a bookmark
wrapped in a a script.

So, I wrote a new one called arxiv that lets users search for articles by
search on all fields, titles, authors, abstracts, or full article text just as
the arXiv search box allows you.

It has a few limitations.  It doesn't allow searching based on article ID
since that doesn't seem to happen through normal GET methods.

Also, when searching by author you can only search for one name and it can
only have two words in it.  It is smart enough, though, to correctly handle
"Last, First" and "First Last" style names.

I think I followed the style guidelines appropriately.  I've attached the new
elvi to this mail.


-- 
--John Gruenenfelder    Research Assistant, UMass Amherst student
                        Systems Manager, MKS Imaging Technology, LLC.
Try Weasel Reader for PalmOS  --  http://weaselreader.org
"This is the most fun I've had without being drenched in the blood
of my enemies!"
        --Sam of Sam & Max
-------------- next part --------------
#!/bin/sh
#
# $Id$
#
# elvis: arxiv -- Search arXiv E-Print Archive for articles
#
# 2008-June-03 - By John Gruenenfelder (johng at as.arizona.edu)
#                Rewrote 'xxx' script to allow searching arXiv site by various
#                means.
#

. surfraw || exit 1


w3_config_hook () {
    def SURFRAW_arxiv_scope all
}


w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search terms]
Description:
  Surfraw the Los Alamos Science E-Print Archive (arXiv)
Local options:
  -scope=                       Limit scope of arXiv search
         all        |           Search all fields
         title      |           Search article titles
         author     |           Search article authors
         abstract   |           Search article abstracts
         fulltext               Search the full text of articles
                                Default: $SURFRAW_arxiv_scope
                                Environment: SURFRAW_arxiv_scope
EOF
    w3_global_usage
}


w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-scope=*) setopt   SURFRAW_arxiv_scope $optarg	;;
	*) return 1 ;;
    esac
    return 0
}




# Parse config
w3_config

# Parse search terms
SURFRAW_quote_ifs=0
w3_parse_args "$@"


# Mangle search terms into something useable
terms=""
cnt=0
if [ ! -z "$w3_args" ]; then
    case $SURFRAW_arxiv_scope in
	all | title | abstract)
	    for w in $w3_args ; do
		terms=$terms"+"`w3_url_of_arg $w`
		cnt=$((cnt + 1))
	    done
	    if [ $cnt -gt 1 ]; then
		terms="+AND"$terms
	    fi
	    ;;
	author)
	    # Names without commas need to be reversed
	    echo "$w3_args" | grep -q ","
	    if [ $? -eq 0 ]; then
	        # Name already in last, first format.
		terms=`echo "$w3_args" | sed -e "s/,/_/g" -e "s/ //g"`
		terms="+"`w3_url_of_arg $terms`
	    else
	        # Name in first last format.  Need to reverse.
		first=""
		last=""
		for n in $w3_args ; do
		    if [ -z $first ]; then
			first=$n
		    elif [ -z $last ]; then
			last=$n
		    fi
		done
		terms=$last"_"$first
		terms="+"`w3_url_of_arg $terms`
	    fi
	    ;;
	fulltext)
	    # Need to remove leading/trailing spaces and quotes
	    for w in $w3_args ; do
		if [ -z $terms ]; then
		    terms=`w3_url_of_arg $w`
		else
		    terms="$terms "`w3_url_of_arg $w`
		fi
	    done
	    ;;
	*)
	    return 1 ;;
    esac
fi



# Form URL
if [ -z "$w3_args" ]; then
    url="http://arXiv.org/"
else
    case $SURFRAW_arxiv_scope in
	all)
	    url="http://arXiv.org/find/all/1/all:"$terms"/0/1/0/all/0/1"
	    ;;
	title)
	    url="http://arXiv.org/find/all/1/ti:"$terms"/0/1/0/all/0/1"
	    ;;
	abstract)
	    url="http://arXiv.org/find/all/1/abs:"$terms"/0/1/0/all/0/1"
	    ;;
	author)
	    url="http://arXiv.org/find/all/1/au:"$terms"/0/1/0/all/0/1"
	    ;;
	fulltext)
	    url="http://search.arXiv.org:8081/?query="$terms"&in="
	    ;;
	*)
	    return 1 ;;
    esac
fi


w3_browse_url $url


More information about the Surfraw-devel mailing list