From 8f0751170385989677392f806762a211f99412ef Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Thu, 21 Nov 2024 13:23:10 +0530 Subject: First Commit --- main.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 main.py (limited to 'main.py') diff --git a/main.py b/main.py new file mode 100644 index 0000000..261a9fe --- /dev/null +++ b/main.py @@ -0,0 +1,80 @@ +#!/bin/python3 + +from frames import * +from getpass import getuser +import mariadb +#import pdb + + +fields = (('userid', 'varchar(100)', 'PRIMARY KEY'), + ('ptype', 'varchar(4)', 'NOT NULL')) + + +def start(): + with mariadb.connect(host="localhost", user=getuser(), password='') as connection: + with connection.cursor() as cursor: + + # check if databse exist + cursor.execute('SHOW DATABASES') + for dbs in cursor.fetchall(): + if 'ptest' in dbs: + break + else: + print('Creating database ptest.') + cursor.execute("CREATE DATABASE ptest") + cursor.execute("USE ptest") + + # check if table exist and is in proper format + cursor.execute('SHOW TABLES') + for tables in cursor.fetchall(): + if 'records' in tables: + cursor.execute("DESCRIBE records") + columns = cursor.fetchall() + l_fields = len(fields) + l_columns = len(columns) + + table_ok = True + if l_fields != l_columns: + table_ok = False + for i in range(l_fields): + if fields[i][0] != columns[i][0] or fields[i][1] != columns[i][1]: + table_ok = False + + if table_ok == False: + cursor.execute("DROP TABLE records") + continue + break + else: + print('Creating table records.') + columns = '' + for i in range(len(fields)): + if i == 0: + columns += ' '.join(fields[i]) + else: + columns += ', ' + ' '.join(fields[i]) + cursor.execute("CREATE TABLE records({})".format(columns)) + + root = Tk() + root.title("Personality Test") + + WIN_HEIGHT, WIN_WIDTH = 1200, 675 + root.geometry(f"{WIN_HEIGHT}x{WIN_WIDTH}") + #root.minsize(WIN_HEIGHT, WIN_WIDTH) + #root.resizable(width=False, height=False) + root.configure(background="black") + root.bind_all("", lambda event: event.widget.focus_set()) + + #startpage = RecordsPage(HomePage(root, cursor), root, cursor) + startpage = HomePage(root, cursor) + startpage.pack(fill=BOTH, expand=TRUE) + startpage.mainloop() + + connection.commit() + + +start() + +# try: +# except Error as e: +# messagebox.showerror(title='Oops!', message=e) +# -- cgit v1.2.3