get_data/hue_polling_to_db.py
def write_db(results):
	""" Writes list of CSV lines (results) to database
	"""

	if influx_url is not None:
		log_to_influx_db(results, influx_url)

	# Set up DB connection
	con = sqlite3.connect(DB)
	cur = con.cursor()


	time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())

	# Write to DB
	for line in results:
		# print('line', line)
		try:
			split_line = line.split(';')
			un = "{0}{1}".format(split_line[0],split_line[7])
			insert_data = ','.join(split_line)
			#un = "{0}{1}".format(insert_data[0],insert_data[7])
			insert_vals = "{},{},{}".format(un, time_string, insert_data)
			insert_vals = ','.join(["'{}'".format(val) for val in insert_vals.split(',')])
			# print(un)
			# print(insert_vals)
			query_str = "INSERT OR IGNORE INTO {0} VALUES({1})".format(DB_TABLE, insert_vals)
			# print(query_str)
			cur.execute(query_str)
		except:
			print "WARNING: Failed writing line to DB; '{0}'".format(line)
	con.commit()
	con.close()
 Writes list of CSV lines (results) to database
	
Writes list of CSV lines (results) to database
Writes list of CSV lines ( results ) to database
def write_db(results):
	if influx_url is not None:
		log_to_influx_db(results, influx_url)
	con = sqlite3.connect(DB)
	cur = con.cursor()
	time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
	for line in results:
		try:
			split_line = line.split(';')
			un = "{0}{1}".format(split_line[0],split_line[7])
			insert_data = ','.join(split_line)
			insert_vals = "{},{},{}".format(un, time_string, insert_data)
			insert_vals = ','.join(["'{}'".format(val) for val in insert_vals.split(',')])
			query_str = "INSERT OR IGNORE INTO {0} VALUES({1})".format(DB_TABLE, insert_vals)
			cur.execute(query_str)
		except:
			print "WARNING: Failed writing line to DB; '{0}'".format(line)
	con.commit()
	con.close()
def write_db ( results ) : if influx_url is not None : log_to_influx_db ( results , influx_url ) con = sqlite3 . connect ( DB ) cur = con . cursor ( ) time_string = time . strftime ( "%Y-%m-%d %H:%M:%S" , time . gmtime ( ) ) for line in results : try : split_line = line . split ( ';' ) un = "{0}{1}" . format ( split_line [ 0 ] , split_line [ 7 ] ) insert_data = ',' . join ( split_line ) insert_vals = "{},{},{}" . format ( un , time_string , insert_data ) insert_vals = ',' . join ( [ "'{}'" . format ( val ) for val in insert_vals . split ( ',' ) ] ) query_str = "INSERT OR IGNORE INTO {0} VALUES({1})" . format ( DB_TABLE , insert_vals ) cur . execute ( query_str ) except : print "WARNING: Failed writing line to DB; '{0}'" . format ( line ) con . commit ( ) con . close ( )
Writes list of CSV lines (results) to database
Writes list of CSV lines ( results ) to database
""" Writes list of CSV lines (results) to database
	""" # Set up DB connection # Write to DB # print('line', line) #un = "{0}{1}".format(insert_data[0],insert_data[7]) # print(un) # print(insert_vals) # print(query_str)
results