-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtabela_AGtaco3_SQL.py
31 lines (28 loc) · 953 Bytes
/
tabela_AGtaco3_SQL.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
#! /usr/bin/env/ python
import string
arquivo = open('taco_AG.csv','r')
arquivoSQL =open('insert_AGtaco3.sql','wr')
conteudo=arquivo.readlines()
tamanhoLista= len(conteudo)
print 'tamanho da lista: ',tamanhoLista
i=0
for item in conteudo:
item=item.strip()
#print item
listaSQL = []
for item in conteudo:
item.replace("\n"," ")
item=item.strip()
linha=string.split(item,";")
dados="INSERT INTO AGtaco3 (id, categoria, numeroAlimento, descricaoAlimento, saturados, monoinsaturados, poliinsaturados, 12_0, 14_0, 16_0, 18_0, 20_0, 22_0, 24_0, 14_1, 16_1, 18_1, 20_1, 18_2N_6, 18_3N_3, 20_4, 20_5, 22_5, 22_6, 18_1t, 18_2t, created_at, updated_at) VALUES (''"
t=0
while (t < len(linha)):
dados = dados+",'"+linha[t]+"'"
t=t+1
dados = dados+");\n"
arquivoSQL.writelines(dados)
i = i + 1
print 'feito a linha: ', i
print '** FINALIZADO! Favor, verifique o aqruivo. **'
arquivoSQL.close()
arquivo.close()