<commit_before>from __future__ import absolute_import
from __future__ import print_function

from builtins import input

import random
import subprocess
import sys
import six
import webbrowser

import click

from .app import PocketApp
from .exceptions import AppNotConfigured, AppException
from .utils import format_article


pocket_app = PocketApp()

WORDS_PER_MINUTE = 180


CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


@click.group(context_settings=CONTEXT_SETTINGS)
@click.version_option()
def main():
    pass


@click.command()
@click.option('--consumer-key', '-k',
              prompt='Please provide your consumer key')
@click.option('--sort_field', '-s',
              type=click.Choice(['id', 'reading_time']),
              default='reading_time',
              prompt='Please provide your preferred sort field\n'
                     '\tAvailable options are [id, reading_time]\n'
                     '\tdefault:')
@click.option('--words-per-minute', '-wpm',
              type=click.INT,
              default=180,
              prompt='Please specify your reading speed in words per minute\n'
                     '\tYou can use this URL to estimate your reading time\n'
                     '\thttp://www.readingsoft.com/\n'
                     '\tdefault:',
              help='Used in calculating reading time for each article')
def configure(consumer_key, sort_field, words_per_minute):
    pocket_app.init_consumer_key(consumer_key)

    request_token = pocket_app.get_request_token()

    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(request_token)

    if not access_token:
        print('Could not obtain access token')
        return

    pocket_app.configure(consumer_key, access_token,
                         words_per_minute, sort_field)
    print('The application is ready to use')


@click.command(name='add')
@click.option('--url', '-u',
              help='The URL to be added')
@click.option('--title', '-t',
              help='The article\'s title')
@click.option('--tags', '-g', multiple=True,
              help='Tags to be associated. '
                   'Can be multiple tags --tags=tag1, --tags=tag2')
def add_article(url, title, tags):<commit_msg>Show a link to obtain access token; resolves #13 This commit adds printing access token link to provide ability to copy & visit it manually to obtain an access token, as a fallback<commit_after>from __future__ import absolute_import
from __future__ import print_function

from builtins import input

import random
import subprocess
import sys
import six
import webbrowser

import click

from .app import PocketApp
from .exceptions import AppNotConfigured, AppException
from .utils import format_article


pocket_app = PocketApp()

WORDS_PER_MINUTE = 180


CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])


@click.group(context_settings=CONTEXT_SETTINGS)
@click.version_option()
def main():
    pass


@click.command()
@click.option('--consumer-key', '-k',
              prompt='Please provide your consumer key')
@click.option('--sort_field', '-s',
              type=click.Choice(['id', 'reading_time']),
              default='reading_time',
              prompt='Please provide your preferred sort field\n'
                     '\tAvailable options are [id, reading_time]\n'
                     '\tdefault:')
@click.option('--words-per-minute', '-wpm',
              type=click.INT,
              default=180,
              prompt='Please specify your reading speed in words per minute\n'
                     '\tYou can use this URL to estimate your reading time\n'
                     '\thttp://www.readingsoft.com/\n'
                     '\tdefault:',
              help='Used in calculating reading time for each article')
def configure(consumer_key, sort_field, words_per_minute):
    pocket_app.init_consumer_key(consumer_key)

    request_token = pocket_app.get_request_token()

    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')
    print('Or open this link in browser manually:')
    print(url);
    webbrowser.open_new_tab(url)
    input()

    access_token = pocket_app.get_access_token(request_token)

    if not access_token:
        print('Could not obtain access token')
        return

    pocket_app.configure(consumer_key, access_token,
                         words_per_minute, sort_field)
    print('The application is ready to use')


@click.command(name='add')
@click.option('--url', '-u',
              help='The URL to be added')
@click.option('--title', '-t',
              help='The article\'s title')
@click.option('--tags', '-g', multiple=True,
              help='Tags to be associated. '
                   'Can be multiple tags --tags=tag1, --tags=tag2')
def add_article(url, title, tags):
{'fraction_non_alphanumeric': 0.11302925676903507, 'fraction_numerical': 0.003997819371252044, 'mean_word_length': 2.7880247763248454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1601664', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1522, 'n_words': 434}