get_data/hue_polling_to_db.py
def retrieve_knmi_weather_parent():
	""" Parent of KNMI polling to make sure only once every 5 minutes is being polled.
	In any other situation we will use the last known value
	"""
	# Check if last KNMI poll < 5 minutes old. Don't retrieve new value.
	con = sqlite3.connect(DB)
	cur = con.cursor()

	query = """
			SELECT 
				MAX(polling_timestamp)
				FROM {0};
		""".format(DB_TABLE_KNMI_CACHE)

	# Execute query
	cur.execute(query)        	
	rows = cur.fetchall()

	# Parse age
	latest_time = "1970-01-01 01:00:00"
	for row in rows:
		latest_time = row[0]
	print(latest_time)
	if latest_time is None:
		return retrieve_knmi_weather()

	
	if time.strptime(latest_time, "%Y-%m-%d %H:%M:%S") > (time.gmtime()-900):
		# Save new latest
		try:
			time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
			cur.execute("INSERT OR IGNORE INTO {0} VALUES({1})".format(DB_TABLE_KNMI_CACHE, time_string))
		except:
			print "WARNING: Failed writing time to KNMI DB Cache; '{0}'"

		# Retrieve
		return retrieve_knmi_weather()
	else:
		return False

	con.close()
 Parent of KNMI polling to make sure only once every 5 minutes is being polled.
	In any other situation we will use the last known value
	
Parent of KNMI polling to make sure only once every 5 minutes is being polled.
In any other situation we will use the last known value
Parent of KNMI polling to make sure only once every 5 minutes is being polled . In any other situation we will use the last known value
def retrieve_knmi_weather_parent():
	con = sqlite3.connect(DB)
	cur = con.cursor()
	query = """
			SELECT 
				MAX(polling_timestamp)
				FROM {0};
		""".format(DB_TABLE_KNMI_CACHE)
	cur.execute(query)        	
	rows = cur.fetchall()
	latest_time = "1970-01-01 01:00:00"
	for row in rows:
		latest_time = row[0]
	print(latest_time)
	if latest_time is None:
		return retrieve_knmi_weather()
	if time.strptime(latest_time, "%Y-%m-%d %H:%M:%S") > (time.gmtime()-900):
		try:
			time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
			cur.execute("INSERT OR IGNORE INTO {0} VALUES({1})".format(DB_TABLE_KNMI_CACHE, time_string))
		except:
			print "WARNING: Failed writing time to KNMI DB Cache; '{0}'"
		return retrieve_knmi_weather()
	else:
		return False
	con.close()
def retrieve_knmi_weather_parent ( ) : con = sqlite3 . connect ( DB ) cur = con . cursor ( ) query = """
			SELECT 
				MAX(polling_timestamp)
				FROM {0};
		""" . format ( DB_TABLE_KNMI_CACHE ) cur . execute ( query ) rows = cur . fetchall ( ) latest_time = "1970-01-01 01:00:00" for row in rows : latest_time = row [ 0 ] print ( latest_time ) if latest_time is None : return retrieve_knmi_weather ( ) if time . strptime ( latest_time , "%Y-%m-%d %H:%M:%S" ) > ( time . gmtime ( ) - 900 ) : try : time_string = time . strftime ( "%Y-%m-%d %H:%M:%S" , time . gmtime ( ) ) cur . execute ( "INSERT OR IGNORE INTO {0} VALUES({1})" . format ( DB_TABLE_KNMI_CACHE , time_string ) ) except : print "WARNING: Failed writing time to KNMI DB Cache; '{0}'" return retrieve_knmi_weather ( ) else : return False con . close ( )
Parent of KNMI polling to make sure only once every 5 minutes is being polled.
Parent of KNMI polling to make sure only once every 5 minutes is being polled .
""" Parent of KNMI polling to make sure only once every 5 minutes is being polled.
	In any other situation we will use the last known value
	""" # Check if last KNMI poll < 5 minutes old. Don't retrieve new value. # Execute query # Parse age # Save new latest # Retrieve