Added ability to configure the application only by supplying the consumer key and reading speed
This commit is contained in:
parent
25a8016671
commit
1d9f507956
2 changed files with 40 additions and 4 deletions
|
@ -12,6 +12,7 @@ from .storage import Storage
|
|||
|
||||
class PocketApp:
|
||||
DEFAULT_WORDS_PER_MINUTE = 180
|
||||
REDIRECT_URL = 'http://www.google.com'
|
||||
|
||||
def __init__(self):
|
||||
self._configs = Configs()
|
||||
|
@ -22,6 +23,22 @@ class PocketApp:
|
|||
self._configs.get('access_token')
|
||||
)
|
||||
|
||||
def configure(self, consumer_key, access_token, words_per_minute):
|
||||
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.write()
|
||||
|
||||
def get_request_token(self, consumer_key):
|
||||
return self._pocket.get_request_token(
|
||||
consumer_key, self.REDIRECT_URL
|
||||
)
|
||||
|
||||
def get_access_token(self, consumer_key, request_token):
|
||||
return self._pocket.get_access_token(
|
||||
consumer_key, request_token
|
||||
)
|
||||
|
||||
def add_article(self, url, title=None, tags=None):
|
||||
if isinstance(tags, tuple):
|
||||
tags = ','.join(list(tags))
|
||||
|
|
|
@ -22,14 +22,33 @@ def main():
|
|||
@click.command()
|
||||
@click.option('--consumer-key', '-k',
|
||||
prompt='Please provide your consumer key')
|
||||
@click.option('--access-token', '-t',
|
||||
prompt='Please provide your access token')
|
||||
@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():
|
||||
pass
|
||||
def configure(consumer_key, words_per_minute):
|
||||
request_token = pocket_app.get_request_token(consumer_key)
|
||||
|
||||
if not request_token:
|
||||
print('Could not obtain request_token')
|
||||
return
|
||||
|
||||
url = 'http://getpocket.com/auth/authorize?request_token={0}' \
|
||||
'&redirect_uri={1}'.format(request_token, 'http://www.google.com')
|
||||
|
||||
print('You will have to authorize the application to access your articles')
|
||||
print('Enter any key once you\'re redirected to google.com')
|
||||
webbrowser.open_new_tab(url)
|
||||
input()
|
||||
|
||||
access_token = pocket_app.get_access_token(consumer_key, request_token)
|
||||
|
||||
if not access_token:
|
||||
print('Could not obtain access token')
|
||||
return
|
||||
|
||||
pocket_app.configure(consumer_key, access_token, words_per_minute)
|
||||
print('The application is ready to use')
|
||||
|
||||
|
||||
@click.command(name='add')
|
||||
|
|
Loading…
Reference in a new issue