add: worksop entry & end date for events/workshops & summary change

This commit is contained in:
2026-07-26 14:17:11 +01:00
parent 5b434abd06
commit ce91ff46e0
11 changed files with 189 additions and 29 deletions

70
bot.py
View File

@@ -37,7 +37,7 @@ async def get_clean_content(url: str) -> str:
result = await loop.run_in_executor(pool, _run_scraper_in_thread, url)
return result
load_dotenv()
load_dotenv(override=True)
logging.getLogger("httpx").setLevel(logging.WARNING)
# Configuration
@@ -103,20 +103,46 @@ def build_url_choice_keyboard(url: str):
return InlineKeyboardMarkup([
[InlineKeyboardButton("📅 Process as Event", callback_data='choose_type:event')],
[InlineKeyboardButton("📋 Process as Opportunity", callback_data='choose_type:opportunity')],
[InlineKeyboardButton("🛠 Process as Workshop", callback_data='choose_type:workshop')],
])
def build_entry_summary(data, entry_type, saved=False):
if entry_type == "event":
event_datetime = data.get('date_time') or data.get('datetime')
return (
f"✅ **{data.get('title', 'Unknown')}**\n"
f"🦆 Org/s: {data.get('org')}\n"
f"📅 Date & Time: {event_datetime}\n"
f"📍 Location: {data.get('location')}\n"
f"🐊 Summary: {data.get('summary')}"
+ ("\n\n💾 **Saved to PocketBase!**" if saved else "")
)
end_date = data.get('end_date') or data.get('end_datetime')
lines = [
f"✅ **{data.get('title', 'Unknown')}**",
f"🦆 Org/s: {data.get('org')}",
f"📅 Date & Time: {event_datetime}",
]
if end_date and end_date != 'N/A':
lines.append(f"📅 End Date: {end_date}")
lines.extend([
f"📍 Location: {data.get('location')}",
f"🐊 Summary: {data.get('summary')}",
])
if saved:
lines.append("\n💾 **Saved to PocketBase!**")
return "\n".join(lines)
if entry_type == "workshop":
event_datetime = data.get('date_time') or data.get('datetime')
end_date = data.get('end_date') or data.get('end_datetime')
lines = [
f"✅ **{data.get('title', 'Unknown')}**",
f"🦆 Org/s: {data.get('org')}",
f"📅 Date & Time: {event_datetime}",
]
if end_date and end_date != 'N/A':
lines.append(f"📅 End Date: {end_date}")
lines.extend([
f"📍 Location: {data.get('location')}",
f"🐊 Summary: {data.get('summary')}",
])
if saved:
lines.append("\n💾 **Saved to PocketBase!**")
return "\n".join(lines)
return (
f"✅ **{data.get('title', 'Unknown')}**\n"
@@ -194,8 +220,9 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"Welcome! I can extract arts opportunities and events.\n\n"
"📋 **Commands:**\n"
"/op <url> - Extract an opportunity\n"
"/ev <url> - Extract an event\n\n"
"You can also send a URL directly and I will ask whether to process it as an event or opportunity."
"/ev <url> - Extract an event\n"
"/ws <url> - Extract a workshop\n\n"
"You can also send a URL directly and I will ask whether to process it as an event, workshop, or opportunity."
)
async def handle_opportunity(update: Update, context: ContextTypes.DEFAULT_TYPE):
@@ -238,6 +265,26 @@ async def handle_event(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("📥 Link queued for processing...")
await task_queue.put((update, context, input_text, "event", source_kind))
async def handle_workshop(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = update.effective_user.id
if user_id not in ALLOWED_IDS:
await update.message.reply_text("Unauthorized. User ID needs to be added!")
return
if not context.args:
await update.message.reply_text("Please provide a URL or paste text. Usage: /ws <url or text>")
return
input_text = " ".join(context.args).strip()
if not input_text:
await update.message.reply_text("Please provide a URL or paste text. Usage: /ws <url or text>")
return
source_kind = "url" if input_text.startswith("http") else "text"
await update.message.reply_text("📥 Link queued for processing...")
await task_queue.put((update, context, input_text, "workshop", source_kind))
async def handle_followup_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_user.id not in ALLOWED_IDS:
return
@@ -327,6 +374,7 @@ async def _main():
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("op", handle_opportunity))
application.add_handler(CommandHandler("ev", handle_event))
application.add_handler(CommandHandler("ws", handle_workshop))
application.add_handler(MessageHandler(filters.TEXT & (~filters.COMMAND), handle_followup_text))
application.add_handler(CallbackQueryHandler(button_handler))