Created
September 8, 2013 19:33
-
-
Save mardukbp/6487740 to your computer and use it in GitHub Desktop.
Patch https://github.com/venthur/gscholar/ to take author and title as arguments in order to narrow search results.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- gscholar/gscholar/gscholar.py | |
+++ gscholar/gscholar/gscholar.py | |
@@ -57,8 +57,10 @@ | |
def query(searchstr, outformat, allresults=False): | |
"""Return a list of bibtex items.""" | |
- logging.debug("Query: %s" % searchstr) | |
- searchstr = '/scholar?q='+urllib2.quote(searchstr) | |
+ author = searchstr[0] | |
+ title = searchstr[1] | |
+ logging.debug("Query: author:%s title:%s" % (author, title)) | |
+ searchstr = '/scholar?as_q=&as_epq='+urllib2.quote(title)+'&as_oq=&as_eq=&as_occt=title&as_sauthors='+urllib2.quote(author)+'&as_publication=&as_ylo=&as_yhi=&btnG=&hl=en&as_sdt=0%2C5' | |
url = GOOGLE_SCHOLAR_URL + searchstr | |
header = HEADERS | |
header['Cookie'] = header['Cookie'] + ":CF=%d" % outformat | |
@@ -78,9 +80,9 @@ | |
request = urllib2.Request(url, headers=header) | |
response = urllib2.urlopen(request) | |
bib = response.read() | |
- print bib | |
+ #print bib | |
result.append(bib) | |
return result | |
@@ -190,12 +192,12 @@ | |
outformat = FORMAT_REFMAN | |
elif options.output == 'wenxianwang': | |
outformat = FORMAT_WENXIANWANG | |
- if len(args) != 1: | |
+ if len(args) < 1: | |
parser.error("No argument given, nothing to do.") | |
sys.exit(1) | |
- args = args[0] | |
+ #args = args[0] | |
pdfmode = False | |
- if os.path.exists(args): | |
+ if os.path.exists(args[1]): | |
logging.debug("File exist, assuming you want me to lookup the pdf: %s." % args) | |
pdfmode = True | |
biblist = pdflookup(args, all, outformat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment