<commit_before>"""Command line interface for facebook downloader"""

import logging
from functools import partial

import click
from facebook_downloader import config, downloader


def config_option(config_function):
    """Helper decorator that turns an option function into a cli option"""
    return (lambda function: click.option('--' + config_function.__name__,
                                          help=config_function.__doc__.strip() + '. Example: "' +
                                               config_function() + '"')(function))


def apply_options(kwargs):
    """Applies passed cli parameters to config.py"""
    for key, value in kwargs.items():
        if value: setattr(config, key, partial(lambda v: v, value))


@click.command()
@config_option(config.app_id)
@config_option(config.app_secret)
@config_option(config.access_token)
@config_option(config.data_dir)
@config_option(config.first_date)
@config_option(config.redownload_window)
@config_option(config.target_accounts)
def download_data(**kwargs):
    """
    Downloads data.
    When options are not specified, then the defaults from config.py are used.
    """
    apply_options(kwargs)
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
    downloader.download_data()
<commit_msg>Import facebook api only when downloader is run (to improve startup speed of apps that use this library)<commit_after>"""Command line interface for facebook downloader"""

import logging
from functools import partial

import click
from facebook_downloader import config


def config_option(config_function):
    """Helper decorator that turns an option function into a cli option"""
    return (lambda function: click.option('--' + config_function.__name__,
                                          help=config_function.__doc__.strip() + '. Example: "' +
                                               config_function() + '"')(function))


def apply_options(kwargs):
    """Applies passed cli parameters to config.py"""
    for key, value in kwargs.items():
        if value: setattr(config, key, partial(lambda v: v, value))


@click.command()
@config_option(config.app_id)
@config_option(config.app_secret)
@config_option(config.access_token)
@config_option(config.data_dir)
@config_option(config.first_date)
@config_option(config.redownload_window)
@config_option(config.target_accounts)
def download_data(**kwargs):
    """
    Downloads data.
    When options are not specified, then the defaults from config.py are used.
    """
    from facebook_downloader import downloader

    apply_options(kwargs)
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
    downloader.download_data()

{'fraction_non_alphanumeric': 0.1081179468511103, 'fraction_numerical': 0.0, 'mean_word_length': 3.754325259515571, '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': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1431216', 'n_tokens_mistral': 763, 'n_tokens_neox': 746, 'n_words': 204}