|
|
|
@ -16,11 +16,6 @@ def parse_args():
|
|
|
|
|
default=False,
|
|
|
|
|
help="Increase logging verbosity to DEBUG.")
|
|
|
|
|
|
|
|
|
|
parser.add_argument('-u', '--url',
|
|
|
|
|
action='store',
|
|
|
|
|
default=None,
|
|
|
|
|
help="Indicate that this is a url path.")
|
|
|
|
|
|
|
|
|
|
parser.add_argument('path', metavar='P', type=str, nargs=1,
|
|
|
|
|
help="The url or file path to process in readable form.")
|
|
|
|
|
|
|
|
|
@ -31,19 +26,27 @@ def parse_args():
|
|
|
|
|
def main():
|
|
|
|
|
args = parse_args()
|
|
|
|
|
|
|
|
|
|
target = None
|
|
|
|
|
if args.url:
|
|
|
|
|
target = args.path[0]
|
|
|
|
|
|
|
|
|
|
if target.startswith('http') or target.startswith('www'):
|
|
|
|
|
is_url = True
|
|
|
|
|
url = target
|
|
|
|
|
else:
|
|
|
|
|
is_url = False
|
|
|
|
|
url = None
|
|
|
|
|
|
|
|
|
|
if is_url:
|
|
|
|
|
import urllib
|
|
|
|
|
target = urllib.urlopen(args.path[0])
|
|
|
|
|
target = urllib.urlopen(target)
|
|
|
|
|
else:
|
|
|
|
|
target = open(args.path[0], 'rt')
|
|
|
|
|
target = open(target, 'rt')
|
|
|
|
|
|
|
|
|
|
enc = sys.__stdout__.encoding or 'utf-8'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
doc = Document(target.read(),
|
|
|
|
|
debug=args.verbose,
|
|
|
|
|
url=args.url)
|
|
|
|
|
url=url)
|
|
|
|
|
print doc.summary().encode(enc, 'replace')
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|