fix documents querying + terminal output

This commit is contained in:
Guilhem Fauré 2023-05-22 17:34:59 +02:00
parent ae7063e241
commit bad5fef4c6
2 changed files with 26 additions and 10 deletions

View File

@ -248,7 +248,6 @@ class Documents(Iterator):
on=(SpipDocuments.id_document == SpipDocumentsLiens.id_document), on=(SpipDocuments.id_document == SpipDocumentsLiens.id_document),
) )
.where(SpipDocumentsLiens.id_objet == object_id) .where(SpipDocumentsLiens.id_objet == object_id)
.order_by(SpipArticles.date.desc())
) )
super().__init__() super().__init__()

View File

@ -106,6 +106,7 @@ if __name__ == "__main__": # Only if script is directly executed
+ f"{article.lang} " + f"{article.lang} "
) )
highlight(article.title, *unknown_chars(article.title)) highlight(article.title, *unknown_chars(article.title))
print()
# Define the full article path & create directory(ies) if needed # Define the full article path & create directory(ies) if needed
articledir: str = sectiondir + "/" + article.get_slug() articledir: str = sectiondir + "/" + article.get_slug()
makedirs(articledir, exist_ok=True) makedirs(articledir, exist_ok=True)
@ -118,24 +119,38 @@ if __name__ == "__main__": # Only if script is directly executed
unknown_chars_articles.append(article) unknown_chars_articles.append(article)
# Loop over articles related files (images …) # Loop over articles related files (images …)
for document, counter in Documents(article.id): for document, counter in Documents(article.id):
if counter.count % 100 == 0:
s: str = "s" if counter.remaining() > 1 else ""
print(" Exporting", end="")
style(f" {counter.remaining()}", BO, B)
style(f" file{s}")
print(" in this article")
# Print the name of the file with a counter # Print the name of the file with a counter
style(f" {counter.count + 1}. {document.media} ") style(f" {counter.count + 1}. {document.media} ")
highlight(article.title, *unknown_chars(article.title)) print(f" {document.title}")
# highlight(document.title, *unknown_chars(document.title))
# Copy the document from its SPIP location to the new location # Copy the document from its SPIP location to the new location
try:
copyfile(config.data_dir + "/" + document.file, document.get_slug()) copyfile(config.data_dir + "/" + document.file, document.get_slug())
except FileNotFoundError:
style(" NOT FOUND", BO, R)
print(f" {document.file}")
else:
# Print the outputted files path when copied the file # Print the outputted files path when copied the file
style(" -->", BO, B) style("\n --> ACTUALLY FOUND", BO, B)
print(f" {articledir}/{document.get_slug()}") print(f" {articledir}/{document.get_slug()}")
# Print the outputted files path when finished exporting the article # Print the outputted files path when finished exporting the article
style(" --> ", BO, Y) style(" --> ", BO, Y)
print(articlepath) print(articlepath)
# Print the outputted files path when finished exporting the section # Print the outputted files path when finished exporting the section
style(" --> ", BO, G) style("--> ", BO, G)
print(sectionpath) print(sectionpath)
print() print()
# Decrement export limit with length of exported section # Decrement export limit with length of exported section
toexport -= len(articles) toexport -= len(articles)
print() # Break line
# Loop through each article that contains an unknown character # Loop through each article that contains an unknown character
for article in unknown_chars_articles: for article in unknown_chars_articles:
# Print the title of the article in which there is unknown characters # Print the title of the article in which there is unknown characters
@ -143,14 +158,16 @@ if __name__ == "__main__": # Only if script is directly executed
unknown_chars_apparitions: list[str] = get_unknown_chars(article.text) unknown_chars_apparitions: list[str] = get_unknown_chars(article.text)
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 ""
style(f"\n{nb}") style(f"{nb}")
print(f" unknown character{s} in") print(f" unknown character{s} in", end="")
style(f" {article.lang} ") style(f" {article.lang} ")
highlight(article.title, *unknown_chars(article.title)) highlight(article.title, *unknown_chars(article.title))
print() # Break line
# Print the context in which the unknown characters are found # Print the context in which the unknown characters are found
for text in unknown_chars_apparitions: for text in unknown_chars_apparitions:
style("") style("")
highlight(text, *unknown_chars(text)) highlight(text, *unknown_chars(text))
style("") style("\n")
print() # Break line
db.close() # Close the connection with the database db.close() # Close the connection with the database