Exemplo n.º 1
0
Arquivo: cli.py Projeto: zogzog/rework
def abort_task(dburi, taskid):
    """ immediately abort the given task

    This will be done by doing a preemptive kill on
    its associated worker.
    """
    engine = create_engine(find_dburi(dburi))
    task = Task.byid(engine, taskid)
    task.abort()


@rework.command('vacuum')
@click.argument('dburi')
@click.option('--workers', is_flag=True, default=False)
@click.option('--tasks', is_flag=True, default=False)
@click.option('--finished', type=click.DateTime())
def vacuum(dburi, workers=False, tasks=False, finished=None):
    " delete non-runing workers or finished tasks "
    if not (workers or tasks):
        print('to cleanup old workers or tasks '
              'please use --workers or --tasks')
        return
    if workers and tasks:
        print('vacuum deletes workers or tasks, not both ' 'at the same time')
        return

    engine = create_engine(find_dburi(dburi))
    if finished is None:
        finished = utcnow()
    if workers:
        count = cleanup_workers(engine, finished)
Exemplo n.º 2
0
                print(detail.format(location, "None", **field_widths))
            else:
                for start, end in date_ranges:
                    print(
                        detail.format(
                            location, f'{start} to {end}'
                            if start and end else str(start), **field_widths))
                    location = ""
    _log.debug(f'{overall}.')


@cli.command("rh")
@click.option('-s',
              '--start',
              'start',
              type=click.DateTime(formats=["%Y-%m-%d"]),
              metavar='START',
              help="The history start date (ISO format).")
@click.option('-e',
              '--end',
              'end',
              nargs=1,
              type=click.DateTime(formats=["%Y-%m-%d"]),
              metavar='END',
              help="The history end date (ISO format).")
@click.argument('location_name', nargs=1, metavar='LOCATION')
@click.pass_obj
def report_history(database: db.Database, location_name: str, start: datetime,
                   end: datetime):
    """Get history from a locations weather data. LOCATION can be either the location name or alias name."""
    overall = StopWatch("rh overall time", in_ms=True)
Exemplo n.º 3
0
                f"gdal_calc.py --quiet -A {f} -B {mask_fname} --outfile=tmp_out.tif "
                f' --calc="A * B " --NoDataValue=0')
            _log_and_run(cmd)
            _log_and_run(f"mv tmp_out.tif {f}")
            _log_and_run(
                f"rm {mask_fname} {mask_fname.replace('.bin', '.hdr')}")


@cli.command("subset")
@click.option("--bbox",
              nargs=4,
              type=float,
              help="Window lat/lon bounds: left bot right top")
@click.option("--out-dir", "-o", type=click.Path(exists=True))
@click.option("--in-dir", "-i", type=click.Path(exists=True))
@click.option("--start-date", "-s", type=click.DateTime(formats=["%Y-%m-%d"]))
@click.option("--end-date", "-e", type=click.DateTime(formats=["%Y-%m-%d"]))
def subset(bbox, out_dir, in_dir, start_date, end_date):
    """Read window subset from .geos in another directory

    Writes the smaller .geos to `outpath`, along with the
    extra files going with it (elevation.dem, .orbtimings)
    """
    import apertools.sario
    from apertools.utils import force_symlink
    import apertools.subset

    if abspath(out_dir) == abspath(in_dir):
        raise ValueError("--in-dir cannot be same as --out-dir")

    # dems:
Exemplo n.º 4
0
from kraken_ore_generator.top_of_book import tob_generation


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


@cli.command("ore")
@click.option("--query_url",
              "-q",
              type=click.STRING,
              help="CDM Metadata Query Service URL")
@click.option("--date",
              "-d",
              type=click.DateTime(["%Y-%m-%d"]),
              help="Date to process")
@click.option("--pair",
              "-p",
              type=click.STRING,
              help="Name of currency pair to process")
@click.option("--ore_path",
              "-op",
              type=click.STRING,
              help="Path to write ORE file")
@click.option("--state_path",
              "-sp",
              type=click.STRING,
              help="Path to write next state file")
@click.option("--extractor-license-path",
              "-ep",
Exemplo n.º 5
0
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import click
from ack.readers.google_search_console.reader import GoogleSearchConsoleReader
from ack.utils.args import extract_args
from ack.utils.date_handler import DEFAULT_DATE_RANGE_FUNCTIONS
from ack.utils.processor import processor


@click.command(name="read_search_console")
@click.option("--search-console-client-id", required=True)
@click.option("--search-console-client-secret", required=True)
@click.option("--search-console-access-token", default="")
@click.option("--search-console-refresh-token", required=True)
@click.option("--search-console-dimensions", required=True, multiple=True)
@click.option("--search-console-site-url", required=True)
@click.option("--search-console-start-date", type=click.DateTime(), default=None)
@click.option("--search-console-end-date", type=click.DateTime(), default=None)
@click.option("--search-console-date-column", type=click.BOOL, default=False)
@click.option("--search-console-row-limit", type=click.INT, default=25000)
@click.option(
    "--search-console-date-range",
    type=click.Choice(DEFAULT_DATE_RANGE_FUNCTIONS.keys()),
    help=f"One of the available ACK default date ranges: {DEFAULT_DATE_RANGE_FUNCTIONS.keys()}",
)
@processor()
def google_search_console(**params):
    return GoogleSearchConsoleReader(**extract_args("search_console_", params))
Exemplo n.º 6
0
def get_click_type(*, annotation: Any,
                   parameter_info: ParameterInfo) -> click.ParamType:
    if annotation == str:
        return click.STRING
    elif annotation == int:
        if parameter_info.min is not None or parameter_info.max is not None:
            min_ = None
            max_ = None
            if parameter_info.min is not None:
                min_ = int(parameter_info.min)
            if parameter_info.max is not None:
                max_ = int(parameter_info.max)
            return click.IntRange(min=min_,
                                  max=max_,
                                  clamp=parameter_info.clamp)
        else:
            return click.INT
    elif annotation == float:
        if parameter_info.min is not None or parameter_info.max is not None:
            return click.FloatRange(
                min=parameter_info.min,
                max=parameter_info.max,
                clamp=parameter_info.clamp,
            )
        else:
            return click.FLOAT
    elif annotation == bool:
        return click.BOOL
    elif annotation == UUID:
        return click.UUID
    elif annotation == datetime:
        return click.DateTime(formats=parameter_info.formats)
    elif (annotation == Path or parameter_info.allow_dash
          or parameter_info.path_type or parameter_info.resolve_path):
        return click.Path(  # type: ignore
            exists=parameter_info.exists,
            file_okay=parameter_info.file_okay,
            dir_okay=parameter_info.dir_okay,
            writable=parameter_info.writable,
            readable=parameter_info.readable,
            resolve_path=parameter_info.resolve_path,
            allow_dash=parameter_info.allow_dash,
            path_type=parameter_info.path_type,
        )
    elif lenient_issubclass(annotation, TextFile):
        return click.File(
            mode=parameter_info.mode or "r",
            encoding=parameter_info.encoding,
            errors=parameter_info.errors,
            lazy=parameter_info.lazy,
            atomic=parameter_info.atomic,
        )
    elif lenient_issubclass(annotation, BinaryFileRead):
        return click.File(
            mode=parameter_info.mode or "rb",
            encoding=parameter_info.encoding,
            errors=parameter_info.errors,
            lazy=parameter_info.lazy,
            atomic=parameter_info.atomic,
        )
    elif lenient_issubclass(annotation, BinaryFileWrite):
        return click.File(
            mode=parameter_info.mode or "wb",
            encoding=parameter_info.encoding,
            errors=parameter_info.errors,
            lazy=parameter_info.lazy,
            atomic=parameter_info.atomic,
        )
    elif lenient_issubclass(annotation, Enum):
        return click.Choice(
            [item.value for item in annotation],
            case_sensitive=parameter_info.case_sensitive,
        )
    raise RuntimeError(f"Type not yet supported: {annotation}")
Exemplo n.º 7
0
        if res.status_code == 200:
            click.echo('User is now logged out')
        else:
            click.echo(res.text)

    else:
        click.echo('No user is logged in')


@main.command(name='ActualTotalLoad', help='Actual total energy load consumed in an area')
@click.option('--area', '-a', required=True, type=str, help='Area of interest')
@click.option('--timeres', '-t', required=True, type=str,
              help='Timeres for the data, can be one of PT15M, PT30M or PT60M')
@optgroup.group('Date', cls=RequiredMutuallyExclusiveOptionGroup,
                help='Date of interest, can be either a date of the form YYYY-MM-DD, month of form YYYY-MM or year of form YYYY')
@optgroup.option('--date', '-d', type=click.DateTime(formats=['%Y-%m-%d']))
@optgroup.option('--month', '-m', type=click.DateTime(formats=["%Y-%m"]))
@optgroup.option('--year', '-y', type=click.DateTime(formats=["%Y"]))
@click.option('--format', '-f', default='json',
              help='Format in which the data appears, can be either json (default) or csv')
def ActualTotalLoad(area, timeres, date, month, year, format):
    if date != None:
        mydate = date.strftime("%Y-%m-%d")
        datetype = 'date'
    elif month != None:
        mydate = month.strftime("%Y-%m")
        datetype = 'month'
    elif year != None:
        mydate = year.strftime("%Y")
        datetype = 'year'
    else:
Exemplo n.º 8
0
 def __init__(self, separator: str = ',', formats: List[str] = None):
     super().__init__(click.DateTime(formats=formats),
                      separator=separator,
                      name='datetimes')
PYTHON_MIN_VERSION = (3, 6)
APP_NAME = 'poc'  # Created in the template


@click.command()
@click.option(
    '-c',
    '--config',
    required=True,
    type=str,
    help='Location of Configuration.\ngs://[bucket]/[config]\n/full/local/path)'
)
@click.option('-sd',
              '--start_date',
              required=False,
              type=click.DateTime(formats=['%Y%m%d']))
@click.option('-ed',
              '--end_date',
              required=False,
              type=click.DateTime(formats=['%Y%m%d']))
@click.option('-b', '--backfill', required=False, is_flag=True)
def instantiate_etl_runner(config, start_date, end_date, backfill):

    runner = ETLRunner(APP_NAME, config, ETLPipeline)
    runner.run(start_date, end_date, backfill)


if __name__ == "__main__":
    assert tuple(
        sys.version_info
    ) >= PYTHON_MIN_VERSION, "Please update to Python {}.{}".format(
Exemplo n.º 10
0
def log(core, **kwargs):
    interactive = kwargs.pop('interactive', False)
    params = {k: v for k, v in kwargs.items() if v}

    if 'today' in params and 'date' in params:
        raise click.BadParameter('Must specify exactyl one of date and today')

    if 'today' in params:
        params['session_date'] = date.today()
        del params['today']

    if 'exercise' not in params:
        interactive = True
        params['exercise'] = click.prompt(
                'enter an exercise (existing options: {})'.format(
                    ', '.join(core.all_exercises())), str)

    if interactive or ('session_date' not in params
                       or not params['session_date']):
        if (click.prompt(
                "Did you do the workout today?",
                default=False, type=bool
           )):
            params['session_date'] = date.today()
        else:
            params['session_date'] = click.prompt(
                    "When did you do the workout?",
                    type=click.DateTime()
            )

    if interactive and 'sets' not in params:
        reps = click.prompt("sets?", type=int, default=0)
        if reps:
            params['reps'] = reps

    if interactive and 'reps' not in params:
        c = click.prompt("reps per set?", type=int, default=0)
        if c:
            params['reps'] = c

    if interactive and 'duration' not in params:
        c = click.prompt("duration?", type=str, default=0)
        if c:
            params['duration'] = validator(core, "duration", c)

    if interactive and 'failure' not in params:
        c = click.prompt("failure", type=bool, default=False)
        if c:
            params['failure'] = c

    if params.get('duration', None):
        dt = params['duration']
        params['duration'] = timedelta(
                hours=dt.hour,
                minutes=dt.minute,
                seconds=dt.second)

    session = Session(**params)
    if click.confirm('save ' + str(session) + '?"'):
        for result in core.insert(session):
            click.echo(result)
    else:
        click.echo('aborted')
Exemplo n.º 11
0
import logging

from google.cloud import bigquery

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

COUNTRIES = [
    'Worldwide', 'United States', 'Germany', 'France', 'India', 'Brazil',
    'China', 'Indonesia', 'Russia', 'Italy', 'Poland'
]

# migrated from https://github.com/mozilla/Fx_Usage_Report/tree/489ca258b14776c01f3021080b2dd686d239dea3/usage_report/annotations # noqa
STATIC_ANNOTATIONS = ["annotations_webusage.json", "annotations_hardware.json"]

date_type = click.DateTime()


@click.command()
@click.option(
    "--date_to",
    type=date_type,
    required=True,
    help="End date for producing version release dates",
)
@click.option('--output_bucket', required=True)
@click.option('--output_prefix', required=True)
def main(date_to, output_bucket, output_prefix):
    """Export annotations to S3"""

    client = bigquery.Client()
Exemplo n.º 12
0
from lift import util


from datetime import datetime, date, timedelta

formats = util.listing_query_date_formats


@click.group()
@click.pass_context
def cli(ctx, **kwargs):
    ctx.obj = core.create()


@click.option('-t', '--time', 'duration',
              type=click.DateTime(formats=util.duration_formats),
              default=None)
@click.option('-p', '--rpe', 'effort',
              type=click.IntRange(
                  min=util.rpe_range[0],
                  max=util.rpe_range[1]
              ),
              default=None)
@click.option('-s', '--sets',
              type=click.INT,
              default=None)
@click.option('-r', '--reps', type=click.INT, default=None)
@click.option('-w', '--weight', type=click.FLOAT, default=None)
@click.option('-d', '--date', 'session_date',
              type=click.DateTime())
@click.option('-e', '--exercise', type=str)
Exemplo n.º 13
0
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--format',
              '-f',
              prompt=True,
              default='csv',
              type=click.Choice(['json', 'csv', 'mongo', 'all', 'none']))
@click.option('--outdir',
              '-o',
              prompt=True,
              type=click.Path(),
              default=lambda: os.getcwd() + '/out')
@click.option('--date',
              '-d',
              prompt=True,
              type=click.DateTime(formats=['%Y-%m-%d']),
              default=lambda: str(datetime.datetime.now())[:10])
@click.argument('input_dirs', nargs=-1, type=click.Path(exists=True))
def cli(format, outdir, date, input_dirs):
    """
    excel-shred  Version 1.0.0

    Open an Excel workbook, and convert all sheets to json datasets
    :param date: the date of the input audit
    :param outdir: output directory for files
    :param format: the output format
    :param input_dirs: one or more directory paths containing excel workbooks

    Examples:

    \b
Exemplo n.º 14
0
@pass_script_info
def run_server(info):
    app = info.load_app()
    Limiter(
        app,
        key_func=get_ipaddr,
        default_limits=config.config.rate_limit
    )
    if config.config.allow_cors:
        CORS(app)
    serve(app, host=config.config.host, port=config.config.port, url_prefix=config.config.base_url)


@cli.command("generate", help="generate new token")
@click.option("-o", "--one-time", is_flag=True, help="make token one-time-useable")
@click.option("-e", "--expires", type=click.DateTime(formats=["%Y-%m-%d"]), default=None, help='expire date: in ISO-8601 format (YYYY-MM-DD)')
def generate_token(one_time, expires):
    token = tokens.tokens.new(ex_date=expires, one_time=one_time)
    print(token.name)


@cli.command("status", help="view status or disable")
@click.option("-s", "--status", default=None, help="token status")
@click.option("-l", "--list", is_flag=True, help="list tokens")
@click.option("-d", "--disable", default=None, help="disable token")
def status_token(status, list, disable):
    if disable:
        if tokens.tokens.disable(disable):
            print("Token disabled")
        else:
            print("Token couldn't be disabled")
Exemplo n.º 15
0
from functools import partial
import click
import numpy as np
import os

from desafio_iafront.data.saving import save_partitioned
from desafio_iafront.jobs.clusters.clusters import dbscan
from desafio_iafront.data.dataframe_utils import read_partitioned_json
from desafio_iafront.jobs.common import filter_date


@click.command()
@click.option('--dataset', type=click.Path(exists=True))
@click.option('--saida',
              type=click.Path(exists=False, dir_okay=True, file_okay=False))
@click.option('--data-inicial', type=click.DateTime(formats=["%d/%m/%Y"]))
@click.option('--data-final', type=click.DateTime(formats=["%d/%m/%Y"]))
@click.option('--eps', type=click.FLOAT)
@click.option('--samples', type=click.INT)
def main(dataset: str, eps: float, samples: int, saida: str, data_inicial,
         data_final):

    filter_function = partial(filter_date,
                              data_inicial=data_inicial,
                              data_final=data_final)

    dataset = read_partitioned_json(file_path=dataset,
                                    filter_function=filter_function)
    vector = np.asarray(list(dataset['features'].to_numpy()))

    labels = dbscan(vector, eps, samples)
Exemplo n.º 16
0
    flatlib.const.MERCURY: "☿",
    flatlib.const.VENUS: "♀",
    flatlib.const.MARS: "♂",
    flatlib.const.JUPITER: "♃",
    flatlib.const.SATURN: "♄",
}


def convert_into_stupid_flatlib_format(dt):
    return Datetime(dt.strftime("%Y/%m/%d"), dt.strftime("%H:%M"))


@click.command()
@click.option("--latitude", type=click.FLOAT, required=True)
@click.option("--longitude", type=click.FLOAT, required=True)
@click.option("--date", type=click.DateTime(), default=datetime.now())
def main(latitude: float, longitude: float, date: datetime):
    flatlib_datetime = convert_into_stupid_flatlib_format(date)
    position = GeoPos(latitude, longitude)
    chart = Chart(flatlib_datetime, position)
    for planet in planet_symbols.keys():
        planet_position = chart.getObject(planet)
        print(
            planet_symbols[planet],
            sign_symbols[planet_position.sign],
            "℞"
            if planet_position.movement() == flatlib.const.RETROGRADE else "",
            end="",
        )
    print()
Exemplo n.º 17
0
              help="Number of failed updates before a video is not checked for updates any more.")
@click.option("--max-backlog", "-b", type=click.INT,
              help="Number of videos in a playlist that are checked for updates.")
@pass_ytcc
def update(ytcc: core.Ytcc, max_fail: Optional[int], max_backlog: Optional[int]):
    """Check if new videos are available.

    Downloads metadata of new videos (if any) without playing or downloading the videos.
    """
    ytcc.update(max_fail, max_backlog)


common_list_options = [
    click.Option(["--tags", "-c"], type=CommaList(str),
                 help="Listed videos must be tagged with one of the given tags."),
    click.Option(["--since", "-s"], type=click.DateTime(["%Y-%m-%d"]),
                 default="1970-01-03",  # Minimum supported by .timestamp() on Windows
                 help="Listed videos must be published after the given date."),
    click.Option(["--till", "-t"], type=click.DateTime(["%Y-%m-%d"]),
                 default="3001-1-19",  # Maximum supported by .timestamp() on Windows (Y3K Bug)
                 help="Listed videos must be published before the given date."),
    click.Option(["--playlists", "-p"], type=CommaList(str),
                 help="Listed videos must be in on of the given playlists."),
    click.Option(["--ids", "-i"], type=CommaList(int),
                 help="Listed videos must have the given IDs."),
    click.Option(["--watched", "-w"], is_flag=True, default=False,
                 help="Only watched videos are listed."),
    click.Option(["--unwatched", "-u"], is_flag=True, default=False,
                 help="Only unwatched videos are listed."),
    click.Option(["--order-by", "-o"], type=(click.Choice(VideoAttr), click.Choice(Direction)),
                 multiple=True, help="Set the column and direction to sort listed videos.")
Exemplo n.º 18
0
              type=click.Choice(REPORT_TYPES),
              default=REPORT_TYPES[0])
@click.option(
    "--sa360-column",
    "sa360_columns",
    multiple=True,
    help="https://developers.google.com/search-ads/v2/report-types",
)
@click.option(
    "--sa360-saved-column",
    "sa360_saved_columns",
    multiple=True,
    help=
    "https://developers.google.com/search-ads/v2/how-tos/reporting/saved-columns",
)
@click.option("--sa360-start-date",
              type=click.DateTime(),
              help="Start date of the report")
@click.option("--sa360-end-date",
              type=click.DateTime(),
              help="End date of the report")
@click.option(
    "--sa360-date-range",
    type=click.Choice(DEFAULT_DATE_RANGE_FUNCTIONS.keys()),
    help=
    f"One of the available ACK default date ranges: {DEFAULT_DATE_RANGE_FUNCTIONS.keys()}",
)
@processor("sa360_access_token", "sa360_refresh_token", "sa360_client_secret")
def google_sa360(**kwargs):
    return GoogleSA360Reader(**extract_args("sa360_", kwargs))
Exemplo n.º 19
0
def grant(general_config,
          bob,
          bob_encrypting_key,
          bob_verifying_key,
          label,
          value,
          rate,
          expiration,
          m, n,
          character_options,
          config_file,
          force):
    """Create and enact an access policy for some Bob. """

    # Setup
    emitter = setup_emitter(general_config)
    ALICE = character_options.create_character(emitter, config_file, general_config.json_ipc)

    # Policy option validation
    if ALICE.federated_only:
        if any((value, rate)):
            message = "Can't use --value or --rate with a federated Alice."
            raise click.BadOptionUsage(option_name="--value, --rate", message=message)
    elif bool(value) and bool(rate):
        raise click.BadOptionUsage(option_name="--rate", message="Can't use --value if using --rate")

    # Grantee selection
    if bob and any((bob_encrypting_key, bob_verifying_key)):
        message = '--bob cannot be used with --bob-encrypting-key or --bob-veryfying key'
        raise click.BadOptionUsage(option_name='--bob', message=message)

    if bob:
        card = Card.load(identifier=bob)
        if card.character is not Bob:
            emitter.error('Grantee card is not a Bob.')
            raise click.Abort
        paint_single_card(emitter=emitter, card=card)
        if not force:
            click.confirm('Is this the correct grantee (Bob)?', abort=True)
        bob_encrypting_key = card.encrypting_key.hex()
        bob_verifying_key = card.verifying_key.hex()

    # Interactive collection follows:
    # TODO: Extricate to support modules
    # - Disclaimer
    # - Label
    # - Expiration Date & Time
    # - M of N
    # - Policy Value (ETH)

    # Policy Expiration
    # TODO: Remove this line when the time is right.
    paint_probationary_period_disclaimer(emitter)

    # Label
    if not label:
        label = click.prompt(f'Enter label to grant Bob {bob_verifying_key[:8]}', type=click.STRING)

    if not force and not expiration:
        if ALICE.duration_periods:
            # TODO: use a default in days or periods?
            expiration = maya.now() + timedelta(days=ALICE.duration_periods)  # default
            if not click.confirm(f'Use default policy duration (expires {expiration})?'):
                expiration = click.prompt('Enter policy expiration datetime', type=click.DateTime())
        else:
            # No policy duration default default available; Go interactive
            expiration = click.prompt('Enter policy expiration datetime', type=click.DateTime())

    # TODO: Remove this line when the time is right.
    enforce_probationary_period(emitter=emitter, expiration=expiration)

    # Policy Threshold and Shares
    if not n:
        n = ALICE.n
        if not force and not click.confirm(f'Use default value for N ({n})?', default=True):
            n = click.prompt('Enter total number of shares (N)', type=click.INT)
    if not m:
        m = ALICE.m
        if not force and not click.confirm(f'Use default value for M ({m})?', default=True):
            m = click.prompt('Enter threshold (M)', type=click.IntRange(1, n))

    # Policy Value
    policy_value_provided = bool(value) or bool(rate)
    if not ALICE.federated_only and not policy_value_provided:
        rate = ALICE.default_rate  # TODO #1709 - Fine tuning and selection of default rates
        if not force:
            default_gwei = Web3.fromWei(rate, 'gwei')
            prompt = "Confirm rate of {node_rate} gwei ({total_rate} gwei per period)?"
            if not click.confirm(prompt.format(node_rate=default_gwei, total_rate=default_gwei*n), default=True):
                interactive_rate = click.prompt('Enter rate per period in gwei', type=GWEI)
                # TODO: Validate interactively collected rate (#1709)
                click.confirm(prompt.format(node_rate=rate, total_rate=rate*n), default=True, abort=True)
                rate = Web3.toWei(interactive_rate, 'gwei')

    # Request
    grant_request = {
        'bob_encrypting_key': bob_encrypting_key,
        'bob_verifying_key': bob_verifying_key,
        'label': label,
        'm': m,
        'n': n,
        'expiration': expiration,
    }
    if not ALICE.federated_only:
        if value:
            grant_request['value'] = value
        elif rate:
            grant_request['rate'] = rate  # in wei

    if not force and not general_config.json_ipc:
        confirm_staged_grant(emitter=emitter, grant_request=grant_request)
    emitter.echo(f'Granting Access to {bob_verifying_key[:8]}', color='yellow')
    return ALICE.controller.grant(request=grant_request)
Exemplo n.º 20
0
            for page in scraper.find_all_pages(base_link_template.format(single_date=single_date)):
                writer.writerow([link_template.format(page=page, single_date=single_date)])


# find_all_pages(None, None)
# download_pages(None, None)
# scrape_pages(None, None)

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


@click.command()
@click.option('--file', default="/tmp/pages.csv", help='Destination file for pages to be written')
@click.option('--date-start', type = click.DateTime(formats=["%Y-%m-%d"]), default=str(date.today()), help='number of greetings')
@click.option('--date-end', type = click.DateTime(formats=["%Y-%m-%d"]), default=str(date.today()), help='number of greetings')
def find_all_pages(file, date_start, date_end):
    date_start = date_start.date()
    date_end = date_end.date()
    click.echo(f"Writing pages from {date_start} to {date_end} into {file}")
    with open(file, "a") as pages_file:
        writer = csv.writer(pages_file, delimiter=",")
        for single_date in daterange(date_start, date_end):
            base_link_template = "https://www.transfermarkt.co.uk/transfers/transfertagedetail/statistik/top/plus/0?land_id_ab=&land_id_zu=&leihe=true&datum={single_date}"
            link_template = "https://www.transfermarkt.co.uk/transfers/transfertagedetail/statistik/top/plus/1/page/{page}?land_id_ab=&land_id_zu=&leihe=true&datum={single_date}"
            for page in scraper.find_all_pages(base_link_template.format(single_date=single_date)):
                writer.writerow([link_template.format(page=page, single_date=single_date)])


@click.command()
Exemplo n.º 21
0
    for i in range(delta.days + 1):
        dates_range.append(first_date + timedelta(days=i))
    return dates_range


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


@cli.command()
@click.option(
    '--start-date',
    default=get_default_start_date,
    type=click.DateTime(formats=['%d/%m/%Y']),
)
@click.option(
    '--end-date',
    default=get_default_end_date,
    type=click.DateTime(formats=['%d/%m/%Y']),
)
@click.option(
    '--refetch-start-date',
    default=None,
    type=click.DateTime(formats=['%d/%m/%Y']),
)
@click.option(
    '--refetch-end-date',
    default=None,
    type=click.DateTime(formats=['%d/%m/%Y']),
Exemplo n.º 22
0
from datetime import date
import click


@click.group()
def cli():
    "Utility for http://b3.com.br datasets"


@cli.command()
@click.option("--date", type=click.DateTime(formats=["%Y-%m-%d"]))
@click.option("--chunk-size", type=int, default=10000)
def download(date, chunk_size):
    """Downloads quotes data"""
    print(date)
    if not date:
        import subprocess
        date = subprocess.getoutput("""echo $(curl --silent 'https://arquivos.b3.com.br/apinegocios/dates') | sed -e 's/"//g' -e 's/\[//g' -e 's/\]//g' | cut -d"," -f 1""")
    else:
        date = str(date)

    from b3_data import download
    download.download_tickercsv(date, chunk_size)
Exemplo n.º 23
0
    search_line = {"day": day, "suffix": suffix}
    r = mongo_client.bookmarks.coords.find_one(search_line)
    if r is None:
        with open(path.join(coords_dir, "default_coords.json")) as f:
            coords = json.load(f)
        r = {"coords": coords}
        mongo_client.bookmarks.coords.insert_one({**search_line, **r})
    return r["coords"]


def _ss(s):
    return s.split(" ")


@click.group()
@click.option("-d", "--day", type=click.DateTime(["%Y-%m-%d"]), default=datetime.now()+timedelta(days=2))
@click.option("--cache-folder", type=click.Path(), default=path.join(path.split(__file__)[0], ".cache"))
@click.option("--cpdf-executable", default="cpdf")
@click.option("--pdfs-folder", type=click.Path(), default=path.join(path.split(__file__)[0], "pdfs"))
@click.option("--pdf-template", type=click.Path(), default=path.join(path.split(__file__)[0], "pdfs", "test.pdf"))
@click.option("--suffix", default="")
@click.option("--mongo-url", envvar="MONGO_URL")
@click.pass_context
def bookmark(ctx, mongo_url, **kwargs):
    basic_config_kwargs = {"handlers": [logging.StreamHandler(), ], }
    if True:
        basic_config_kwargs["level"] = logging.INFO
    if True:
        now = datetime.now()
        log_file = f".logs/{kwargs['day'].strftime('%Y%m%d')}_{now.isoformat()}.log.txt"
        _handler = logging.FileHandler(log_file)
Exemplo n.º 24
0
def prepare_original_cli(source, destination):
    """Parse a file with a of participants, clean it up and save to json"""
    with open(source) as fp:
        lines = (line for line in fp)
        valid_lines = filter_usernames(lines)
        prepared_usernames = [prepare_username(uname) for uname in valid_lines]

    with open(destination, "w") as ofp:
        dump(prepared_usernames, ofp)


@cli.command("choose")
@click.argument(
    "participants", type=click.Path(exists=True, file_okay=True, dir_okay=False)
)
@click.argument("date", type=click.DateTime(formats=["%d-%m-%Y"]), required=False)
@click.option("--n", default=1, show_default=True)
def choose_winner_cli(participants, date, n):
    """Choose a winner from PARTICIPANTS while using DATE to count seed"""
    if date is None:
        date = get_date_from_filename(participants)
    with open(participants) as fp:
        raw_usernames = load(fp)
    hashed_participants = process_usernames(raw_usernames)
    hashed_winners = choose_winners(hashed_participants, date, n=n)
    participants = [prepare_username(uname) for uname in raw_usernames]
    winners = find_winners(hashed_winners, participants)
    click.echo(" ".join(winners))


@cli.command("prepare_hashed")
    show_default=True,
    help="Save footage to folder structure with format 'YYYY/MM/DD/camera_name/'",
)
@click.option(
    "--download-request-timeout",
    "download_timeout",
    default=60.0,
    show_default=True,
    help="Time to wait before aborting download request, in seconds",
)
@click.option(
    "--start",
    type=click.DateTime(
        formats=[
            "%Y-%m-%d",
            "%Y-%m-%dT%H:%M:%S",
            "%Y-%m-%d %H:%M:%S",
            "%Y-%m-%d %H:%M:%S%z",
        ]
    ),
    required=False,
    help=(
        "Download range start time. "
        # TODO(danielfernau): uncomment the next line as soon as the feature is implemented
        # "If omitted, the time of the first available recording for each camera will be used."
    ),
)
@click.option(
    "--end",
    type=click.DateTime(
        formats=[
            "%Y-%m-%d",
Exemplo n.º 26
0
    plot = sns.barplot(
        data=sorted_pd,
        x=group_field,
        y="count(DISTINCT CRAB_UserHN)",
        color="tab:blue",
    )
    fig.savefig(
        os.path.join(output_folder, f"{filename}.png"),
        bbox_inches="tight",
    )


@click.command()
@click.argument("start_date",
                nargs=1,
                type=click.DateTime(_VALID_DATE_FORMATS))
@click.argument("end_date", nargs=1, type=click.DateTime(_VALID_DATE_FORMATS))
@click.option(
    "--by",
    default="month",
    type=click.Choice(_VALID_BY),
    help="Either weekofyear or month",
)
@click.option(
    "--generate_plots",
    default=False,
    is_flag=True,
    help="Additional to the csv, generate the plot(s)",
)
@click.option("--output_folder",
              default="./output",
Exemplo n.º 27
0
              type=click.STRING,
              help='VAM code for dataset to process')
@click.option(
    '--interleave',
    is_flag=True,
    help='Interleave MOD13 & MYD13 products to MXD (only works for VIM!)')
@click.option('--parallel-tiles',
              type=click.INT,
              default=1,
              help='Number of tiles processed in parallel (default = 1)')
@click.option('--cleanup', is_flag=True, help='Remove collected HDF files')
@click.option('--force',
              is_flag=True,
              help='Force collect process not failing on corrupt inputs')
@click.option('--last-collected',
              type=click.DateTime(formats=['%Y%j']),
              help='Last collected date in julian format (YYYYDDD - %Y%j)')
@click.option("--tiles-required",
              type=click.STRING,
              help="Required tiles - supplied as csv list")
def cli(
    src_dir: str,
    targetdir: str,
    compression: str,
    vam_code: str,
    interleave: bool,
    parallel_tiles: int,
    cleanup: bool,
    force: bool,
    last_collected: datetime,
    tiles_required: str,
Exemplo n.º 28
0
device_guid_argument = click.argument("device-guid", type=str)

change_device_name_option = click.option(
    "--change-device-name",
    required=False,
    is_flag=True,
    default=False,
    help="""Prepend "deactivated_" and today's date to the name of any
    deactivated devices.""",
)

DATE_FORMAT = "%Y-%m-%d"
purge_date_option = click.option(
    "--purge-date",
    required=False,
    type=click.DateTime(formats=[DATE_FORMAT]),
    default=None,
    help="""The date on which the archive should be purged from cold storage in yyyy-MM-dd format.
    If not provided, the date will be set according to the appropriate org settings.""",
)


@devices.command()
@device_guid_argument
@change_device_name_option
@purge_date_option
@sdk_options()
def deactivate(state, device_guid, change_device_name, purge_date):
    """Deactivate a device within Code42. Requires the device GUID to deactivate."""
    _deactivate_device(state.sdk, device_guid, change_device_name, purge_date)
Exemplo n.º 29
0
@click.argument("command")
@click.argument("parameters", default=None, required=False)
def raw_command(dev: SmartDevice, module, command, parameters):
    """Run a raw command on the device."""
    import ast

    if parameters is not None:
        parameters = ast.literal_eval(parameters)
    res = dev._query_helper(module, command, parameters)
    click.echo(res)


@cli.command()
@pass_dev
@click.option("--year",
              type=click.DateTime(["%Y"]),
              default=None,
              required=False)
@click.option("--month",
              type=click.DateTime(["%Y-%m"]),
              default=None,
              required=False)
@click.option("--erase", is_flag=True)
def emeter(dev, year, month, erase):
    """Query emeter for historical consumption."""
    click.echo(click.style("== Emeter ==", bold=True))
    if not dev.has_emeter:
        click.echo("Device has no emeter")
        return

    if erase:
Exemplo n.º 30
0
@click.pass_context
@pass_project(migrate=True)
def schedule(project, ctx):
    ctx.obj["project"] = project
    ctx.obj["schedule_service"] = schedule_service = ScheduleService(project)


@schedule.command(short_help="[default] Add a new schedule")
@click.argument("name")
@click.argument("extractor")
@click.argument("loader")
@click.argument("interval")
@click.option("--transform",
              type=click.Choice(["skip", "only", "run"]),
              default="skip")
@click.option("--start-date", type=click.DateTime(), default=None)
@click.pass_context
def add(ctx, name, extractor, loader, transform, interval, start_date):
    """
    Add a new schedule

    \b
    NAME:\tThe schedule name, must be unique
    EXTRACTOR:\tWhich extractor should be used
    LOADER:\tWhich loader should be used
    INTERVAL:\tCron-like syntax to specify the schedule interval (@daily, @hourly, etc…)
    """

    project = ctx.obj["project"]
    schedule_service = ctx.obj["schedule_service"]