Skip to content

Commit d6b5ac4

Browse files
committed
Added console module for shell usage
1 parent 5c665c2 commit d6b5ac4

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ Checks for meta refresh html tags & refresh http header.
77

88
# Installation
99

10-
You can install library as usual with `pip install urlsresolver`.
10+
You can install library as usual with `pip install urlsresolver`.
11+
12+
# Python module usage
13+
14+
Example of usage module as console utility.
15+
16+
> python -m urlsresolver http://t.co/dRW1iSInvA -V
17+
> Source:
18+
> http://t.co/dRW1iSInvA
19+
>
20+
> Expanded:
21+
> http://www.findelight.net/frenbull_detail.html?id=1078982008178233213_2206075018
22+
>
23+
> Redirects history:
24+
> 1. http://t.co/dRW1iSInvA
25+
> 2. http://www.findelight.net/frenbull_detail.html?id=1078982008178233213_2206075018
26+
>
27+
> Total 1 redirects
1128
1229

1330
# Contributon and contacts

urlsresolver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import requests
99

10-
__version__ = (1, 0, 1)
10+
__version__ = (1, 1, 0)
1111
__author__ = 'Alexandr Shurigin (https://github.com/phpdude/)'
1212

1313
# HTML tags syntax http://www.w3.org/TR/html-markup/syntax.html

urlsresolver/__main__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)