Skip to content

Commit

Permalink
Simplify search command drill-down key-based indexing; loop for ease
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerdq committed Aug 21, 2019
1 parent 4f03546 commit eb749b4
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pdfca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@


def checkIndex(dataframe):
key = click.prompt('Please enter item to explore')
key = int(click.prompt('Please enter item to explore'))
while True:
if key in dataframe.index:
if key in dataframe.index.values:
key = dataframe.at[key, 'filename']
return key
else:
key = click.prompt('Please enter a valid key')
key = int(click.prompt('Please enter a valid key'))


def count(x, term):
Expand Down Expand Up @@ -267,15 +268,19 @@ def search(term, binary, form, search_type, number):
else:
results = dropped.sum().sort_values(by=[term])
click.echo(f'Top {number} results:')
results = results.tail(number)
results = results.tail(number).reset_index()
click.echo(results)
if click.confirm('\nWould you like to drill down?'):
key = checkIndex(results)
filtered = grouped.get_group(key).sort_values(by=[term])
filtered = filtered.set_index('page')
click.echo()
click.echo(f'Top {number} results:')
click.echo(filtered.tail(number).sort_values(by=['page']))
while True:
key = checkIndex(results)
filtered = grouped.get_group(key).sort_values(by=[term])
filtered = filtered.set_index('page')
click.echo()
click.echo(f'Top {number} results:')
click.echo(filtered.tail(number).sort_values(by=['page']))
if not click.confirm('\nExplore another PDF?'):
break
click.echo(f'{results}\n')


@cli.command()
Expand Down

0 comments on commit eb749b4

Please sign in to comment.