by
228 7
0
3
172
0
Top 5% !
Specified
OpenSource
Popularity: 27486th place
Created
Modified Sep 29, 2016
No tags for this snippet yet.
Languagepython
LicenseMIT_X11

Importação de CSV de histórico de cotações

post this code
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1461635/Importa--o-de-CSV-de-hist-rico-de-cota--?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
//https://br.financas.yahoo.com/q/hp?s=BRAP3.SA&a=07&b=14&c=2000&d=06&e=6&f=2016&g=d import csv import MySQLdb arquivo = 'BRAP3.csv' I = 0 with open(arquivo,) as csvfile: readCSV = csv.reader(csvfile, delimiter=',') for row in readCSV: if(row[0] != 'Date'): I = I + 1 ##print('Data: ' + row[0] + ' Abertura: ' + row[1] + ' +Alta: ' + row[2] + ' -Baixa: ' + row[3] + ' Fechamento: ' + row[4] + ' Volume: ' + row[5]) db = MySQLdb.connect("192.168.1.101","******","********","*******" ) cursor = db.cursor() SQL = "insert into historico_cotacoes (data, abertura, maior_alta, maior_baixa, fechamento, volume_negociado, ajusta_fechamento,data_importacao) values ( " SQL = SQL + " '" + row[0] + "', " + row[1] + ", " + row[2] + ", " + row[3] + ", " + row[4] + ", " + row[5] + ", " + row[6] +", CURRENT_DATE); " #print SQL cursor.execute(SQL) db.commit() db.close() if(str(I)[-1:] == '0'): print "################################## " + str(I) + " Inseridos #############################################" print "################################## " + str(I) + " Registros inseridos #############################################"
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus