Vielen Dank für die Antwort. Ich bekomme von 40 Währungspaaren täglich Daten. Gesammelt habe ich seit dem 04.01.1999 bis heute. Die Daten werden in Form von CSV Dateien geliefert. Mittlerweile ist die Datenflut auf 16GB angewachsen.
Hier eine Beispiel für eine CSV Datei. Die anderen CSV Dateien sind genauso aufgebaut.
Folgende Aufgaben habe ich noch zu lösen:
1. wie soll der Datenbankentwurf aussehen?
2. wie importiere ich die Daten ?
3. wie geht man bei Fehlern während des Datenimportes in die Datenbank vor?
4. automatisches Versenden einer Email nach jedem Datenimport, um zu wissen, dass der Import gelaufen ist.
Vielen Dank für die Hilfe
Code: Alles auswählen
"Date","Time","Open","High","Low","Close","Total Ticks"
01.03.2016,19:30:00,1.08627,1.08627,1.08535,1.08535,1
01.03.2016,19:31:00,1.08535,1.08538,1.08535,1.08538,1
01.03.2016,19:32:00,1.08538,1.08564,1.08535,1.08564,4
01.03.2016,19:33:00,1.08564,1.08564,1.08536,1.08564,13
01.03.2016,19:35:00,1.08564,1.08564,1.08564,1.08564,2
01.03.2016,19:37:00,1.08564,1.08564,1.08561,1.08561,1
01.03.2016,19:38:00,1.08561,1.08563,1.08561,1.08562,2
01.03.2016,19:39:00,1.08562,1.08563,1.08562,1.08562,2
01.03.2016,19:40:00,1.08562,1.08568,1.08562,1.08566,3
01.03.2016,19:45:00,1.08566,1.08566,1.08551,1.08553,7
01.03.2016,19:49:00,1.08553,1.08553,1.08543,1.08543,1
01.03.2016,19:50:00,1.08543,1.08548,1.08543,1.08543,2
Das Script sieht jetzt so aus:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding:utf-8 -*-
import csv
import glob
import MySQLdb
import os
# Use the absolute path
file_path = os.path.abspath(__file__)
# Traverse the directory and process each .csv file
for csvfile in glob.glob('data/*.csv'):
# Remove the path and extension and use what's as a table name
table_name = os.path.splitext(os.path.basename(csvfile))[0]
# Open database connection
try:
db = MySQLdb.connect(host="localhost", user="user", passwd="passwd", db="db")
# Prepare a cursor object using cursor() method
cursor = db.cursor()
# Drop table if it already exist using execute() method
# cursor.execute("""DROP TABLE IF EXISTS EURUSD""")
# Execute MySQL command to create specified table
sql = """CREATE TABLE IF NOT EXISTS %s
(id int NOT NULL AUTO_INCREMENT,
Date date NOT NULL,
Time time NOT NULL,
Open decimal NOT NULL,
High decimal NOT NULL,
Low decimal NOT NULL,
Close decimal NOT NULL,
PRIMARY KEY (id))""" % table_name
cursor.execute(sql)
# print (sql)
# Error messages
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
# Quit ython script
sys.exit(1)
# Disconnect from server
finally:
if db:
db.close()