Add mf2, a handy little filter for invoking the mf2py parser from the command line - especially cool in combination with jq
This commit is contained in:
parent
65a479aba3
commit
9fda00f465
1 changed files with 22 additions and 0 deletions
22
local/bin/mf2
Executable file
22
local/bin/mf2
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/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:
|
||||||
|
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)
|
Loading…
Reference in a new issue