Added a configuration param for choosing the sort field
This commit is contained in:
parent
6b8b90da0d
commit
b439150973
2 changed files with 22 additions and 5 deletions
|
@ -29,10 +29,12 @@ class PocketApp:
|
|||
self._configs.get('access_token')
|
||||
)
|
||||
|
||||
def configure(self, consumer_key, access_token, words_per_minute):
|
||||
def configure(self, consumer_key, access_token,
|
||||
words_per_minute, sort_field):
|
||||
self._configs.set('consumer_key', consumer_key)
|
||||
self._configs.set('access_token', access_token)
|
||||
self._configs.set('words_per_minute', words_per_minute)
|
||||
self._configs.set('sort_field', sort_field)
|
||||
self._configs.set('last_fetch', 0)
|
||||
self._configs.write()
|
||||
|
||||
|
@ -61,7 +63,14 @@ class PocketApp:
|
|||
if self._storage.is_empty():
|
||||
self.fetch_articles(True)
|
||||
|
||||
return self._storage.read(limit, order)
|
||||
articles = self._storage.read(limit, order)
|
||||
sort_field = self._configs.get('sort_field')
|
||||
if not sort_field:
|
||||
sort_field = 'reading_time'
|
||||
|
||||
articles = sorted(articles,
|
||||
key=itemgetter(sort_field))
|
||||
return articles
|
||||
|
||||
def archive_article(self, item_id):
|
||||
try:
|
||||
|
@ -141,8 +150,12 @@ class PocketApp:
|
|||
if spinner:
|
||||
spinner.finish()
|
||||
|
||||
sort_field = self._configs.get('sort_field')
|
||||
if not sort_field:
|
||||
sort_field = 'reading_time'
|
||||
|
||||
articles_index = sorted(articles_index,
|
||||
key=itemgetter('reading_time'))
|
||||
key=itemgetter(sort_field))
|
||||
self._storage.write(articles_index)
|
||||
|
||||
self._configs.set('last_fetch', self._get_timestamp(datetime.now()))
|
||||
|
|
|
@ -23,11 +23,14 @@ def main():
|
|||
@click.command()
|
||||
@click.option('--consumer-key', '-k',
|
||||
prompt='Please provide your consumer key')
|
||||
@click.option('--sort_field', '-s',
|
||||
type=click.Choice(['id', 'reading_time']),
|
||||
prompt='Please provide your preferred sort field')
|
||||
@click.option('--words-per-minute', '-wpm',
|
||||
type=click.INT,
|
||||
prompt='Please prefer your reading speed in words per minute',
|
||||
help='Used in calculating reading time for each article')
|
||||
def configure(consumer_key, words_per_minute):
|
||||
def configure(consumer_key, sort_field, words_per_minute):
|
||||
request_token = pocket_app.get_request_token(consumer_key)
|
||||
|
||||
if not request_token:
|
||||
|
@ -48,7 +51,8 @@ def configure(consumer_key, words_per_minute):
|
|||
print('Could not obtain access token')
|
||||
return
|
||||
|
||||
pocket_app.configure(consumer_key, access_token, words_per_minute)
|
||||
pocket_app.configure(consumer_key, access_token,
|
||||
words_per_minute, sort_field)
|
||||
print('The application is ready to use')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue