Created
April 12, 2013 08:34
-
-
Save nipunbatra/5370512 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
import time | |
import MySQLdb | |
DATA_PATH='/home/nipun/Desktop/' | |
THRESHOLD_TIME=300 | |
connection = MySQLdb.Connect(host='', user='root', passwd='password', db='smart_meter_data',local_infile = 1) | |
cursor = connection.cursor() | |
folders=os.listdir(DATA_PATH) | |
try: | |
list_of_files=glob.glob(str(DATA_PATH)+str("/*.csv")) | |
for f in list_of_files: | |
if int(time.time())-int(os.stat(f).st_mtime)>THRESHOLD_TIME: | |
query = "LOAD DATA LOCAL INFILE "+"'"+f+"'"+" INTO TABLE data FIELDS TERMINATED BY ',' IGNORE 1 LINES" | |
cursor.execute(query) | |
connection.commit() | |
os.remove(f) | |
except MySQLdb.Error,e: | |
pass | |
else: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment