fixes to use the program with repr
This commit is contained in:
parent
c38274b58e
commit
221aa5d3aa
@ -1,20 +1,18 @@
|
|||||||
#!python
|
#!python
|
||||||
# pyright: basic
|
# pyright: basic
|
||||||
|
import sys
|
||||||
|
from os import makedirs, mkdir
|
||||||
|
from shutil import rmtree
|
||||||
|
|
||||||
from articles import Article, Articles
|
from articles import Article, Articles
|
||||||
from config import config
|
from config import config
|
||||||
from converter import highlight_unknown_chars
|
from converter import highlight_unknown_chars
|
||||||
from database import db
|
from database import db
|
||||||
|
|
||||||
if __name__ != "__main__":
|
if __name__ != "__main__":
|
||||||
exit()
|
# Clean the output dir & create a new
|
||||||
|
rmtree(config.output_dir, True)
|
||||||
import sys
|
mkdir(config.output_dir)
|
||||||
from os import makedirs, mkdir
|
|
||||||
from shutil import rmtree
|
|
||||||
|
|
||||||
# Clean the output dir & create a new
|
|
||||||
rmtree(config.output_dir, True)
|
|
||||||
mkdir(config.output_dir)
|
|
||||||
|
|
||||||
# Connect to the MySQL database with Peewee ORM
|
# 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.init(config.db, host=config.db_host, user=config.db_user, password=config.db_pass)
|
||||||
@ -36,36 +34,37 @@ RESET: str = "\033[0m"
|
|||||||
# Articles that contains unknown chars
|
# Articles that contains unknown chars
|
||||||
unknown_chars_articles: list[Article] = []
|
unknown_chars_articles: list[Article] = []
|
||||||
|
|
||||||
# Loop among first maxexport articles & export them
|
if __name__ != "__main__":
|
||||||
for counter, article in Articles(maxexport):
|
# Loop among first maxexport articles & export them
|
||||||
if (counter["exported"] - 1) % 100 == 0:
|
for counter, article in Articles(maxexport):
|
||||||
|
if (counter["exported"] - 1) % 100 == 0:
|
||||||
|
print(
|
||||||
|
f"\n{BOLD}Exporting {R}{counter['remaining']+1}{RESET}"
|
||||||
|
+ f"{BOLD} SPIP articles to Markdown & YAML files{RESET}\n"
|
||||||
|
)
|
||||||
|
empty: str = "EMPTY " if len(article.text) < 1 else ""
|
||||||
print(
|
print(
|
||||||
f"\n{BOLD}Exporting {R}{counter['remaining']+1}{RESET}"
|
f"{BOLD}{counter['exported']}. {empty}{RESET}"
|
||||||
+ f"{BOLD} SPIP articles to Markdown & YAML files{RESET}\n"
|
+ highlight_unknown_chars(article.title)
|
||||||
)
|
)
|
||||||
empty: str = "EMPTY " if len(article.text) < 1 else ""
|
fullpath: str = config.output_dir + "/" + article.get_path()
|
||||||
print(
|
print(f"{BOLD}>{RESET} {fullpath}{article.get_filename()}")
|
||||||
f"{BOLD}{counter['exported']}. {empty}{RESET}"
|
makedirs(fullpath, exist_ok=True)
|
||||||
+ highlight_unknown_chars(article.title)
|
with open(fullpath + article.get_filename(), "w") as f:
|
||||||
)
|
f.write(article.get_article())
|
||||||
fullpath: str = config.output_dir + "/" + article.get_path()
|
# Store detected unknown characters
|
||||||
print(f"{BOLD}>{RESET} {fullpath}{article.get_filename()}")
|
if len(article.get_unknown_chars()) > 0:
|
||||||
makedirs(fullpath, exist_ok=True)
|
unknown_chars_articles.append(article)
|
||||||
with open(fullpath + article.get_filename(), "w") as f:
|
|
||||||
f.write(article.get_article())
|
|
||||||
# Store detected unknown characters
|
|
||||||
if len(article.get_unknown_chars()) > 0:
|
|
||||||
unknown_chars_articles.append(article)
|
|
||||||
|
|
||||||
for article in unknown_chars_articles:
|
for article in unknown_chars_articles:
|
||||||
unknown_chars_apparitions: list = article.get_unknown_chars()
|
unknown_chars_apparitions: list = article.get_unknown_chars()
|
||||||
nb: int = len(unknown_chars_apparitions)
|
nb: int = len(unknown_chars_apparitions)
|
||||||
s: str = "s" if nb > 1 else ""
|
s: str = "s" if nb > 1 else ""
|
||||||
print(
|
print(
|
||||||
f"\n{BOLD}{nb}{RESET} unknown character{s} in {BOLD}{article.lang}{RESET} "
|
f"\n{BOLD}{nb}{RESET} unknown character{s} in {BOLD}{article.lang}{RESET} "
|
||||||
+ highlight_unknown_chars(article.title)
|
+ highlight_unknown_chars(article.title)
|
||||||
)
|
)
|
||||||
for text in unknown_chars_apparitions:
|
for text in unknown_chars_apparitions:
|
||||||
print(f" {BOLD}…{RESET} " + highlight_unknown_chars(text))
|
print(f" {BOLD}…{RESET} " + highlight_unknown_chars(text))
|
||||||
|
|
||||||
db.close() # Close the database connection
|
db.close() # Close the database connection
|
||||||
|
Loading…
Reference in New Issue
Block a user