Commit f6b99a06 authored by MatveiT's avatar MatveiT
Browse files

Add backup feature for the input lexique text

parent 38cc9347
......@@ -13,5 +13,7 @@ PARAMETERS = {
# Directory where to copy .pdf file after execution (set None if no need to copy it)
"copy_to_dir": None,
# url from where to fetch lexique text (set None to not fetch from an url)
"fetch_url": None
"fetch_url": None,
# Set to True to backup the lexique input text
"backup_lexique_text": True
}
# Ignore everything in this directory
*
# Except this files
!.gitignore
......@@ -16,6 +16,7 @@ print(" - Initialize ...")
output_name = PARAMETERS["output_name"]
current_dir = path.abspath(path.dirname(__file__))
doc_dir = path.join(current_dir, "doc")
backup_dir = path.join(current_dir, "backup")
lexique_txt_path = path.join(doc_dir, "lexique.txt")
latex_template_path = path.join(doc_dir, "template.tex")
tex_output_path = path.join(doc_dir, output_name + ".tex")
......@@ -31,6 +32,14 @@ if PARAMETERS["fetch_url"] is not None:
print(" - Read lexique text ...")
lexique_txt = read_file(lexique_txt_path)
# Backup input text lexique if required
if PARAMETERS["backup_lexique_text"]:
print(" - Backup lexique text ...")
backup_file_name = f"{output_name}-{get_current_date(sep='-', reverse=False)}.txt"
backup_path = path.join(backup_dir, backup_file_name)
write_file(backup_path, lexique_txt)
print(f" -> Backup saved in '{backup_path}'")
# Parse text lexique
print(" - Parse lexique ...")
lexique_dic = Parser().add(lexique_txt).get()
......
......@@ -23,10 +23,11 @@ def write_file(file_path, text):
# Date and Time ----------------------------------------------------------------
def get_current_date(sep="/"):
def get_current_date(sep="/", reverse=True):
""" Generate current date as a string in format DD/MM/YYYY """
current_data = str(datetime.now()).split()[0].split("-")
current_data.reverse()
if reverse:
current_data.reverse()
return sep.join(current_data)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment