#!/usr/bin/python3

import json
import pathlib
import asyncio
import pynayzr
from argparse import ArgumentParser
from PIL import Image


def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--bc', action='store', type=str)
    parser.add_argument('--dir', action='store', type=str, required=True)
    parser.add_argument('-i')
    return parser


def main():
    args = get_parser().parse_args()

    support_news = list(pynayzr.streams.support_news.keys())
    if args.bc:
        pynayzr.ocr.set_bing_credentials(args.bc)
        parser = pynayzr.ocr.parse_by_bing
        aparser = pynayzr.ocr.parse_by_async_bing
    else:
        parser = pynayzr.ocr.parse_by_async_tesseract
        aparser = None

    nm = asyncio.run(
        pynayzr.core.async_analyze(support_news,
                                   parser=parser,
                                   aparser=aparser,
                                   parse=True))

    w, h = nm['tvbs'].img.size
    im = Image.new('RGB', (w * 3, h * 3), '#FFFFFF')
    for index, v in enumerate(nm.items()):
        news, model = v
        r = index // 3
        c = index % 3
        im.paste(model.img, (c * w, r * h))

    # Make dir
    dir_path = pathlib.Path(args.dir)
    dir_path.mkdir(parents=True, exist_ok=True)

    # Dump all
    im.save(dir_path.joinpath('wall.jpg'))
    for news, model in nm.items():
        # Dump img
        model.save_all(dir_path.joinpath(f'{news}.jpg'))

        # Dump text json
        json.dump(model.to_json(), open(dir_path.joinpath(f'{news}.json'), 'w'),
                  ensure_ascii=False, indent=4)


if __name__ == '__main__':
    main()

@@ -1444,24 +1444,20 @@
 f'%7Bnews%7D
-.jpg
 '))%0A
+
 %0A       
@@ -1486,34 +1486,12 @@
     
-json.dump(model.to_json(),
+with
  ope
@@ -1531,24 +1531,23 @@
 '), 'w')
-,%0A      
+ as f:%0A
         
@@ -1554,36 +1554,31 @@
     
-ensure_ascii=False, indent=4
+f.write(model.to_json()
 )%0A%0A%0A

Fix typo