set encoding
This commit is contained in:
parent
94cdab618b
commit
84114e6f68
|
@ -3,7 +3,6 @@
|
|||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from .consts import *
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ def write_card_templates(model_dir_path: str, templates: list[CardTemplate]) ->
|
|||
if not os.path.isdir(dir_path):
|
||||
os.mkdir(dir_path)
|
||||
for filename, content in zip((FRONT_FILENAME, BACK_FILENAME), (template.front, template.back)):
|
||||
with open(os.path.join(dir_path, filename), 'w') as f:
|
||||
with open(os.path.join(dir_path, filename), 'w', encoding='utf8') as f:
|
||||
f.write(content)
|
||||
|
||||
|
||||
|
@ -77,17 +77,17 @@ def save_note_type(model: NoteType):
|
|||
if not os.path.isdir(dir_path):
|
||||
os.mkdir(dir_path)
|
||||
|
||||
with open(json_path, 'w') as f:
|
||||
with open(json_path, 'w', encoding='utf8') as f:
|
||||
json.dump(format_export(model), f, indent=JSON_INDENT, ensure_ascii=False)
|
||||
|
||||
with open(css_path, 'w') as f:
|
||||
with open(css_path, 'w', encoding='utf8') as f:
|
||||
f.write(model.css)
|
||||
|
||||
write_card_templates(dir_path, model.templates)
|
||||
remove_deleted_templates(dir_path, [template.name for template in model.templates])
|
||||
|
||||
if not os.path.isfile(readme_path):
|
||||
with open(readme_path, 'w') as f:
|
||||
with open(readme_path, 'w', encoding='utf8') as f:
|
||||
f.write(f"# {model.name}\n\n*Description and screenshots here.*")
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from .consts import *
|
|||
|
||||
|
||||
def read_css(model_dir_name: str) -> str:
|
||||
with open(os.path.join(NOTE_TYPES_DIR, model_dir_name, CSS_FILENAME)) as f:
|
||||
with open(os.path.join(NOTE_TYPES_DIR, model_dir_name, CSS_FILENAME), encoding='utf8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
|
@ -19,13 +19,16 @@ def read_card_templates(model_dir_name: str, template_names: list[str]) -> list[
|
|||
templates = []
|
||||
for template_name in template_names:
|
||||
dir_path = os.path.join(NOTE_TYPES_DIR, model_dir_name, template_name)
|
||||
with open(os.path.join(dir_path, FRONT_FILENAME)) as front, open(os.path.join(dir_path, BACK_FILENAME)) as back:
|
||||
with (
|
||||
open(os.path.join(dir_path, FRONT_FILENAME), encoding='utf8') as front,
|
||||
open(os.path.join(dir_path, BACK_FILENAME), encoding='utf8') as back
|
||||
):
|
||||
templates.append(CardTemplate(template_name, front.read(), back.read()))
|
||||
return templates
|
||||
|
||||
|
||||
def read_model(model_dir_name: str) -> NoteType:
|
||||
with open(os.path.join(NOTE_TYPES_DIR, model_dir_name, JSON_FILENAME)) as f:
|
||||
with open(os.path.join(NOTE_TYPES_DIR, model_dir_name, JSON_FILENAME), encoding='utf8') as f:
|
||||
model_dict = json.load(f)
|
||||
|
||||
return NoteType(
|
||||
|
|
Loading…
Reference in a new issue