From 96456c485b050bb0eceb82575864800726dcb7c1 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Sat, 17 Jan 2026 12:06:39 +0700 Subject: [PATCH] metaprofile module --- modules/api/metaprofile/metaprofile.py | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 modules/api/metaprofile/metaprofile.py diff --git a/modules/api/metaprofile/metaprofile.py b/modules/api/metaprofile/metaprofile.py new file mode 100644 index 0000000..3566ab6 --- /dev/null +++ b/modules/api/metaprofile/metaprofile.py @@ -0,0 +1,64 @@ +import mysql.connector as mariadb + +from config import database +from scripts import loggorilla + +import datetime + +class metaprofile: + + def __init__(self): + self.db_main = mariadb.connect(**database.db_main) + self.cursor = self.db_main.cursor(dictionary=True) + + def save(self, params): + APIADDR = "/api/metaprofile/save" + response = {} + loggorilla.prcss(APIADDR, "Define Models") + key = params["key" ] + favicon = params["favicon" ] + copyright = params["copyright" ] + self.cursor.execute("BEGIN;") + try: + loggorilla.prcss(APIADDR, "Activity: Update") + self.cursor.execute("UPDATE `metaprofile` SET `favicon` = %s, `copyright` = %s WHERE `id` = %s ;", (favicon, copyright, key) ) + loggorilla.prcss(APIADDR, "Set Response") + response["status" ] = "success" + response["desc" ] = "data updated" + except Exception as e: + self.cursor.execute("ROLLBACK;") + loggorilla.error(APIADDR, str(e) ) + loggorilla.prcss(APIADDR, "Set Response") + response["status" ] = "failed" + response["desc" ] = "Internal Server Error. Please contact us if you still have an error." + finally: + self.cursor.execute("COMMIT;") + self.cursor.close() + self.db_main.close() + return response + + def detail(self, params): + APIADDR = "/api/metaprofile/detail" + response = {} + loggorilla.prcss(APIADDR, "Define Models") + key = params["key" ] + self.cursor.execute("BEGIN;") + try: + self.cursor.execute("select `favicon`, `copyright` from `metaprofile` where `id` = %s ;", (key,) ) + row = self.cursor.fetchone() + loggorilla.prcss(APIADDR, "Set Response") + response["status" ] = "success" + response["desc" ] = "data collected" + response["data" ] = row + except Exception as e: + self.cursor.execute("ROLLBACK;") + loggorilla.error(APIADDR, str(e) ) + loggorilla.prcss(APIADDR, "Set Response") + response["status" ] = "failed" + response["desc" ] = "Internal Server Error. Please contact us if you still have an error." + finally: + self.cursor.execute("COMMIT;") + self.cursor.close() + self.db_main.close() + return response +