From 5e02e5912378213a7f64dc1cde92b0729e3fc74c Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Sat, 12 Oct 2019 18:49:19 +0530 Subject: [PATCH] utils: Add flag to store json. --- utils/housekeep.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/utils/housekeep.py b/utils/housekeep.py index 7f8d1f0..5dfb229 100644 --- a/utils/housekeep.py +++ b/utils/housekeep.py @@ -1,3 +1,5 @@ +import simplejson + # we assume that every line after # Books # starting with * is a book title if file type is old # starting with | (and not with | Name or |--) is a book if the file type is new @@ -26,6 +28,12 @@ try: action='store_true', default=False ) + parser.add_argument( + '--store-json', + dest='store-json', + action='store_true', + default=False + ) flags = parser.parse_args() except ImportError: flags = None @@ -49,14 +57,15 @@ def main(): input_file_type = flags.input_file_type or 'new' sort_by = flags.sort_by or 'rating' force = flags.force + store_json = flags.store_json reverse = True if sort_by == 'rating' else False library = load(in_file, input_file_type) get_goodread_info(library, force) library = sort(library, sort_by, reverse) render(in_file, out_file, library) - + if store_json: + with open("out.json", "w") as f: + f.write(simplejson.dumps(library, indent=4, sort_keys=True)) if __name__ == '__main__': main() - -