35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
import mysql.connector as mariadb
|
||
|
import config.database as database
|
||
|
import config.globalvar as globalvar
|
||
|
|
||
|
class main:
|
||
|
|
||
|
def __init__(self):
|
||
|
pass
|
||
|
|
||
|
def result(self, params):
|
||
|
response = {
|
||
|
"message_action" : "success" ,
|
||
|
"message_desc" : "New portal created" ,
|
||
|
"message_data" : {
|
||
|
"title" : params['title' ],
|
||
|
"website" : params['website' ],
|
||
|
"logo" : params['logo' ],
|
||
|
"directory" : params['directory' ],
|
||
|
},
|
||
|
}
|
||
|
if params['logo']:
|
||
|
query = f"INSERT INTO portal VALUES (DEFAULT, '{params['title']}', NULL, '{params['website']}', '{params['logo']}', '{params['directory']}')"
|
||
|
else:
|
||
|
query = f"INSERT INTO portal VALUES (DEFAULT, '{params['title']}', NULL, '{params['website']}', NULL, '{params['directory']}')"
|
||
|
try:
|
||
|
con = mariadb.connect(**database.main_db)
|
||
|
cursor = con.cursor()
|
||
|
cursor.execute(query)
|
||
|
con.close()
|
||
|
except Exception as e:
|
||
|
print(f"Error: {e}")
|
||
|
response["message_action" ] = "failed",
|
||
|
response["message_desc" ] = f"error: {e}"
|
||
|
return response
|