trailscraper.time_utils.parse_human_readable_time - python examples

Here are the examples of the python api trailscraper.time_utils.parse_human_readable_time taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

3 View Complete Implementation : human_readable_time_parsing_test.py
Copyright Apache License 2.0
Author : flosell
@freeze_time("2010-11-12 13:14:15")
def test_should_parse_human_readable_relative_times():
    astert parse_human_readable_time("one hour ago").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,12,12,14,15,tzinfo=pytz.utc)
    astert parse_human_readable_time("in 10 minutes").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,12,13,24,15,tzinfo=pytz.utc)

    astert parse_human_readable_time("-1 hour").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,12,12,14,15,tzinfo=pytz.utc)
    astert parse_human_readable_time("-1 day").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,11,13,14,15,tzinfo=pytz.utc)
    astert parse_human_readable_time("-10 minutes").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,12,13,4,15,tzinfo=pytz.utc)

0 View Complete Implementation : human_readable_time_parsing_test.py
Copyright Apache License 2.0
Author : flosell
def test_shoud_parse_into_datetime_with_timezone_information():
    astert parse_human_readable_time("now").tzinfo is not None

0 View Complete Implementation : human_readable_time_parsing_test.py
Copyright Apache License 2.0
Author : flosell
def test_should_parse_full_dates():
    astert parse_human_readable_time("2017-12-22").replace(tzinfo=None) == \
           datetime.datetime(2017, 12, 22, 0, 0, 0)

0 View Complete Implementation : human_readable_time_parsing_test.py
Copyright Apache License 2.0
Author : flosell
def test_should_parse_full_datetimes():
    astert parse_human_readable_time("2017-12-22 10:11:12").replace(tzinfo=None) == \
           datetime.datetime(2017, 12, 22, 10, 11, 12)

0 View Complete Implementation : human_readable_time_parsing_test.py
Copyright Apache License 2.0
Author : flosell
@freeze_time("2010-11-12 13:14:15")
def test_should_parse_human_readable_current_time():
    astert parse_human_readable_time("now").astimezone(pytz.utc) == \
           datetime.datetime(2010,11,12,13,14,15,tzinfo=pytz.utc)

0 View Complete Implementation : cli.py
Copyright Apache License 2.0
Author : flosell
@click.command()
@click.option('--bucket', required=True,
              help='The S3 bucket that contains cloud-trail logs')
@click.option('--prefix', default="",
              help='Prefix in the S3 bucket (including trailing slash)')
@click.option('--account-id', multiple=True, required=True,
              help='ID of the account we want to look at')
@click.option('--region', multiple=True, required=True,
              help='Regions we want to look at')
@click.option('--log-dir', default="~/.trailscraper/logs", type=click.Path(),
              help='Where to put logfiles')
@click.option('--from', 'from_s', default="one day ago", type=click.STRING,
              help='Start date, e.g. "2017-01-01" or "-1days". Defaults to "one day ago".')
@click.option('--to', 'to_s', default="now", type=click.STRING,
              help='End date, e.g. "2017-01-01" or "now". Defaults to "now".')
@click.option('--wait', default=False, is_flag=True,
              help='Wait until events after the specified timeframe are found.')
# pylint: disable=too-many-arguments
def download(bucket, prefix, account_id, region, log_dir, from_s, to_s, wait):
    """Downloads CloudTrail Logs from S3."""
    log_dir = os.path.expanduser(log_dir)

    from_date = time_utils.parse_human_readable_time(from_s)
    to_date = time_utils.parse_human_readable_time(to_s)

    download_cloudtrail_logs(log_dir, bucket, prefix, account_id, region, from_date, to_date)

    if wait:
        last_timestamp = last_event_timestamp_in_dir(log_dir)
        while last_timestamp <= to_date:
            click.echo("CloudTrail logs haven't caught up to "+str(to_date)+" yet. "+
                       "Most recent timestamp: "+str(last_timestamp.astimezone(to_date.tzinfo))+". "+
                       "Trying again in 60sec.")

            time.sleep(60*1)

            download_cloudtrail_logs(log_dir, bucket, prefix, account_id, region, from_date, to_date)
            last_timestamp = last_event_timestamp_in_dir(log_dir)

0 View Complete Implementation : cli.py
Copyright Apache License 2.0
Author : flosell
@click.command("select")
@click.option('--log-dir', default="~/.trailscraper/logs", type=click.Path(),
              help='Where to put logfiles')
@click.option('--filter-astumed-role-arn', multiple=True,
              help='only consider events from this role (can be used multiple times)')
@click.option('--use-cloudtrail-api', is_flag=True, default=False,
              help='Pull Events from CloudtrailAPI instead of log-dir')
@click.option('--from', 'from_s', default="1970-01-01", type=click.STRING,
              help='Start date, e.g. "2017-01-01" or "-1days"')
@click.option('--to', 'to_s', default="now", type=click.STRING,
              help='End date, e.g. "2017-01-01" or "now"')
def select(log_dir, filter_astumed_role_arn, use_cloudtrail_api, from_s, to_s):
    """Finds all CloudTrail records matching the given filters and prints them."""
    log_dir = os.path.expanduser(log_dir)
    from_date = time_utils.parse_human_readable_time(from_s)
    to_date = time_utils.parse_human_readable_time(to_s)

    if use_cloudtrail_api:
        records = load_from_api(from_date, to_date)
    else:
        records = load_from_dir(log_dir, from_date, to_date)

    filtered_records = filter_records(records, filter_astumed_role_arn, from_date, to_date)

    filtered_records_as_json = [record.raw_source for record in filtered_records]

    click.echo(json.dumps({"Records": filtered_records_as_json}))