# coding: utf-8
import click


@click.command()
@click.option('--carrier', prompt='Carrier ID', help='Example: "ect" for Correios')
@click.option('--object-id', prompt='Object ID',
              help='Example: PN871429404BR')
def main(carrier, object_id):
    from trackr import Trackr
    from trackr.exceptions import PackageNotFound

    try:
        p = Trackr.track(carrier, object_id)
    except PackageNotFound as e:
        click.echo(click.style(
            u'Package with object ID {} ({}) not found'.format(
                object_id, carrier),
            fg='red')
        )

        if e.carrier_message:
            click.echo(click.style(
                u'Carrier message: {}'.format(e.carrier_message),
                fg='red',)
            )
        return

    click.echo(click.style(u'Package found!', fg='green'))

    for t in p.tracking_info:
        click.echo(t.__unicode__())


if __name__ == "__main__":
    main()

[((5, 1, 5, 16), 'click.command', 'click.command', ({}, {}), '()', False, 'import click\n'), ((6, 1, 6, 83), 'click.option', 'click.option', (), '', False, 'import click\n'), ((7, 1, 8, 44), 'click.option', 'click.option', (), '', False, 'import click\n'), ((14, 12, 14, 44), 'trackr.Trackr.track', 'Trackr.track', ({(14, 25, 14, 32): 'carrier', (14, 34, 14, 43): 'object_id'}, {}), '(carrier, object_id)', False, 'from trackr import Trackr\n'), ((29, 15, 29, 57), 'click.style', 'click.style', (), '', False, 'import click\n')]