From 9fda00f4659dda8c6c8f07c15e15480b196f487b Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Thu, 26 Oct 2017 16:02:49 +1100 Subject: [PATCH] Add mf2, a handy little filter for invoking the mf2py parser from the command line - especially cool in combination with jq --- local/bin/mf2 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 local/bin/mf2 diff --git a/local/bin/mf2 b/local/bin/mf2 new file mode 100755 index 0000000..cf7b6c6 --- /dev/null +++ b/local/bin/mf2 @@ -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)