i have the following problem:
i want to insert the temperature of my RPI using SQLite3 and Python. The python script that i want to use:
import subprocess
import os
import sqlite3 as lite
import datetime
import sys
import time
def get_temperature():
"Returns the temperature in degrees C"
try:
s = subprocess.check_output(["cat","/sys/class/thermal/thermal_zone0/temp"])
return s[:-1]
except:
return 0
try:
con = lite.connect('/www/auslastung.s3db')
cur = con.cursor()
temp = int(get_temperature())
zeit = time.strftime('%Y-%m-%d %H:%M:%S')
cur.execute("INSERT INTO 'temperatur' ('Wert', 'Zeit') VALUES (%s, %s)", (temp, zeit))
con.commit()
except lite.Error, e:
if con:
con.rollback()
print "Error %s" % e.args[0]
sys.exit(1)
finally:
if con:
con.close()
Every time i want to run this, i just get the error:
Error near "%": syntax error
What should i do to solve this?