From 34d84dcde2247620811bcedb12867f9bffbae6ec Mon Sep 17 00:00:00 2001 From: knoflook Date: Thu, 10 Feb 2022 12:52:55 +0100 Subject: [PATCH] cal, vid: slugify instead of sanitize_name --- lumbunglib/cloudcal.py | 9 ++------- lumbunglib/video.py | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lumbunglib/cloudcal.py b/lumbunglib/cloudcal.py index 7f67017..0645e45 100644 --- a/lumbunglib/cloudcal.py +++ b/lumbunglib/cloudcal.py @@ -3,6 +3,7 @@ import re import shutil from pathlib import Path from urllib.parse import urlparse +from slugify import slugify import arrow import jinja2 @@ -111,12 +112,6 @@ def localize_time(date): ) return localized_begins -def sanitize_name(name): - sanitized = "".join([c if c.isalnum() or c == " " else "-" for c in name]) - if len(sanitized) > 20: - return sanitized[:20] - return sanitized - def create_event_post(post_dir, event): """ Create HUGO post based on calendar event metadata @@ -193,7 +188,7 @@ def update_event_post(post_dir, event): def main(): for event in list(cal.events): - post_name = sanitize_name(event.name) + "-" + event.uid + post_name = slugify(event.name) + "-" + event.uid post_dir = os.path.join(output_dir, post_name) if post_name not in existing_posts: diff --git a/lumbunglib/video.py b/lumbunglib/video.py index 2945286..94a1908 100644 --- a/lumbunglib/video.py +++ b/lumbunglib/video.py @@ -4,6 +4,7 @@ import json import os import shutil from pathlib import Path +from slugify import slugify import arrow import jinja2 @@ -97,12 +98,6 @@ def update_post(post_directory, video_metadata, host): # compat for when there is no timestamp yet.. create_post(post_directory, video_metadata, host) -def sanitize_name(name): - sanitized = "".join([c if c.isalnum() or c == " " else "-" for c in name]) - if len(sanitized) > 40: - return sanitized[:40] - return sanitized - def main(): v = peertube.VideoApi(client) @@ -119,7 +114,7 @@ def main(): existing_posts = os.listdir(output_dir) for video_metadata in videos: - post_name = sanitize_name(video_metadata["name"]) + "-" + video_metadata["uuid"] + post_name = slugify(video_metadata["name"]) + "-" + video_metadata["uuid"] post_dir = os.path.join(output_dir, post_name) if (