How to use the click.File function in click

To help you get started, we’ve selected a few click examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mcs07 / ChemDataExtractor / chemdataextractor / cli / evaluate.py View on Github external
@click.argument('input', type=click.File('r'))
def run(input):
    """"""
    pub = os.path.basename(input.name).split('.', 1)[0]
    if pub == 'rsc':
        reader = RscHtmlReader()
    elif pub == 'acs':
        reader = AcsHtmlReader()
    elif pub == 'springer':
        reader = NlmXmlReader()
    else:
        raise click.ClickException('Invalid publisher')
    doc = reader.read(input)
    # Serialize all records apart from those that are just chemical names or just labels
    records = [record.serialize(primitive=True) for record in doc.records]
    records = [record for record in records if not record.keys() == ['names'] and not record.keys() == ['labels']]
    with open('%s-out.json' % os.path.splitext(input.name)[0], 'w') as outf:
github sdague / mychevy / mychevy / cli.py View on Github external
@click.option('--config', '-c', type=click.File('r'),
              required=True,
              help="Config file with my.chevy credentials")
@click.option('--show-browser', '-S', is_flag=True,
              help="Show browser window when running")
def main(config=None, show_browser=None):
    """Console script for mychevy"""
    cfile = configparser.ConfigParser()
    cfile.read_file(config)

    page = MyChevy(cfile["default"]["user"], cfile["default"]["passwd"])
    click.echo("Loading data, this takes up to 2 minutes...")
    page.login()
    page.get_cars()
    cars = page.update_cars()
    for c in cars:
        click.echo(c)
github mcs07 / ChemDataExtractor / chemdataextractor / cli / __init__.py View on Github external
@click.option('--output', '-o', type=click.File('w', encoding='utf8'), help='Output file.', default=click.get_text_stream('stdout'))
@click.argument('input', type=click.File('rb'), default=click.get_binary_stream('stdin'))
@click.pass_obj
def read(ctx, input, output):
    """Output processed document elements."""
    log.info('chemdataextractor.read')
    log.info('Reading %s' % input.name)
    doc = Document.from_file(input)
    for element in doc.elements:
        output.write(u'%s : %s\n=====\n' % (element.__class__.__name__, six.text_type(element)))
github learntextvis / textkit / textkit / filter / filter_lengths.py View on Github external
@click.argument('tokens', type=click.File('r'), default=click.open_file('-'))
@click.option('-m', '--minimum', default=3,
              help='Minimum length of token to not filter.', show_default=True)
def filterlengths(minimum, tokens):
    '''Remove tokens that are shorter then the minimum length provided.'''
    content = read_tokens(tokens)
    [output(token) for token in content if len(token) >= minimum]
github simonw / sqlite-utils / sqlite_utils / cli.py View on Github external
def insert_upsert_options(fn):
    for decorator in reversed(
        (
            click.argument(
                "path",
                type=click.Path(file_okay=True, dir_okay=False, allow_dash=False),
                required=True,
            ),
            click.argument("table"),
            click.argument("json_file", type=click.File(), required=True),
            click.option(
                "--pk", help="Columns to use as the primary key, e.g. id", multiple=True
            ),
            click.option("--nl", is_flag=True, help="Expect newline-delimited JSON"),
            click.option("-c", "--csv", is_flag=True, help="Expect CSV"),
            click.option("--tsv", is_flag=True, help="Expect TSV"),
            click.option(
                "--batch-size", type=int, default=100, help="Commit every X records"
            ),
            click.option(
                "--alter",
                is_flag=True,
                help="Alter existing table to add any missing columns",
            ),
            click.option(
                "--not-null",
github neocities / python-neocities / neocities / neocli.py View on Github external
@click.argument("source", required=True, type=click.File("rb"))
@click.argument("destination", required=False)
def upload(source, destination):
    """Upload one or more files to a NeoCities site.
    Source refers to a local file.
    Destination refers to the remote file name and location.
    """
    if destination and "." not in destination:
        click.echo("Invalid target; specify a target path file extension.")
        return 1
    nc.upload((source.name, destination if destination else source.name))
github erayerdin / tgcli / tgcli / cli / bot / send.py View on Github external
"-y", "--longitude", type=click.FLOAT, required=True, help="Longitude of location.",
)
@click.pass_context
def location(ctx, latitude: float, longitude: float):
    session = tgcli.request.bot.BotSession(ctx.obj["token"])
    session.verify = ctx.obj["secure"]
    receiver = ctx.obj["receiver"]

    request = tgcli.request.bot.SendLocationRequest(
        session, receiver, latitude, longitude
    )

    send_message(session, request)


THUMBNAIL_OPTION = click.option("--thumbnail", type=click.File("rb"))
FILE_ARGUMENT = click.argument("file", type=click.File("rb"), required=True)
MESSAGE_OPTION = click.option(
    "-m",
    "--message",
    callback=validation.check_empty_string,
    help="The message to inline with file.",
)


@send.command()
@MESSAGE_OPTION
@THUMBNAIL_OPTION
@FILE_ARGUMENT
@click.pass_context
def document(ctx, message: str, thumbnail: io.BytesIO, file: io.BytesIO):
    session = tgcli.request.bot.BotSession(ctx.obj["token"])
github geneontology / go-site / graphstore / rule-runner / rulerunner / main.py View on Github external
@click.option("-o", "--out", type=click.File("w"))
def group(endpoint, rules_dir, schema, verbose, out) -> None:

    gorules_paths = glob.glob(os.path.join(rules_directory(path=rules_dir), "gorule-*.md"))
    rules = [load_yamldown(path) for path in gorules_paths if rule.sparql_from(load_yamldown(path))]
    s = schema if schema else SCHEMA
    results = []
    for r in rules:
        validate(r, s)
        result = rule.test_rule(r, endpoint)
        results.append(result)
        click.echo(result.short_summary())

        if result.returned and verbose:
            click.echo(result.verbose_readable())

    if out:
github mfranberg / svsim / svsim / commands / create_donor_contigs.py View on Github external
                    type=click.File('w'),
)
@click.option('-d', '--delimiter',
                    default='|',
                    help='The fasta identifier separator, default is "|".'
)
@click.option('-n', '--genome_name',
                    default='donor-genome',
                    help="The name of the genome."
)
@click.option('-i', '--field_index',
                    nargs=1,
                    default=0,
                    help='The 0-based index of field separated by field_sep that contains the relevant contig name.'
)
@click.option('-c', '--chrom',
                    nargs=1,