-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adiciona no banco as novas informações de professores
- Loading branch information
1 parent
82dac32
commit 3254c71
Showing
10 changed files
with
1,137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
import pymysql.cursors | ||
import json | ||
|
||
# Carregar os dados do JSON | ||
with open('../../data/info-pessoais-professores.json', 'r', encoding='utf-8') as file: | ||
data = json.load(file) | ||
|
||
# Estabelecer a conexão com o banco de dados | ||
connection = pymysql.connect( | ||
host='35.193.233.216', | ||
user='root', | ||
password='mdssquad4avaliaunbdb24', | ||
database='avalia_unb', | ||
charset='utf8mb3', | ||
cursorclass=pymysql.cursors.DictCursor | ||
) | ||
|
||
try: | ||
with connection.cursor() as cursor: | ||
# Atualizar a tabela de professores e inserir as graduações | ||
for professor in data['dados']: | ||
# Atualizar os dados do professor na tabela de professores | ||
sql_professor = """ | ||
UPDATE professor | ||
SET email = %s, sala = %s | ||
WHERE cod_professor = %s | ||
""" | ||
cursor.execute(sql_professor, (professor['email'], professor['sala'], professor['codigo'])) | ||
|
||
# Inserir as graduações do professor na tabela professor_graduacoes | ||
for graduacao in professor['graduacoes']: | ||
sql_graduacao = """ | ||
INSERT INTO professor_graduacoes (cod_professor, graduacao) | ||
VALUES (%s, %s) | ||
""" | ||
cursor.execute(sql_graduacao, (professor['codigo'], graduacao)) | ||
|
||
# Confirmar as alterações no banco de dados | ||
connection.commit() | ||
print("Dados atualizados com sucesso!") | ||
|
||
except Exception as e: | ||
# Em caso de erro, imprimir o erro e fazer rollback das alterações | ||
print("Erro:", e) | ||
connection.rollback() | ||
|
||
finally: | ||
# Fechar a conexão com o banco de dados | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
import pymysql.cursors | ||
import json | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Esses dados foram retirados da listagem de professores do Sigaa e serão usados para o preenchimento do banco de dados |
Oops, something went wrong.