-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split a main file into two files and merge four functions into two.
- Loading branch information
1 parent
8f4d10c
commit f37b03e
Showing
7 changed files
with
97 additions
and
107 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"input": "./test2.md", | ||
"stylesheet": "", | ||
"lang": "CN" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import argparse | ||
import json | ||
import asstLib | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-v", "--version", action="version", | ||
version="%(prog)s 0.1", help="display tool name and version.") | ||
parser.add_argument( | ||
"-i", "--input", help="specify an input file or folder to be processed.") | ||
parser.add_argument('-l', '--lang', nargs='?', type=str, default='en=CA', | ||
help='Language of the document (default is en=CA)') | ||
parser.add_argument( | ||
"-c", "--config", help="specify a config file to be processed") | ||
args = parser.parse_args() | ||
input = args.input | ||
|
||
if args.config is not None: | ||
try: | ||
with open(args.config, "r", encoding="utf-8") as config_file: | ||
config = json.load(config_file) | ||
if "input" in config: | ||
input = config["input"] | ||
else: | ||
input = None | ||
if "lang" in config: | ||
args.lang = config["lang"] | ||
except FileNotFoundError: | ||
print(f'Error: File "{args.config}" cannot be found!') | ||
except json.JSONDecodeError: | ||
print(f'Error: File "{args.config} has invalid JSON syntax!" ') | ||
|
||
if input is None: | ||
print(f'Error: Input is not found! Please specify a file/folder to be processed.') | ||
exit() | ||
|
||
if (args.lang is not None): | ||
langlist = "".join(args.lang) | ||
lang = langlist.strip() | ||
|
||
all_files = [] | ||
folder = "" | ||
|
||
# output .md file | ||
if not input.endswith(".md"): | ||
# folder = input + "/" | ||
all_files = asstLib.get_files(folder) | ||
else: | ||
all_files.append(input) | ||
|
||
for file in all_files: | ||
file_path = folder + file | ||
title = asstLib.get_md_title(file_path) | ||
bodycont = asstLib.generate_md_content(file_path, title) | ||
html = asstLib.format_to_html(file, title, bodycont, lang) | ||
asstLib.output_result(file, html) | ||
|
||
# output .txt file | ||
if not input.endswith(".txt"): | ||
|
||
# folder = input + "/" | ||
all_files = asstLib.get_files(folder) | ||
else: | ||
all_files.append(input) | ||
|
||
for file in all_files: | ||
file_path = folder + file | ||
title = asstLib.get_txt_title(file_path) | ||
bodycont = asstLib.generate_txt_content(file_path, title) | ||
html = asstLib.format_to_html(file, title, bodycont, lang) | ||
asstLib.output_result(file, html) | ||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters