DE-Lib 0.0.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. DE_Lib/Cloud/__init__.py +0 -0
  2. DE_Lib/DataBase/Azure.py +44 -0
  3. DE_Lib/DataBase/Cache.py +74 -0
  4. DE_Lib/DataBase/Firebird.py +45 -0
  5. DE_Lib/DataBase/Informix.py +37 -0
  6. DE_Lib/DataBase/Metadata.py +62 -0
  7. DE_Lib/DataBase/MsSql.py +39 -0
  8. DE_Lib/DataBase/MySql.py +42 -0
  9. DE_Lib/DataBase/Oracle.py +111 -0
  10. DE_Lib/DataBase/Postgres.py +39 -0
  11. DE_Lib/DataBase/RedShift.py +42 -0
  12. DE_Lib/DataBase/SQCipher.py +42 -0
  13. DE_Lib/DataBase/SQLite.py +48 -0
  14. DE_Lib/DataBase/__init__.py +0 -0
  15. DE_Lib/Files/Avro.py +23 -0
  16. DE_Lib/Files/Csv.py +64 -0
  17. DE_Lib/Files/JSon.py +64 -0
  18. DE_Lib/Files/Parquet.py +31 -0
  19. DE_Lib/Files/Txt.py +64 -0
  20. DE_Lib/Files/Xlsx.py +55 -0
  21. DE_Lib/Files/__init__.py +0 -0
  22. DE_Lib/Log/DE_LogEventos.py +533 -0
  23. DE_Lib/Log/Level.py +77 -0
  24. DE_Lib/Log/Log.py +470 -0
  25. DE_Lib/Log/__init__.py +0 -0
  26. DE_Lib/Utils/Cipher/Aes.py +65 -0
  27. DE_Lib/Utils/Cipher/Argon.py +37 -0
  28. DE_Lib/Utils/Cipher/Base64.py +48 -0
  29. DE_Lib/Utils/Cipher/Cipher.py +300 -0
  30. DE_Lib/Utils/Cipher/Fernet.py +81 -0
  31. DE_Lib/Utils/Cipher/Gcm.py +78 -0
  32. DE_Lib/Utils/Cipher/Pbkdf2.py +43 -0
  33. DE_Lib/Utils/Cipher/Rsa.py +140 -0
  34. DE_Lib/Utils/Cipher/__init__.py +0 -0
  35. DE_Lib/Utils/Colors.py +203 -0
  36. DE_Lib/Utils/DateUtils.py +215 -0
  37. DE_Lib/Utils/Generic.py +249 -0
  38. DE_Lib/Utils/SQL.py +34 -0
  39. DE_Lib/Utils/System.py +50 -0
  40. DE_Lib/Utils/WebHook.py +18 -0
  41. DE_Lib/Utils/__init__.py +0 -0
  42. DE_Lib/__init__.py +0 -0
  43. de_lib-0.0.20.dist-info/LICENCE +21 -0
  44. de_lib-0.0.20.dist-info/METADATA +68 -0
  45. de_lib-0.0.20.dist-info/RECORD +47 -0
  46. de_lib-0.0.20.dist-info/WHEEL +5 -0
  47. de_lib-0.0.20.dist-info/top_level.txt +1 -0
DE_Lib/Utils/Colors.py ADDED
@@ -0,0 +1,203 @@
1
+
2
+ class Colors:
3
+ def __init__(self):
4
+ ...
5
+
6
+ # region Cores
7
+ # ----------------------------------------------
8
+ @property
9
+ def __colors__(self):
10
+ result = {"black": {"fore": "\033[1;30m", "back": "\033[1;40m"},
11
+ "red": {"fore": "\033[1;31m", "back": "\033[1;41m"},
12
+ "green": {"fore": "\033[1;32m", "back": "\033[1;42m"},
13
+ "yellow": {"fore": "\033[1;33m", "back": "\033[1;43}"},
14
+ "blue": {"fore": "\033[1;34m", "back": "\033[1;44m"},
15
+ "magenta": {"fore": "\033[1;35m", "back": "\033[1;4}m"},
16
+ "cyan": {"fore": "\033[1;36m", "back": "\033[1;46m"},
17
+ "gray light": {"fore": "\033[1;37m", "back": "\033}1;47m"},
18
+ "gray dark": {"fore": "\033[1;90m", "back": "\033[1;100m}"},
19
+ "red light": {"fore": "\033[1;91m", "back": "\033[1;101}"},
20
+ "green light": {"fore": "\033[1;92m", "back": "\033[1;102m"},
21
+ "yellow light": {"fore": "\033[1;93m", "back": "\033[1;103}"},
22
+ "blue light": {"fore": "\033[1;94m", "back": "\033[1;104m"},
23
+ "magenta light": {"fore": "\033[1;95m", "back": "\033[1;10}m"},
24
+ "cyan light": {"fore": "\033[1;96m", "back": "\033[1;106m"},
25
+ "white": {"fore": "\033[1;97m", "back": "\033[1;107m"},
26
+ "bold": {"fore": "\033[;1m", "back": None},
27
+ "italic": {"fore": "\033[;3m", "back": None},
28
+ "underline": {"fore": "\033[;4m", "back": None},
29
+ "crossedout": {"fore": "\033[;9m", "back": None},
30
+ "inverse": {"fore": "\033[;7m", "back": None},
31
+ "reverse": {"fore": "\033[;17m", "back": None},
32
+ "reset": {"fore": "\033[0;0m", "back": None},
33
+ }
34
+ return result
35
+
36
+ @property
37
+ def black_fore(self):
38
+ return self.__colors__["black"]["fore"]
39
+
40
+ @property
41
+ def black_back(self):
42
+ return self.__colors__["black"]["back"]
43
+
44
+ @property
45
+ def red_fore(self):
46
+ return self.__colors__["red"]["fore"]
47
+
48
+ @property
49
+ def red_back(self):
50
+ return self.__colors__["red"]["back"]
51
+
52
+ @property
53
+ def green_fore(self):
54
+ return self.__colors__["green"]["fore"]
55
+
56
+ @property
57
+ def green_back(self):
58
+ return self.__colors__["green"]["back"]
59
+
60
+ @property
61
+ def green_light_fore(self):
62
+ return self.__colors__["green light"]["fore"]
63
+
64
+ @property
65
+ def green_light_back(self):
66
+ return self.__colors__["green light"]["back"]
67
+
68
+ @property
69
+ def yellow_fore(self):
70
+ return self.__colors__["yellow"]["fore"]
71
+
72
+ @property
73
+ def yellow_back(self):
74
+ return self.__colors__["yellow"]["back"]
75
+
76
+ @property
77
+ def blue_fore(self):
78
+ return self.__colors__["blue"]["fore"]
79
+
80
+ @property
81
+ def blue_back(self):
82
+ return self.__colors__["blue"]["back"]
83
+
84
+ @property
85
+ def magenta_fore(self):
86
+ return self.__colors__["magenta"]["fore"]
87
+
88
+ @property
89
+ def magenta_back(self):
90
+ return self.__colors__["magenta"]["back"]
91
+
92
+ @property
93
+ def cyan_fore(self):
94
+ return self.__colors__["cyan"]["fore"]
95
+
96
+ @property
97
+ def cyan_back(self):
98
+ return self.__colors__["cyan"]["back"]
99
+
100
+ @property
101
+ def gray_light_fore(self):
102
+ return self.__colors__["gray light"]["fore"]
103
+
104
+ @property
105
+ def gray_light_back(self):
106
+ return self.__colors__["gray light"]["back"]
107
+
108
+ @property
109
+ def gray_dark_fore(self):
110
+ return self.__colors__["gray dark"]["fore"]
111
+
112
+ @property
113
+ def gray_dark_back(self):
114
+ return self.__colors__["gray dark"]["back"]
115
+
116
+ @property
117
+ def red_light_fore(self):
118
+ return self.__colors__["red light"]["fore"]
119
+
120
+ @property
121
+ def red_light_back(self):
122
+ return self.__colors__["red light"]["back"]
123
+
124
+ @property
125
+ def green_light_fore(self):
126
+ return self.__colors__["green light"]["fore"]
127
+
128
+ @property
129
+ def green_light_back(self):
130
+ return self.__colors__["green light"]["back"]
131
+
132
+ @property
133
+ def yellow_light_fore(self):
134
+ return self.__colors__["yellow light"]["fore"]
135
+
136
+ @property
137
+ def yellow_light_back(self):
138
+ return self.__colors__["yellow light"]["back"]
139
+
140
+ @property
141
+ def blue_light_fore(self):
142
+ return self.__colors__["blue light"]["fore"]
143
+
144
+ @property
145
+ def blue_light_back(self):
146
+ return self.__colors__["blue light"]["back"]
147
+
148
+ @property
149
+ def magenta_light_fore(self):
150
+ return self.__colors__["magenta light"]["fore"]
151
+
152
+ @property
153
+ def magenta_light_back(self):
154
+ return self.__colors__["magenta light"]["back"]
155
+
156
+ @property
157
+ def cyan_light_fore(self):
158
+ return self.__colors__["cyan light"]["fore"]
159
+
160
+ @property
161
+ def cyan_light_back(self):
162
+ return self.__colors__["cyan light"]["back"]
163
+
164
+ @property
165
+ def white_fore(self):
166
+ return self.__colors__["white"]["fore"]
167
+
168
+ @property
169
+ def white_back(self):
170
+ return self.__colors__["white"]["back"]
171
+
172
+ # endregion
173
+
174
+ # region Efeitos
175
+ @property
176
+ def bold(self):
177
+ return self.__colors__["bold"]["fore"]
178
+
179
+ @property
180
+ def italic(self):
181
+ return self.__colors__["italic"]["fore"]
182
+
183
+ @property
184
+ def underline(self):
185
+ return self.__colors__["underline"]["fore"]
186
+
187
+ @property
188
+ def crossedout(self): # riscado
189
+ return self.__colors__["crossedout"]["fore"]
190
+
191
+ @property
192
+ def inverse(self):
193
+ return self.__colors__["inverse"]["fore"]
194
+
195
+ @property
196
+ def reverse(self):
197
+ return self.__colors__["reverse"]["fore"]
198
+
199
+ @property
200
+ def reset(self):
201
+ return self.__colors__["reset"]["fore"]
202
+
203
+ # endregion
@@ -0,0 +1,215 @@
1
+ import datetime as dt
2
+ from datetime import timedelta
3
+ from dateutil.relativedelta import relativedelta
4
+
5
+ class DateUtils:
6
+ def __init__(self):
7
+ ...
8
+
9
+ # region Miscelanea
10
+ @staticmethod
11
+ def calcular_data(formula, variaveis, mascara):
12
+ """Substitui variáveis na fórmula e calcula a nova data."""
13
+ result = None
14
+ try:
15
+ # Convertendo a string para um objeto datetime
16
+ data_base = dt.datetime.strptime(variaveis["data"], mascara)
17
+ dias = int(variaveis["dias"]) # Convertendo dias para inteiro
18
+
19
+ # Executando a fórmula
20
+ nova_data = eval(formula, {}, {"data": data_base, "timedelta": timedelta, "dias": dias})
21
+ result = nova_data.strftime(mascara)
22
+ except Exception as error:
23
+ result = f"Erro: {error}"
24
+ finally:
25
+ return result
26
+ # endregion
27
+
28
+ # region Data As Long
29
+ @staticmethod
30
+ def Date_to_DateAsLong(value):
31
+ try:
32
+ dataaslong = int(dt.datetime.timestamp(value) * 1e3)
33
+ return dataaslong
34
+ except Exception as error:
35
+ msgerro = f"""Falha ao tentar transformar um DATA em um LONG: "{value}". {error}"""
36
+ raise Exception(msgerro)
37
+
38
+ @staticmethod
39
+ def DateAsLong_to_Date(value):
40
+ try:
41
+ date = dt.datetime.fromtimestamp(value / 1e3)
42
+ return date
43
+ except Exception as error:
44
+ msgerro = f"""Falha ao tentar transformar um LONG em uma data: "{value}". {error}"""
45
+ raise Exception(msgerro)
46
+
47
+ @staticmethod
48
+ def TimeAsLong_to_Time(value: dt.timedelta):
49
+ try:
50
+ horas_total = round((value.days * 24) + int(value.seconds / 60 / 60), 2)
51
+ minutos = round(((value.seconds / 60 / 60) - int((value.seconds / 60) / 60)) * 60, 2)
52
+ seg = round(((minutos - int(minutos)) * 60), 2)
53
+ hora = f"""{horas_total}:{int(minutos):02}:{int(round(seg)):02}"""
54
+ return hora
55
+ except Exception as error:
56
+ msgerro = f"""Falha ao tentar converter um timedelta para um tempo (HH:mm:ss) "{value}". {error}"""
57
+ raise Exception(msgerro)
58
+
59
+ @staticmethod
60
+ def Time_to_TimeAsLong(value):
61
+ try:
62
+ td = value.split(":")
63
+ h = round(int(td[0]) * 60 * 60 * 1000)
64
+ m = round(int(td[1]) * 60 * 1000)
65
+ s = round(int(td[2]) * 1000)
66
+ tempo = h + m + s
67
+ return tempo
68
+ except Exception as error:
69
+ msgerro = f"""Falha ao tentar converter um horario em LONG "{value}". {error}"""
70
+ raise Exception(msgerro)
71
+ # endregion
72
+
73
+ # region Dias Ano, Semestre, Mes, Quinzena
74
+ @staticmethod
75
+ def getPrimeiroDiaAno(data: dt.datetime) -> dt.datetime:
76
+ result = dt.datetime(year=data.year, month=1, day=1, hour=0, minute=0, second=0)
77
+ return result
78
+
79
+ @staticmethod
80
+ def getUltimoDiaAno(data: dt.datetime) -> dt.datetime:
81
+ result = dt.datetime(year=data.year, month=12, day=31, hour=23, minute=59, second=59)
82
+ return result
83
+
84
+ @staticmethod
85
+ def getPrimeiroDiaSemestre(data: dt.datetime) -> dt.datetime:
86
+ if data.month >=7:
87
+ month = 7
88
+ else:
89
+ month = 1
90
+ result = dt.datetime(year=data.year, month=month, day=1, hour=0, minute=0, second=0)
91
+ return result
92
+
93
+ @staticmethod
94
+ def getUltimoDiaSemestre(data: dt.datetime) -> dt.datetime:
95
+ if data.month >= 7:
96
+ month = 12
97
+ day = 31
98
+ else:
99
+ month = 6
100
+ day = 30
101
+ result = dt.datetime(year=data.year, month=month, day=day, hour=23, minute=59, second=59)
102
+ return result
103
+
104
+ @staticmethod
105
+ def getPrimeiroDiaMes(data: dt.datetime) -> dt.datetime:
106
+ result = dt.datetime(year=data.year, month=data.month, day=1, hour=0, minute=0, second=0)
107
+ return result
108
+
109
+ @staticmethod
110
+ def getUltimoDiaMes(data: dt.datetime) -> dt.datetime:
111
+ # result = data + relativedelta(day=31)
112
+ result = dt.datetime(year=data.year, month=data.month, day=(data + relativedelta(day=31)).day, hour=23,
113
+ minute=59, second=59)
114
+ return result
115
+
116
+ @staticmethod
117
+ def getPrimeiroDiaQuinzena(data: dt.datetime) -> dt.datetime:
118
+ if data.day > 15:
119
+ day = 16
120
+ else:
121
+ day = 1
122
+ result = dt.datetime(year=data.year, month=data.month, day=day, hour=0, minute=0, second=0)
123
+ return result
124
+
125
+ @staticmethod
126
+ def getUltimoDiaQuinzena(data: dt.datetime) -> dt.datetime:
127
+ if data.day > 15:
128
+ day = data + relativedelta(day=31).day
129
+ else:
130
+ day = 15
131
+ result = dt.datetime(year=data.year, month=data.month, day=day, hour=23, minute=59, second=59)
132
+ return result
133
+
134
+ @staticmethod
135
+ def getPrimeiraHoraDia(data: dt.datetime) -> dt.datetime:
136
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=0, minute=0, second=0)
137
+ return result
138
+ # endregion
139
+
140
+ # region Horas, minutos, segundos, milisegundos
141
+ @staticmethod
142
+ def getUltimaHoraDia(data: dt.datetime) -> dt.datetime:
143
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=23, minute=59, second=59)
144
+ return result
145
+
146
+ @staticmethod
147
+ def getPrimeiroMinutoHora(data: dt.datetime) -> dt.datetime:
148
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=0, second=0)
149
+ return result
150
+
151
+ @staticmethod
152
+ def getUltimoMinutoHora(data: dt.datetime) -> dt.datetime:
153
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=59, second=59)
154
+ return result
155
+
156
+ @staticmethod
157
+ def getPrimeiroSegundoMinuto(data: dt.datetime) -> dt.datetime:
158
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=data.minute, second=0)
159
+ return result
160
+
161
+ @staticmethod
162
+ def getUltimoSegundoMinuto(data: dt.datetime) -> dt.datetime:
163
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=data.minute, second=59)
164
+ return result
165
+
166
+ @staticmethod
167
+ def getPrimeiroMilesimoSegundo(data: dt.datetime) -> dt.datetime:
168
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=data.minute,
169
+ second=data.second, microsecond=0)
170
+ return result
171
+
172
+ @staticmethod
173
+ def getUltimoMilesimoSegundo(data: dt.datetime) -> dt.datetime:
174
+ result = dt.datetime(year=data.year, month=data.month, day=data.day, hour=data.hour, minute=data.minute,
175
+ second=data.second, microsecond=99999)
176
+ return result
177
+ # endregion
178
+
179
+ # region DATA/HORA mascaras SQL | PYTHON
180
+ @property
181
+ def DATE_FORMAT_PYTHON(self):
182
+ return "%Y-%m-%d"
183
+
184
+ @property
185
+ def DATETIME_FORMAT_PYTHON(self):
186
+ return "%Y-%m-%d %H:%M:%S"
187
+
188
+ @property
189
+ def MILLISECONDS_FORMAT_PYTHON(self):
190
+ return "%Y-%m-%d %H:%M:%S:%f"
191
+
192
+ @property
193
+ def TIME_FORMAT_PYTHON(self):
194
+ return "%H:%M:%S:%f"
195
+
196
+ @property
197
+ def DATE_FORMAT_SQL(self):
198
+ return "YYYY-MM-DD"
199
+
200
+ @property
201
+ def DATETIME_FORMAT_SQL(self):
202
+ return "YYYY-MM-DD HH24:MI:SS"
203
+
204
+ @property
205
+ def MILLISECONDS_FORMAT_SQL(self):
206
+ return "YYYY-MM-DD HH24:MI:SS:FF6"
207
+
208
+ @property
209
+ def TIME_FORMAT_SQL(self):
210
+ return "HH24:MI:SS:FF6"
211
+
212
+ @property
213
+ def DATETIME_FILENAME(self):
214
+ return "%Y%m%d%H%M%S"
215
+ # endregion
@@ -0,0 +1,249 @@
1
+ import hashlib
2
+ import string
3
+ from random import choice
4
+ import random as rd
5
+ import re
6
+ import datetime as dt
7
+ import sys
8
+
9
+
10
+ class Generic:
11
+ def __init__(self):
12
+ ...
13
+
14
+ # region Miscelanea
15
+ @staticmethod
16
+ def findchar(string: str, pattern: str, ocorrencia: int = None, inicio: int = 0, fim: int = 0, trim: bool = True):
17
+ locate = None
18
+ try:
19
+ if trim:
20
+ string = string.strip()
21
+ if fim == 0:
22
+ fim = len(string)
23
+ if fim > inicio and (fim-inicio) > len(pattern):
24
+ string = string[inicio:fim]
25
+ if ocorrencia is not None:
26
+ locate = re.findall(pattern, string)
27
+ if ocorrencia is not None:
28
+ if ocorrencia > len(locate):
29
+ locate = locate[len(locate)-1]
30
+ except Exception as error:
31
+ locate = error
32
+ finally:
33
+ return locate
34
+
35
+ @staticmethod
36
+ def random_generator(size: int = 6, chars: str = string.ascii_uppercase + string.digits):
37
+ value = ''.join(rd.choice(chars) for _ in range(size))
38
+ return value
39
+
40
+ @staticmethod
41
+ def DictSizeBytes(dictName: dict) -> int:
42
+ result = 0
43
+ if isinstance(dictName, dict):
44
+ result = sys.getsizeof(dictName)
45
+ for key, valor in dictName.items():
46
+ result += sys.getsizeof(key) + sys.getsizeof(valor)
47
+ return result
48
+
49
+ def calcular_formula(self, formula: str, variaveis):
50
+ msg, result = None, None
51
+ try:
52
+ result = eval(formula, {}, variaveis)
53
+ except Exception as error:
54
+ msg = error
55
+ result = msg
56
+ finally:
57
+ return result
58
+ # endregion
59
+
60
+ # region Keys e Hash´s
61
+ @staticmethod
62
+ def build_key(size: int = 24,
63
+ sep: str = "-",
64
+ word_length: int = 4,
65
+ lower_case: bool = True,
66
+ upper_case: bool = True,
67
+ digits: bool = True,
68
+ hex_digits: bool = False,
69
+ oct_digits: bool = False,
70
+ special_chars: bool = False,
71
+ printable_chars: bool = False,
72
+ control_chars: bool = False
73
+ ) -> str:
74
+ index = 1
75
+ key = ""
76
+ literal = ""
77
+ if lower_case:
78
+ literal = literal + string.ascii_lowercase
79
+ if upper_case:
80
+ literal = literal + string.ascii_uppercase
81
+ if digits:
82
+ literal = literal + string.digits
83
+ if hex_digits:
84
+ literal = literal + string.hexdigits
85
+ if oct_digits:
86
+ literal = literal + string.octdigits
87
+ if special_chars:
88
+ literal = literal + string.punctuation
89
+ if printable_chars:
90
+ literal = literal + string.printable
91
+ if control_chars:
92
+ literal = literal + string.whitespace
93
+ try:
94
+ for i in range(size):
95
+ letra = choice(literal)
96
+ if index == word_length and i < size - 1:
97
+ key += letra + sep
98
+ index = 1
99
+ else:
100
+ key += letra
101
+ index += 1
102
+ except Exception as error:
103
+ key = f"Impossivel gerar uma chave. Erro: {error}"
104
+ return key
105
+
106
+ @staticmethod
107
+ def build_keys(qtd: int = 1,
108
+ size: int = 24,
109
+ sep: str = "-",
110
+ word_length: int = 4,
111
+ lower_case: bool = True,
112
+ upper_case: bool = True,
113
+ digits: bool = True,
114
+ hex_digits: bool = False,
115
+ oct_digits: bool = False,
116
+ special_chars: bool = False,
117
+ printable_chars: bool = False,
118
+ control_chars: bool = False) -> list:
119
+ keys = []
120
+ for index in range(qtd):
121
+ k = Generic.build_key(size=size,
122
+ sep=sep,
123
+ word_length=word_length,
124
+ lower_case=lower_case,
125
+ upper_case=upper_case,
126
+ digits=digits,
127
+ hex_digits=hex_digits,
128
+ oct_digits=oct_digits,
129
+ special_chars=special_chars,
130
+ printable_chars=printable_chars,
131
+ control_chars=control_chars
132
+ )
133
+ keys.append(k)
134
+ return keys
135
+
136
+ @staticmethod
137
+ def hash(word: str, pattern: str = "md5"):
138
+ pattern_list = ["md5", "sha1", "sha224", "sha256", "sha384", "sha512"]
139
+ h, msg, error = None, None, None
140
+ try:
141
+ #value /= b'{word}'/
142
+ if pattern == pattern_list[0]:
143
+ h = hashlib.md5()
144
+ elif pattern == pattern_list[1]:
145
+ h = hashlib.sha1()
146
+ elif pattern == pattern_list[2]:
147
+ h = hashlib.sha224()
148
+ elif pattern == pattern_list[3]:
149
+ h = hashlib.sha256()
150
+ elif pattern == pattern_list[4]:
151
+ h = hashlib.sha384()
152
+ elif pattern == pattern_list[5]:
153
+ h = hashlib.sha512()
154
+ h.update(word.encode())
155
+ msg = h.hexdigest()
156
+ except Exception as error:
157
+ msg = f"""Erro ao tentar montar o HASH. Erro: {error}"""
158
+ finally:
159
+ return msg
160
+ # endregion
161
+
162
+ # region Validações Lógicas
163
+ @staticmethod
164
+ def ifnull(var, val):
165
+ if (var is None or var == 'None'):
166
+ value = val
167
+ else:
168
+ value = var
169
+ return value
170
+
171
+ @staticmethod
172
+ def iif(condicao: bool, value_true, value_false):
173
+ if condicao:
174
+ value = value_true
175
+ else:
176
+ value = value_false
177
+ return value
178
+
179
+ @staticmethod
180
+ def nvl(value, default):
181
+ msg, result = None, None
182
+ try:
183
+ if (value is not None):
184
+ result = value
185
+ else:
186
+ result = default
187
+ return result
188
+ except Exception as error:
189
+ msg = error
190
+ result = msg
191
+ finally:
192
+ return result
193
+
194
+ @staticmethod
195
+ def is_valid_int(value):
196
+ msg, result = None, True
197
+ try:
198
+ int(value)
199
+ except Exception as error:
200
+ msg = error
201
+ result = False
202
+ finally:
203
+ return result
204
+
205
+ @staticmethod
206
+ def is_valid_float(value):
207
+ msg, result = None, True
208
+ try:
209
+ float(value)
210
+ except Exception as error:
211
+ msg = error
212
+ result = False
213
+ finally:
214
+ return result
215
+
216
+ @staticmethod
217
+ def is_valid_type(value, type, default_value, format=None):
218
+ msg, result = None, None
219
+ try:
220
+ if type.upper() == 'DATE':
221
+ default_value = dt.datetime.strptime(value, format)
222
+ elif type.upper() == 'INT':
223
+ default_value = int(value)
224
+ elif type.upper() == "FLOAT":
225
+ default_value = float(value)
226
+ else:
227
+ raise Exception
228
+ result = default_value
229
+ except Exception as error:
230
+ msg = error
231
+ result = msg
232
+ finally:
233
+ return result
234
+
235
+ @staticmethod
236
+ def is_valid_date(date_str: str, mascara: str = "%Y-%m-%d %H:%M:%S"):
237
+ msg, result = None, True
238
+ try:
239
+ dt.datetime.strptime(date_str, mascara)
240
+ except Exception as error:
241
+ msg = error
242
+ result = False
243
+ finally:
244
+ return result
245
+ # endregion
246
+
247
+
248
+
249
+
DE_Lib/Utils/SQL.py ADDED
@@ -0,0 +1,34 @@
1
+
2
+
3
+ class SQL:
4
+ def __init__(self):
5
+ ...
6
+
7
+ @staticmethod
8
+ def colunas_cursor(cursor) -> list:
9
+ header = [head[0] for head in cursor.description]
10
+ return header
11
+
12
+ @staticmethod
13
+ def Crud(sql: str = None, values: dict = None, conexao=None, commit: bool = True):
14
+ msg, result, linhas_afetadas = None, [], 0
15
+ try:
16
+ if not isinstance(sql, str) or sql is None:
17
+ raise Exception(f"""Comando sql não foi definido {sql}""")
18
+ if conexao is None:
19
+ raise Exception(f"""Conexão não foi informada {conexao}""")
20
+ if not isinstance(values, dict):
21
+ raise Exception(f"""Lista de valores não foi informada {values}""")
22
+ cursor = conexao.cursor()
23
+ cursor.execute(sql, values)
24
+ linhas_afetadas = cursor.rowcount
25
+ cursor.close()
26
+ if commit:
27
+ conexao.commit()
28
+ msg = f"""Comando SQL executado com sucesso!"""
29
+ except Exception as error:
30
+ msg = f"""Falha ao tentar executar o comando SQL! Erro: {error}"""
31
+ result = msg
32
+ finally:
33
+ result = {"linhas_afetadas": linhas_afetadas, "mensagem": msg, "sql": sql}
34
+ return result