playing with regexes
This commit is contained in:
parent
d40afca1a4
commit
6b63276dd7
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from telegram.ext import ConversationHandler, CommandHandler, MessageHandler, filters, CallbackQueryHandler, CallbackContext
|
||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, InputMediaPhoto
|
||||
from telegram.constants import ParseMode
|
||||
# ACTION_CHOICE, DATE_ENTRY, ADD_CONTENT = range(3)
|
||||
MEMORY_CHOICE = range(1)
|
||||
|
||||
@ -81,7 +82,8 @@ class MemoryHandler(BaseHandler):
|
||||
await query.edit_message_text(
|
||||
f"On {chosen_match.date_pretty}, "
|
||||
f"{chosen_match.author} wrote: \n"
|
||||
f"{chosen_match.text}"
|
||||
f"{chosen_match.spoiler_text}",
|
||||
parse_mode=ParseMode.HTML
|
||||
)
|
||||
|
||||
return ConversationHandler.END
|
||||
|
@ -1,4 +1,5 @@
|
||||
from datetime import time, timedelta, timezone, datetime, date
|
||||
from telegram.constants import ParseMode
|
||||
import os
|
||||
from peewee import fn
|
||||
import logging
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user