Пример #1
0
def time_stamps_cli():
    """Print time_stampss informations."""
    cache = current_cache.get('timestamps')
    if cache:
        for key, value in cache.items():
            time = value.pop('time')
            args = [f'{k}={v}' for k, v in value.items()]
            click.echo(f'{time}: {key} {" | ".join(args)}')
Пример #2
0
def get_timestamp(name):
    """Get timestamp in current cache.

    :param name: name of time stamp.
    :returns: time of time stamp
    """
    time_stamps = current_cache.get('timestamps')
    if not time_stamps:
        return None
    return time_stamps.get(name)
Пример #3
0
def set_timestamp(name, **kwargs):
    """Set timestamp in current cache.

    Allows to timestamp functionality and monitoring of the changed
    timestamps externaly via url requests.

    :param name: name of time stamp.
    :returns: time of time stamp
    """
    time_stamps = current_cache.get('timestamps')
    if not time_stamps:
        time_stamps = {}
    utc_now = datetime.utcnow()
    time_stamps[name] = {}
    time_stamps[name]['time'] = utc_now
    for key, value in kwargs.items():
        time_stamps[name][key] = value
    current_cache.set('timestamps', time_stamps)
    return utc_now
Пример #4
0
def timestamps():
    """Get time stamps from current cache.

    Makes the saved timestamps accessible via url requests.

    :return: jsonified timestamps.
    """
    data = {}
    time_stamps = current_cache.get('timestamps')
    if time_stamps:
        for name, values in time_stamps.items():
            # make the name safe for JSON export
            name = name.replace('-', '_')
            data[name] = {}
            for key, value in values.items():
                if key == 'time':
                    data[name]['utctime'] = value.strftime("%Y-%m-%d %H:%M:%S")
                    data[name]['unixtime'] = time.mktime(value.timetuple())
                else:
                    data[name][key] = value

    return jsonify({'data': data})