Exemple #1
0
def process_topic(file_path: str, topic_txt: str, url: str, extra_opt):
    try:
        mkdir_p(os.path.dirname(file_path))
    except Exception:
        raise
    # process TeX mode pieces
    topic_txt = convert_canonical_tex(topic_txt)
    topic_txt = replace_display_tex(topic_txt)
    topic_txt = replace_inline_tex(topic_txt)
    topic_txt = replace_dollar_tex(topic_txt)

    # do not touch time stamp if previously
    # an identical file already exists.
    jsonfile = f"{file_path}.json"
    if os.path.isfile(jsonfile):
        print(f"[exists]{jsonfile}")
        save_json(f"{file_prefix}.tmp", topic_txt, url)
        if filecmp.cmp(f"{file_prefix}.tmp", jsonfile):
            # two files are identical, do not touch
            print("[identical, no touch]")
            return
        else:
            print("[overwrite]")

    # two files are different, save files
    save_json(jsonfile, topic_txt, url)
    if extra_opt["save-preview"]:
        save_preview(f"{file_path}.html", topic_txt, url)
def process_post(post_id, post_txt, url):
    # decide sub-directory
    file_path = get_file_path(post_id)
    try:
        mkdir_p(os.path.dirname(file_path))
    except:
        raise
    # process TeX mode pieces
    post_txt = convert_canonical_tex(post_txt)
    post_txt = replace_display_tex(post_txt)
    post_txt = replace_inline_tex(post_txt)
    post_txt = replace_dollar_tex(post_txt)

    # do not touch time stamp if previously
    # an identical file already exists.
    jsonfile = file_path + ".json"
    if os.path.isfile(jsonfile):
        print('[exists]' + jsonfile)
        save_json(file_prefix + '.tmp', post_txt, url)
        if filecmp.cmp(file_prefix + '.tmp', jsonfile):
            # two files are identical, do not touch
            print('[identical, no touch]')
            return
        else:
            print('[overwrite]')

    # two files are different, save files
    save_json(jsonfile, post_txt, url)
    save_preview(file_path + '.html', post_txt, url)
Exemple #3
0
def process_post(
    post_id: int,
    post_txt: str,
    taglist: List[str],
    url: str,
    if_save_preview: bool,
):
    # decide sub-directory
    file_path = get_file_path(post_id)
    try:
        mkdir_p(os.path.dirname(file_path))
    except:
        raise
    # process TeX mode pieces
    post_txt = replace_display_tex(post_txt)
    post_txt = replace_inline_tex(post_txt)
    post_txt = replace_dollar_tex(post_txt)

    # do not touch time stamp if previously
    # an identical file already exists.
    jsonfile = f"{file_path}.json"
    if os.path.isfile(jsonfile):
        print(f"[exists]{jsonfile}")
        save_json(f"{file_prefix}.tmp", post_txt, taglist, url)
        if filecmp.cmp(f"{file_prefix}.tmp", jsonfile):
            # two files are identical, do not touch
            print("[identical, no touch]")
            return
        else:
            print("[overwrite]")

    # two files are different, save files
    save_json(jsonfile, post_txt, taglist, url)
    if if_save_preview:
        save_preview(f"{file_path}.html", post_txt, url)