# 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()

[((32, 47), 'click.command', 'click.command', ([], {}), '()\n', (45, 47), False, 'import click\n'), ((49, 136), 'click.option', 'click.option', (['"""--carrier"""'], {'prompt': '"""Carrier ID"""', 'help': '"""Example: "ect" for Correios"""'}), '(\'--carrier\', prompt=\'Carrier ID\', help=\n    \'Example: "ect" for Correios\')\n', (61, 136), False, 'import click\n'), ((133, 211), 'click.option', 'click.option', (['"""--object-id"""'], {'prompt': '"""Object ID"""', 'help': '"""Example: PN871429404BR"""'}), "('--object-id', prompt='Object ID', help='Example: PN871429404BR')\n", (145, 211), False, 'import click\n'), ((358, 390), 'trackr.Trackr.track', 'Trackr.track', (['carrier', 'object_id'], {}), '(carrier, object_id)\n', (370, 390), False, 'from trackr import Trackr\n'), ((794, 836), 'click.style', 'click.style', (['u"""Package found!"""'], {'fg': '"""green"""'}), "(u'Package found!', fg='green')\n", (805, 836), False, 'import click\n')]