diff --git a/__pycache__/sanitize.cpython-311.pyc b/__pycache__/sanitize.cpython-311.pyc new file mode 100644 index 0000000..5453e3c Binary files /dev/null and b/__pycache__/sanitize.cpython-311.pyc differ diff --git a/bot.py b/bot.py index f22537f..0350b10 100644 --- a/bot.py +++ b/bot.py @@ -1,6 +1,7 @@ import json import logging import os +from sanitize import sanitize import discord from pytz import timezone @@ -39,7 +40,7 @@ async def on_ready(): directory = start_time.strftime("%Y/%m/%d") start_time = start_time.strftime("%H:%M") end_time = end_time.strftime("%H:%M") - filename = f"{date}-{event.name.replace('/', '').replace(':', '')}.md" + filename = f"{date}-{sanitize(event.name)}.md" fields = f"""--- title: {json.dumps(event.name)} tags: ["hs3"] diff --git a/sanitize.py b/sanitize.py new file mode 100644 index 0000000..7e79bad --- /dev/null +++ b/sanitize.py @@ -0,0 +1,27 @@ +import re + +safe = "abcdefghijklmnopqrstuvwxyz01234567890-_ .," +tomap = ("éàèùçâêîôûëïüąćęłńóśźżříšžčýůňúěďáéäüößœ", + (*"eaeucaeioueiuacelnoszzriszcyunuedae", + "ae", "ue", "oe", "ss", "oe")) +map = { + **{c: c for c in safe + safe.upper()}, + **{s: d for (s, d) in zip(*tomap)}, + **{s.upper(): d.upper() for (s, d) in zip(*tomap)}, +} + + +def sanitize(s): + return re.sub("_+", "_", "".join([map[c] if c in map else "_" for c in s])) + + +if __name__ == "__main__": + def test(s): + print(f"{s} --> {sanitize(s)}") + print(f"{s.upper()} --> {sanitize(s.upper())}") + + test("Pójdźże, kiń tę chmurność w głąb flaszy!") + test("Příliš žluťoučký kůň úpěl ďábelské ódy") + test("Fix, Schwyz! quäkt Jürgen blöd vom Paß") + test("HellOO 😂🤣--😍🥰 there, you!.md") + test("Voix ambiguë d’un cœur qui au zéphyr préfère les jattes de kiwis")