#!/usr/bin/python

import sys,time,os
from medon_data import *

id = "MeDON_data"

def main():
	yearname = "/root/MeDON/%s_%s" %(id, time.strftime("%Y", time.gmtime()))
	print "Creating directory %s" %yearname
	os.system("mkdir %s" %yearname)
	monthname = "%s" %(time.strftime("%B", time.gmtime()))
	print "Creating directory %s" %monthname
	os.system("mkdir %s/%s" %(yearname, monthname))
	filepath = "%s/%s/%s" %(yearname, monthname, time.strftime("%Y%m%d", time.gmtime()))
	print("Time: %s" %time.strftime("%H:%M:%S", time.gmtime()))
	if not os.path.exists(filepath):
		FILE = open(filepath, "w")
		FILE.write("Date, Time, Temp, Cond, Sal, DOsat, DO, Depth, pH, ORP, Chl, Turb, Batt, OCR412.5, OCR443.1, OCR490.7, OCR510.5, OCR555.2, OCR619.4, OCR665.5, NULL\n\r")
		FILE.write("d/m/y, hh:mm:ss, C, mS/cm, ppt, %, mg/L, m, pH, mV, ug/L, NTU, volts, uW/cm2/nm/sr, ditto, ditto, ditto, ditto, ditto, ditto\n\r")
		FILE.close()
	FILE = open(filepath, "a")
	data_str = "%s\n" %get_data()
	FILE.write(data_str)
	FILE.close()

if __name__ == '__main__':
	main()
