From afe31e695aaec38c45a0acf750c98e3aca6ac7c8 Mon Sep 17 00:00:00 2001 From: pictuga Date: Sat, 21 Dec 2013 20:14:10 +0100 Subject: [PATCH] "json" arg to output json feed --- morss.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/morss.py b/morss.py index 2c8a41a..423c3a0 100644 --- a/morss.py +++ b/morss.py @@ -605,7 +605,7 @@ def Gather(url, cachePath, options): log(len(rss.items)) log(time.time() - startTime) - return rss.tostring(xml_declaration=True, encoding='UTF-8') + return rss if __name__ == '__main__': options = ParseOptions() @@ -676,6 +676,8 @@ if __name__ == '__main__': print 'Content-Type: text/plain' elif options.progress: print 'Content-Type: application/octet-stream' + elif options.json: + print 'Content-Type: application/json' else: print 'Content-Type: text/xml' print '' @@ -694,7 +696,13 @@ if __name__ == '__main__': RSS = Gather(url, cachePath, options) if RSS is not False and not options.progress and not DEBUG and not options.silent: - print RSS + if options.json: + if options.indent: + print json.dumps(RSS, sort_keys=True, indent=4, default=lambda x: dict(x)) + else: + print json.dumps(RSS, sort_keys=True, default=lambda x: dict(x)) + else: + print RSS.tostring(xml_declaration=True, encoding='UTF-8') if RSS is False and 'progress' not in options: print 'Error fetching feed.'