Advertisement
Guest User

Raspberry Kodas

a guest
May 19th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import pymysql.cursors
  2. from time import gmtime, strftime
  3. print ("Jungiamasi...")
  4. connection = pymysql.connect(host='localhost',
  5.                              user='root',
  6.                              password='',
  7.                              db='test',
  8.                              cursorclass=pymysql.cursors.DictCursor)
  9. print("Prisijungta.")
  10. temperatura = "21.5"
  11. dregme = "28"
  12. laikas = strftime("%Y-%m-%d", gmtime())
  13.  
  14. try:
  15.     with connection.cursor() as cursor:
  16.         sql = "INSERT INTO `orai`(temperatura, dregme, datetime) VALUES (%s, %s, %s)"
  17.         cursor.execute(sql, (temperatura, dregme, laikas))
  18.     connection.commit()
  19.  
  20.     with connection.cursor() as cursor:
  21.         sql = "SELECT `temperatura`, `dregme` FROM `orai` WHERE `id`=1"
  22.         cursor.execute(sql)
  23.         result = cursor.fetchone()
  24.         print(result)
  25. finally:
  26.     connection.close()
  27.     print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement