Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to specify where to start looking at results. #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,8 @@ class SearchScholarQuery(ScholarQuery):
+ '&as_vis=%(citations)s' \
+ '&btnG=&hl=en' \
+ '%(num)s' \
+ '&as_sdt=%(patents)s%%2C5'
+ '&as_sdt=%(patents)s%%2C5' \
+ '&start=%(start)s'

def __init__(self):
ScholarQuery.__init__(self)
Expand All @@ -773,6 +774,7 @@ def __init__(self):
self.timeframe = [None, None]
self.include_patents = True
self.include_citations = True
self.start = 0

def set_words(self, words):
"""Sets words that *all* must be found in the result."""
Expand Down Expand Up @@ -822,6 +824,9 @@ def set_include_citations(self, yesorno):
def set_include_patents(self, yesorno):
self.include_patents = yesorno

def set_start_index(self, index):
self.start = index

def get_url(self):
if self.words is None and self.words_some is None \
and self.words_none is None and self.phrase is None \
Expand Down Expand Up @@ -852,7 +857,8 @@ def get_url(self):
'ylo': self.timeframe[0] or '',
'yhi': self.timeframe[1] or '',
'patents': '0' if self.include_patents else '1',
'citations': '0' if self.include_citations else '1'}
'citations': '0' if self.include_citations else '1',
'start': self.start or '0'}

for key, val in urlargs.items():
urlargs[key] = quote(encode(val))
Expand Down Expand Up @@ -1191,6 +1197,8 @@ def main():
help='Do not search, just use articles in given cluster ID')
group.add_option('-c', '--count', type='int', default=None,
help='Maximum number of results')
group.add_option('-r', '--start', type='int', default=None,
help='Begin with the result at a particular index [zero-indexed]')
parser.add_option_group(group)

group = optparse.OptionGroup(parser, 'Output format',
Expand Down Expand Up @@ -1285,6 +1293,8 @@ def main():
query.set_include_patents(False)
if options.no_citations:
query.set_include_citations(False)
if options.start:
query.set_start_index(options.start)

if options.count is not None:
options.count = min(options.count, ScholarConf.MAX_PAGE_RESULTS)
Expand Down