|
| 1 | +import argparse |
| 2 | + |
| 3 | +import urlsresolver |
| 4 | + |
| 5 | +if __name__ == '__main__': |
| 6 | + args = argparse.ArgumentParser( |
| 7 | + prog='python -m urlsresolver', |
| 8 | + description='Urls resolver library. Allow you get real url of shortened.', |
| 9 | + version=".".join(map(str, urlsresolver.__version__)), |
| 10 | + ) |
| 11 | + args.add_argument('url') |
| 12 | + args.add_argument('-V', '--verbose', help='Verbose output', action='store_true') |
| 13 | + args.add_argument('-A', '--user-agent', help='Custom user agent') |
| 14 | + args.add_argument('-S', '--chunk-size', default=1500, metavar='SIZE', |
| 15 | + help='Length of fetched html block for testing meta redirects. Default 1500') |
| 16 | + args.add_argument('-H', '--history', help='Print redirection history', action='store_true') |
| 17 | + args.add_argument( |
| 18 | + '--remove_noscript', |
| 19 | + action='store_true', |
| 20 | + help='Remove <noscript>...</noscript> blocks from header html for meta redirects' |
| 21 | + ) |
| 22 | + args = args.parse_args() |
| 23 | + |
| 24 | + result = urlsresolver.resolve_url( |
| 25 | + args.url, |
| 26 | + user_agent=args.user_agent, |
| 27 | + chunk_size=args.chunk_size, |
| 28 | + history=args.verbose, |
| 29 | + remove_noscript=args.remove_noscript |
| 30 | + ) |
| 31 | + |
| 32 | + if not args.verbose: |
| 33 | + print result |
| 34 | + else: |
| 35 | + print 'Source:\n %s\n' % args.url |
| 36 | + print 'Expanded:\n %s\n' % result[0] |
| 37 | + |
| 38 | + if len(result[1]) > 1: |
| 39 | + print 'Redirects history:' |
| 40 | + for i, url in enumerate(result[1], start=1): |
| 41 | + print ' %s. %s' % (i, url) |
| 42 | + |
| 43 | + print '\nTotal %s redirects' % (len(result[1]) - 1) |
0 commit comments