<commit_before>import os
import datetime

import click

CONF = os.path.join(os.path.expanduser('~'), '.watson')


@click.group()
def cli():
    pass


@cli.command()
@click.argument('project')
def start(project):
    start_time = datetime.datetime.now()
    click.echo("Starting {} at {:%H:%M:%S}".format(project, start_time))

if __name__ == '__main__':
    cli()<commit_msg>First working version of start and stop<commit_after>import os
import json
import datetime

import click

WATSON_FILE = os.path.join(os.path.expanduser('~'), '.watson')


def get_watson():
    try:
        with open(WATSON_FILE) as f:
            return json.load(f)
    except FileNotFoundError:
        return {}
    except ValueError:
        return {}


def save_watson(content):
    with open(WATSON_FILE, 'w+') as f:
        return json.dump(content, f)


@click.group()
def cli():
    pass


@cli.command()
@click.argument('project')
def start(project):
    watson = get_watson()
    start_time = datetime.datetime.now()

    if watson.get('current') is not None:
        project = watson['current'].get('project', "?")
        click.echo(
            ("Project {} is already started"
             .format(project, start_time)),
            err=True
        )
        return

    click.echo("Starting {} at {:%H:%M:%S}".format(project, start_time))

    watson['current'] = {
        'project': project,
        'start': start_time.isoformat()
    }

    save_watson(watson)


@cli.command()
def stop():
    watson = get_watson()
    stop_time = datetime.datetime.now()
    current = watson.get('current')

    if not current or not current.get('project'):
        click.echo("No project started", err=True)
        return

    click.echo("Stopping {}.".format(current['project']))

    if not watson.get('projects'):
        watson['projects'] = {}

    project = watson['projects'].get(current['project'])

    if not project:
        project = {'frames': []}
        watson['projects'][current['project']] = project

    project['frames'].append({
        'start': current['start'],
        'stop': stop_time.isoformat()
    })

    del watson['current']

    save_watson(watson)

if __name__ == '__main__':
    cli()
{'fraction_non_alphanumeric': 0.15887426236949614, 'fraction_numerical': 0.0, 'mean_word_length': 2.949820788530466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1810146', 'n_tokens_mistral': 724, 'n_tokens_neox': 679, 'n_words': 153}