From 31fadce8c548b85e3bd66174a3000076ce724755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Wed, 24 May 2023 12:07:52 +0200 Subject: [PATCH] cleaning --- spip2md/main.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/spip2md/main.py b/spip2md/main.py index 9bd0336..bc2d83e 100755 --- a/spip2md/main.py +++ b/spip2md/main.py @@ -16,19 +16,6 @@ from spipobjects import ( 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 BO = 1 # Bold IT = 3 # Italic @@ -43,6 +30,18 @@ C1 = 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] … def highlight(string: str, *start_stop: tuple[int, int]) -> None: previous_stop = 0 @@ -64,11 +63,6 @@ def indent(nb: int = 1) -> None: 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 def write_section(index: int, total: int, section: Rubrique) -> str: color = G # Associate sections to green @@ -179,6 +173,11 @@ def warn_unknown_chars(article: Article) -> None: 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 if __name__ == "__main__": # Define max nb of articles to export based on first CLI argument