From 2b488ee1f8786aeb33a2793483fd064f3709294f Mon Sep 17 00:00:00 2001 From: Dennis Potter Date: Sat, 2 Feb 2019 16:16:37 +0100 Subject: [PATCH] Most of the Admidio event plugins now makes use of the Admidio Python API This commit also adds the function which enables users to request participants from the bot. --- plugins/admidio_events/admidio_events.py | 162 ++++++++++++------ plugins/admidio_events/config.hjson.example | 3 +- .../messages/messages.dutch.hjson | 33 +++- plugins/admidio_events/requirements.txt | 1 + 4 files changed, 140 insertions(+), 59 deletions(-) diff --git a/plugins/admidio_events/admidio_events.py b/plugins/admidio_events/admidio_events.py index d7a70ab..dba3d09 100644 --- a/plugins/admidio_events/admidio_events.py +++ b/plugins/admidio_events/admidio_events.py @@ -11,11 +11,18 @@ import hjson import time import sqlite3 import threading +import importlib +import sys import datetime as dt import MySQLdb as mysql from matrix_bot_api.mregex_handler import MRegexHandler +sys.path.insert(0, os.path.dirname(__file__)) + +import admidio_python_api.admidio as admidio +import admidio_python_api.group as group + MESSAGES_DIR = os.path.join(os.path.dirname(__file__), 'messages') DATA_DIR = os.path.join(os.path.dirname(__file__),'../../data/events') CONFIG_LOCATION = os.path.join(os.path.dirname(__file__), 'config.hjson') @@ -37,6 +44,13 @@ class Plugin: with open(MESSAGES_LOCATION) as hjson_data: self.messages = hjson.load(hjson_data) + self.adm = admidio.Admidio( + self.config['database_credentials']['host'], + self.config['database_credentials']['username'], + self.config['database_credentials']['password'], + self.config['database_credentials']['database'], + self.config['database_credentials']['adm_prefix']) + # Define sensitivity self.handler = [] @@ -64,7 +78,6 @@ class Plugin: database = self.config['database_credentials']['database'], host = self.config['database_credentials']['host']) - def check_new_event_thread(self): while not self.bot.cancel: self.check_new_event() @@ -150,7 +163,8 @@ class Plugin: if room.display_name in mapping[1]: room.send_html( self.messages["new_event"].format( - row[3].strftime("%d-%m-%Y om %H:%M"), + row[3].strftime("%d-%m-%Y"), + row[3].strftime("%H:%M"), row[2], view_link, attend_link, @@ -183,42 +197,33 @@ class Plugin: room.send_text(self.messages['list_event_num_err']) number_events = 10 - datetime_now = dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - mysql_db = self.connect_database() - mysql_cursor = mysql_db.cursor() + base_date_url = "{}{}".format( + self.config['base_url_adm'], + "/adm_program/modules/dates/") - select_sql = f"""SELECT dat_id, dat_cat_id, - dat_headline, dat_begin, dat_end - FROM adm_dates - WHERE dat_begin >'{datetime_now}' - ORDER BY dat_begin - LIMIT {number_events}""" + function_link = "{}dates_function.php?mode={}&dat_id={}&" - mysql_cursor.execute(select_sql) - - # Fetch events - results = mysql_cursor.fetchall() + now = dt.datetime.now() + events = (x for (k,x) in self.adm.events.items() if x.start_time > now) # Set header html_message = self.messages['list_events_head'].format(number_events) # Loop through fetched events html_message += "