export files
This commit is contained in:
parent
bad5fef4c6
commit
79f1a9e958
@ -1,4 +1,5 @@
|
||||
# pyright: strict
|
||||
from os.path import basename, splitext
|
||||
from typing import Any, Optional
|
||||
|
||||
from slugify import slugify
|
||||
@ -158,9 +159,9 @@ class Document:
|
||||
def __init__(self, document: SpipDocuments) -> None:
|
||||
self.id: int = document.id_document
|
||||
self.thumbnail_id: int = document.id_vignette
|
||||
self.title: str = document.titre
|
||||
self.title: str = convert_meta(document.titre)
|
||||
self.date: str = document.date
|
||||
self.description: str = document.descriptif
|
||||
self.description: str = convert_meta(document.descriptif)
|
||||
self.file: str = document.fichier
|
||||
self.draft: bool = document.statut == "publie"
|
||||
self.creation: str = document.date
|
||||
@ -169,7 +170,11 @@ class Document:
|
||||
self.media: str = document.media
|
||||
|
||||
def get_slug(self, date: bool = False) -> str:
|
||||
return slugify((self.publication + "-" if date else "") + self.title)
|
||||
name_type = splitext(basename(self.file))
|
||||
return (
|
||||
slugify((self.publication + "-" if date else "") + name_type[0])
|
||||
+ name_type[1]
|
||||
)
|
||||
|
||||
|
||||
class LimitCounter:
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!python
|
||||
# pyright: strict
|
||||
from os import makedirs, mkdir
|
||||
from os.path import expanduser
|
||||
from shutil import copyfile, rmtree
|
||||
from sys import argv
|
||||
|
||||
@ -123,21 +124,25 @@ if __name__ == "__main__": # Only if script is directly executed
|
||||
s: str = "s" if counter.remaining() > 1 else ""
|
||||
print(" Exporting", end="")
|
||||
style(f" {counter.remaining()}", BO, B)
|
||||
style(f" file{s}")
|
||||
style(f" document{s}")
|
||||
print(" in this article")
|
||||
# Print the name of the file with a counter
|
||||
style(f" {counter.count + 1}. {document.media} ")
|
||||
print(f" {document.title}")
|
||||
# highlight(document.title, *unknown_chars(document.title))
|
||||
if len(document.title) > 0:
|
||||
highlight(document.title + " ", *unknown_chars(document.title))
|
||||
style("at ")
|
||||
print(document.file)
|
||||
# Define document path
|
||||
documentpath: str = expanduser(config.data_dir + "/" + document.file)
|
||||
# Copy the document from it’s SPIP location to the new location
|
||||
try:
|
||||
copyfile(config.data_dir + "/" + document.file, document.get_slug())
|
||||
copyfile(documentpath, articledir + "/" + document.get_slug())
|
||||
except FileNotFoundError:
|
||||
style(" NOT FOUND", BO, R)
|
||||
print(f" {document.file}")
|
||||
style(" NOT FOUND: ", BO, R)
|
||||
print(documentpath)
|
||||
else:
|
||||
# Print the outputted file’s path when copied the file
|
||||
style("\n --> ACTUALLY FOUND", BO, B)
|
||||
style(" -->", BO, B)
|
||||
print(f" {articledir}/{document.get_slug()}")
|
||||
# Print the outputted file’s path when finished exporting the article
|
||||
style(" --> ", BO, Y)
|
||||
|
Loading…
Reference in New Issue
Block a user