Advertisement
Guest User

Untitled

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