コード例 #1
0
ファイル: dblogger.py プロジェクト: buwx/logger
 def store_message(self, message, commit):
     with self.lock:
         ts = int(time.time()*1000)
         self.cur.execute("INSERT INTO sensor(dateTime,sensor,data,description) VALUES(%s,%s,%s,%s)", (ts,sensor(message),message,description(message)))
         if commit:
             self.con.commit()
コード例 #2
0
ファイル: update.py プロジェクト: buwx/logger
import MySQLdb as mdb

from util import formatData, description, sensor

# the main procedure

con = None

try:

    con = mdb.connect("localhost", "davis", "davis", "davis")
    cur = con.cursor()

    cur.execute("SELECT id, data FROM logger WHERE id>=18020 AND id<=64164")
    for row in cur:
        identifier = row[0]
        data = row[1]
        print "UPDATE logger set sensor='" + sensor(data) + "', data='" + formatData(
            data
        ) + "', description='" + description(data) + "' WHERE id=" + str(identifier) + ";"
    # cur.execute("INSERT INTO logger(sensor,data,description) VALUES(%s,%s,%s)", (sensor(line),formatData(line),description(line)))
    # con.commit()

except Exception:
    print "Error!"

finally:
    if con:
        con.close()