-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (39 loc) · 1.41 KB
/
main.py
File metadata and controls
49 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import warnings
import pymysql as sql
from PyQt6 import QtGui, QtWidgets
from app import APP
from model.modelo import DATABASE_NAME, PASSWORD, PORT, USER, create_tables
############################################################
# ARQUIVO MAIN: INICIALIZA O BANCO E A APLICAÇÃO #
############################################################
driver = sql.connect(user=USER, password=PASSWORD, host="localhost", port=PORT)
cursor = driver.cursor()
# VERIFICA SE O BANCO DE DADOS EXISTE
if (
cursor.execute(
f"SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '{DATABASE_NAME}'"
)
== 0
):
cursor.execute(f"CREATE DATABASE {DATABASE_NAME}")
cursor.execute(f"use {DATABASE_NAME}")
create_tables(cursor)
# IGNORA WARNING DA LIB DATEPARSER
warnings.filterwarnings(
"ignore",
message="The localize method is no longer necessary, as this time zone supports the fold attribute",
)
# CAPTURA ERROS SEM FECHAR O APP
def excepthook(type_, value, traceback_):
sys.__excepthook__(type_, value, traceback_)
msg = QtWidgets.QMessageBox()
msg.setWindowIcon(QtGui.QIcon("resources/logo-icon.png"))
msg.setIcon(QtWidgets.QMessageBox.Icon.Critical)
msg.setWindowTitle("Erro")
msg.setText("Ocorreu um erro.\nEntre em contato com o desenvolvedor")
msg.exec()
sys.excepthook = excepthook
if __name__ == "__main__":
c = APP()
c.run()