2017-10-26 01:02:49 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import mf2py
|
|
|
|
import sys
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
if not args:
|
|
|
|
args.append('-')
|
|
|
|
|
|
|
|
|
|
|
|
def parse(**kwargs):
|
|
|
|
return mf2py.Parser(html_parser='html5lib', **kwargs).to_json()
|
|
|
|
|
|
|
|
|
|
|
|
for arg in args:
|
2017-11-08 18:08:39 -05:00
|
|
|
if arg.startswith('//'):
|
|
|
|
arg = 'https:' + arg
|
2017-10-26 01:02:49 -04:00
|
|
|
if arg.startswith('http'):
|
|
|
|
doc = parse(url=arg)
|
|
|
|
elif arg == '-':
|
|
|
|
doc = parse(doc=sys.stdin)
|
|
|
|
else:
|
|
|
|
with open(arg, 'r') as f:
|
|
|
|
doc = parse(doc=f)
|
|
|
|
print(doc)
|