-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
92 lines (76 loc) · 2.2 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Used Python 3
# Created by Robson Aristóteles Campos de Souza
# At 2017/05
import codecs
import cx_Oracle
import os
import string
import sys
import time
os.environ["NLS_LANG"] = ".AL32UTF8"
START_VALUE = u"Unicode \u3042 3"
END_VALUE = u"Unicode \u3042 6"
def main():
# Build connection string
user = "USUARIO"
host = "host.com.br"
port = "1521"
sid = "adm"
pswd = "senha"
dsn = cx_Oracle.makedsn (host, port, sid)
# Connect to Oracle and test
con = cx_Oracle.connect (user, pswd, dsn)
start = time.time()
if (con):
print("Connection successful")
print(con.version)
print("--------------------------")
cur = con.cursor()
cur.execute('select * from emp order by empno')
res = cur.fetchall()
elapsed = (time.time() - start)
print(elapsed, " seconds")
for result in cur:
print(result)
print("----------Fet----------------")
for r in res:
print(r)
print("------------Fim--------------")
cur.close()
else:
print("Connection not successful")
con.close()
def grava_registro_bd(param):
# Build connection string
user = "USUARIO"
host = "host.com.br"
port = "1521"
sid = "adm"
pswd = "senha"
dsn = cx_Oracle.makedsn (host, port, sid)
con = cx_Oracle.connect (user, pswd, dsn)
start = time.time()
if (con):
cur = con.cursor()
cur.execute("INSERT INTO TB1 (COLUMN1, COLUMN2) VALUES ("+str(param[0])+", '"+param[4]+"')")
else:
print("Connection not successful")
con.commit()
con.close()
def lista_diretorios():
print("Listing arcives in directory.")
path = "/Users/robson.aristoteles/Documents/workspace/project/"
for filename in os.listdir(path):
print("Starting file import '",filename,"' size:",round(os.stat(path+filename).st_size/1024/1024,2),"MB")
with open(path+filename, encoding = "UTF-8") as f:
for line in f:
valor_linha = line.replace('"', '').strip('\n').split(';')
grava_registro_bd(valor_linha)
f.close()
print("Finish...",filename)
if __name__ == '__main__':
start = time.time()
# main()
lista_diretorios()
elapsed = (time.time() - start)
print(elapsed, " seconds")