playing with regexes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from peewee import *
|
||||
from pathlib import Path
|
||||
import re
|
||||
import os
|
||||
import datetime
|
||||
|
||||
@@ -60,6 +61,14 @@ class JournalEntry(BaseModel):
|
||||
except ValueError: #fck windows
|
||||
return self.date.strftime('%a, %d. %b %Y')
|
||||
|
||||
@property
|
||||
def spoiler_text(self) -> str:
|
||||
new_text = self.text.replace("\n", "<br>").replace("<", "<").replace(">", ">").replace("&", "&")
|
||||
matches = re.findall(r"[A-Z](\s|\w)+\:\)(\w|\s)+\.", new_text)
|
||||
for match in matches:
|
||||
new_text = new_text.replace(match, f"<tg-spoiler>{match}</tg-spoiler>")
|
||||
return new_text
|
||||
|
||||
|
||||
def set_db(db_path):
|
||||
db.initialize(SqliteDatabase(db_path))
|
||||
|
Reference in New Issue
Block a user