Beispiel #1
0
def getLastVal(type):
	# get the data
	cur.execute("SELECT * FROM {0} ORDER BY time DESC LIMIT 1;".format(
		type
	))
	
	# return!
	return cur.fetchone()
Beispiel #2
0
def doorTweet():
	from LGSStatus import twitter
	
	# get the last two door states
	cur.execute("SELECT * FROM door ORDER BY time DESC LIMIT 2;")
	states = cur.fetchall()
	
	if states[0][1] != states[1][1]:
		# check what to tweet - door opened
		if states[0][1] > states[1][1]:
			# get one random opening tweet and tweet it
			twitter.update_status(random.choice(config["twitter"]["tweets"]["opened"]))
		# '' - door closed
		else:
			twitter.update_status(random.choice(config["twitter"]["tweets"]["closed"]))
Beispiel #3
0
def getTypeVals(type, limit):
	out = "["
	
	# get all the data
	cur.execute("SELECT * FROM {0} ORDER BY time DESC LIMIT {1};".format(
		type,
		limit
	))
	
	# reverse it and put it into one string
	for d in reversed(cur.fetchall()):
		out += "[{0}, {1}],".format(
			d[2]*1000,
			d[1]
		)
	
	# delete the last comma, add a closing ] and return all the things
	return out[0:-1] + "]"
Beispiel #4
0
def insert(type):
	# key check
	if bottle.request.query.key in config["keys"]:
		# type check
		if type in config["types"]:
			# value check
			if bottle.request.query.value:
				cur.execute("INSERT INTO {0} (value, time) VALUES (?, ?);".format(type), (
					bottle.request.query.value,
					int(time.time())
				))
				db.commit()
				
				# door tweet thingy
				if type == "door":
					helpers.doorTweet()
				
				return "1"
			
			bottle.abort(400, "you think nobody needs the value? then i can't agree with you.")
		bottle.abort(400, "what about correct types?")
	bottle.abort(403, "muhahaha penis")