From 908de22013ae2823d0204bf6540db1b1c7b556be Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 25 Jun 2023 12:49:27 +0200 Subject: [PATCH] remove unused contrib script --- contrib/sqlite_to_posts.py | 46 -------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 contrib/sqlite_to_posts.py diff --git a/contrib/sqlite_to_posts.py b/contrib/sqlite_to_posts.py deleted file mode 100644 index 3b8349e..0000000 --- a/contrib/sqlite_to_posts.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import re -import shutil -from pathlib import Path - -from django.core.management.base import BaseCommand - -from attachments.models import Attachment -from articles.models import Article - - -class Command(BaseCommand): - def handle(self, *_args, **_options) -> None: - base_folder="/app/db/posts" - os.makedirs(base_folder, exist_ok=True) - for article in Article.objects.all(): - self.stdout.write(f"Processing {article.title}...") - tags = map(repr, article.tags.all().values_list("name", flat=True)) - date = article.published_at or article.created_at - lines = [ - "---", - f'title: "{article.title}"', - f"tags: [{', '.join(tags)}]", - f"date: {date.isoformat()}", - f'aliases: ["/{article.slug}"]', - "---", - ] - folder = f"{base_folder}/{article.slug}" - os.makedirs(folder, exist_ok=True) - attachments = set(re.findall(r"/attachments/(\d+)", article.content)) - attachments = Attachment.objects.filter(id__in=attachments) - content = article.content.replace("\r", "") - content = re.sub(r"!\[([^]]*)]\(/attachments/(\d+)[^)]*\)", r"![\1](\2.__SUFFIX__)", content) - content = re.sub(r"\{:[^}]*}", "", content) - for attachment in attachments: - src = Path(attachment.original_file.path) - dst = (Path(folder) / str(attachment.pk)).with_suffix(src.suffix) - shutil.copy(src, dst) - self.stdout.write(str(dst)) - content = content.replace(f"{attachment.pk}.__SUFFIX__", f"{attachment.pk}{src.suffix}") - with open(f"{folder}/index.md", "w") as f: - f.write("\n".join(lines)) - f.write("\n") - f.write(content) - f.write("\n") - self.stdout.write(self.style.SUCCESS("Successfully wrote all posts."))