Commit 38cc9347 authored by MatveiT's avatar MatveiT
Browse files

Add fetch feature

parent 2c2d281b
......@@ -4,10 +4,14 @@ Complete your own parameter in ./PARAMETERS.py file by following this template.
"""
PARAMETERS = {
# Set True to see the latex logs in the console during execution
# Set True to see latex logs in the console during execution
"print_latex_logs": False,
# Name of the generated lexique file (withoud extention)
# Set True to see wget logs in the console during execution
"print_wget_logs": False,
# Name of the generated lexique file (without extention)
"output_name": "lexique_technopolice",
# Directory where to copy .pdf file after execution (set None if no need to copy it)
"copy_to_dir": None
"copy_to_dir": None,
# url from where to fetch lexique text (set None to not fetch from an url)
"fetch_url": None
}
......@@ -14,8 +14,10 @@ https://technopolice.be/
## Usage
- Create the file `./doc/lexique.txt` containing the content of the lexique following the syntax of `./doc/lexique_example.txt`.
- Create the file `./doc/lexique.txt` containing the content of the lexique following the syntax of `./doc/lexique_example.txt`. Or specify an url from where to fetch the text file in `./PARAMETERS.py`.
- Create the file `./PARAMETERS.py` and set your parameters following the template file `./PARAMETERS_TEMPLATE.py`.
- Run `./main.py` with python3
- If required, adapt the template of the latex file in `./doc/template.tex`.
......@@ -3,7 +3,7 @@
from os import path, system
from PARAMETERS import PARAMETERS
from scr.utils import read_file, write_file, get_current_date, generate_pdf
from scr.utils import read_file, write_file, get_current_date, generate_pdf, wget_file
from scr.Parser import Parser
from scr.Generator import Generator
......@@ -22,6 +22,11 @@ tex_output_path = path.join(doc_dir, output_name + ".tex")
pdf_output_path = path.join(doc_dir, output_name + ".pdf")
current_date = get_current_date()
# Fetch lexique if url is specified
if PARAMETERS["fetch_url"] is not None:
print(" - Fetch lexique text ...")
wget_file(PARAMETERS["fetch_url"], lexique_txt_path, PARAMETERS["print_wget_logs"])
# Read input text lexique
print(" - Read lexique text ...")
lexique_txt = read_file(lexique_txt_path)
......
......@@ -35,9 +35,16 @@ def generate_pdf(dir, file_name, do_print=False):
""" Generate a pdf using 'pdflatex' """
# Generate command
cmd_suffix = "" if do_print else ">/dev/null"
cmd_str = f"cd {dir} && pdflatex {file_name} {cmd_suffix}"
pdflatex_cmd = f"cd {dir} && pdflatex {file_name} {cmd_suffix}"
# Execute command
# For a mysterious reason of latex, you sometimes need to compile the file two times to get the wanted redering ...
system(cmd_str)
system(cmd_str)
system(pdflatex_cmd)
system(pdflatex_cmd)
# Fetch from web ---------------------------------------------------------------
def wget_file(url, save_path, do_print=False):
""" Save (wget) a file in <save_path> from url <url> """
cmd_suffix = "" if do_print else "-o /dev/null"
wget_cmd = f"wget {url} -O {save_path} {cmd_suffix}"
system(wget_cmd)
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