# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return
# 
# def build_query(filters):
#     return [tuple(f.split('=', 1)) for f in filters if '=' in f]


import json
import click
from tabulate import tabulate
from alertaclient.models.alert import Alert
from alertaclient.utils import DateTime, build_query
                    alert.customer or '-',
                    alert.environment,
                    ','.join(alert.service),
                    alert.resource,
                    alert.group,
                    alert.event,
                    alert.value or 'n/a'), fg=color['fg'])
                click.secho(f'   |{alert.text}', fg=color['fg'])

                if display == 'full':
                    click.secho('    severity   | {} -> {}'.format(alert.previous_severity,
                                                                   alert.severity), fg=color['fg'])
                    click.secho(f'    trend      | {alert.trend_indication}', fg=color['fg'])
                    click.secho(f'    status     | {alert.status}', fg=color['fg'])
                    click.secho(f'    resource   | {alert.resource}', fg=color['fg'])
                    click.secho(f'    group      | {alert.group}', fg=color['fg'])
                    click.secho(f'    event      | {alert.event}', fg=color['fg'])
                    click.secho(f'    value      | {alert.value}', fg=color['fg'])
                    click.secho('    tags       | {}'.format(' '.join(alert.tags)), fg=color['fg'])

                    for key, value in alert.attributes.items():
                        click.secho(f'    {key.ljust(10)} | {value}', fg=color['fg'])

                    latency = alert.receive_time - alert.create_time

                    click.secho('        time created  | {}'.format(
                        DateTime.localtime(alert.create_time, timezone)), fg=color['fg'])
                    click.secho('        time received | {}'.format(
                        DateTime.localtime(alert.receive_time, timezone)), fg=color['fg'])
                    click.secho('        last received | {}'.format(

# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return
# 
# def build_query(filters):
#     return [tuple(f.split('=', 1)) for f in filters if '=' in f]


# Path: alertaclient/commands/cmd_query.py
import json
import click
from tabulate import tabulate
from alertaclient.models.alert import Alert
from alertaclient.utils import DateTime, build_query

                    alert.customer or '-',
                    alert.environment,
                    ','.join(alert.service),
                    alert.resource,
                    alert.group,
                    alert.event,
                    alert.value or 'n/a'), fg=color['fg'])
                click.secho(f'   |{alert.text}', fg=color['fg'])

                if display == 'full':
                    click.secho('    severity   | {} -> {}'.format(alert.previous_severity,
                                                                   alert.severity), fg=color['fg'])
                    click.secho(f'    trend      | {alert.trend_indication}', fg=color['fg'])
                    click.secho(f'    status     | {alert.status}', fg=color['fg'])
                    click.secho(f'    resource   | {alert.resource}', fg=color['fg'])
                    click.secho(f'    group      | {alert.group}', fg=color['fg'])
                    click.secho(f'    event      | {alert.event}', fg=color['fg'])
                    click.secho(f'    value      | {alert.value}', fg=color['fg'])
                    click.secho('    tags       | {}'.format(' '.join(alert.tags)), fg=color['fg'])

                    for key, value in alert.attributes.items():
                        click.secho(f'    {key.ljust(10)} | {value}', fg=color['fg'])

                    latency = alert.receive_time - alert.create_time

                    click.secho('        time created  | {}'.format(
                        DateTime.localtime(alert.create_time, timezone)), fg=color['fg'])
                    click.secho('        time received | {}'.format(
                        DateTime.localtime(alert.receive_time, timezone)), fg=color['fg'])
                    click.secho('        last received | {}'.format(

                        DateTime.localtime(alert.last_receive_time, timezone)), fg=color['fg'])