-
Notifications
You must be signed in to change notification settings - Fork 1
/
connector.py
38 lines (29 loc) · 1.2 KB
/
connector.py
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
import mysql.connector
from dbfread import DBF
import os
try:
path = 'files\\'
files = os.listdir(path)
connection = mysql.connector.connect(host='localhost',
database='votacao_camara_deputados',
user='root',
password='medsys')
for file_name in files:
full_path = path + file_name
cursor = connection.cursor()
for record in DBF(full_path):
values = "'" + record["NUMVOT"] + "','" + record["NOME_PAR"] + \
"','" + record["ESTADO"] + "','" + record["VOTO"] + \
"','" + record["PARTIDO"] + "'"
mySql_insert_query = """INSERT INTO votos (Proposicao, Parlamentar, UF, Voto, Partido)
VALUES (""" + values + """) """
print(mySql_insert_query)
cursor.execute(mySql_insert_query)
connection.commit()
cursor.close()
except mysql.connector.Error as error:
print("Failed to insert record into votos table {}".format(error))
finally:
if connection.is_connected():
connection.close()
print("MySQL connection is closed")