Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import pymysql.cursors
- from time import gmtime, strftime
- print ("Jungiamasi...")
- connection = pymysql.connect(host='MeteoPyPi.mysql.pythonanywhere-services.com',
- user='MeteoPyPi',
- password='passwordas',
- db='default',
- cursorclass=pymysql.cursors.DictCursor)
- print("Prisijungta.")
- temperatura = "28.7"
- dregme = "31"
- laikas = strftime("%Y-%m-%d", gmtime())
- try:
- with connection.cursor() as cursor:
- sql = "INSERT INTO `orai` VALUES (%s, %s, %s)"
- cursor.execute(sql, (temperatura, dregme, laikas))
- connection.commit()
- with connection.cursor() as cursor:
- sql = "SELECT `temperatura`, `dregme` FROM `orai` WHERE `id`=1"
- cursor.execute(sql)
- result = cursor.fetchone()
- prin(result)
- finally:
- connection.close()
- print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement