This commit is contained in:
Guilhem Fauré 2023-05-24 12:07:52 +02:00
parent 93a717b721
commit 31fadce8c5

View File

@ -16,19 +16,6 @@ from spipobjects import (
get_sections, get_sections,
) )
# Print a stylized string, without trailing newline
def style(string: str, *args: int) -> None:
esc = "\033[" # Terminal escape sequence, needs to be closed by "m"
if len(args) == 0:
params: str = "1;" # Defaults to bold
else:
params: str = ""
for a in args:
params += str(a) + ";"
print(esc + params[:-1] + "m" + string + esc + "0m", end="")
# Define styles # Define styles
BO = 1 # Bold BO = 1 # Bold
IT = 3 # Italic IT = 3 # Italic
@ -43,6 +30,18 @@ C1 = 96 # Color
C2 = 96 # Color C2 = 96 # Color
# Print a stylized string, without trailing newline
def style(string: str, *args: int) -> None:
esc = "\033[" # Terminal escape sequence, needs to be closed by "m"
if len(args) == 0:
params: str = "1;" # Defaults to bold
else:
params: str = ""
for a in args:
params += str(a) + ";"
print(esc + params[:-1] + "m" + string + esc + "0m", end="")
# Print a string, highlighting every substring starting at start_stop[x][0] … # Print a string, highlighting every substring starting at start_stop[x][0] …
def highlight(string: str, *start_stop: tuple[int, int]) -> None: def highlight(string: str, *start_stop: tuple[int, int]) -> None:
previous_stop = 0 previous_stop = 0
@ -64,11 +63,6 @@ def indent(nb: int = 1) -> None:
print(" ", end="") print(" ", end="")
# Connect to the MySQL database with Peewee ORM
DB.init(config.db, host=config.db_host, user=config.db_user, password=config.db_pass)
DB.connect()
# Output information about ongoing export & write section to output destination # Output information about ongoing export & write section to output destination
def write_section(index: int, total: int, section: Rubrique) -> str: def write_section(index: int, total: int, section: Rubrique) -> str:
color = G # Associate sections to green color = G # Associate sections to green
@ -179,6 +173,11 @@ def warn_unknown_chars(article: Article) -> None:
print() # Break line print() # Break line
# Connect to the MySQL database with Peewee ORM
DB.init(config.db, host=config.db_host, user=config.db_user, password=config.db_pass)
DB.connect()
# Main loop to execute only if script is directly executed # Main loop to execute only if script is directly executed
if __name__ == "__main__": if __name__ == "__main__":
# Define max nb of articles to export based on first CLI argument # Define max nb of articles to export based on first CLI argument