Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. from __future__ import print_function
  2. from datetime import date, datetime
  3. import random, time
  4. import mysql.connector
  5.  
  6. cnx = mysql.connector.connect(user='root', host='localhost', password='mynewpassword', database='Kim_IoTDatabase')
  7. cursor = cnx.cursor()
  8. add_record = ("INSERT INTO Temperature_Readings "
  9. "(Device_ID, Temperature_Far, Temperature_Cel, Insert_Date)"
  10. "VALUES (%s, %s, %s, %s)")
  11.  
  12. for i in range(20):
  13. timestamp = datetime.now().strftime('%y-%m-%d %H:%M:%S')
  14. for j in range(10):
  15. f = round(random.uniform(57, 92), 2)
  16. c = (f - 32) * (5.0/9.0)
  17. data_record = ("device"+str(j), f, c, timestamp)
  18. cursor.execute(add_record, data_record)
  19. cnx.commit()
  20. print("r: " + str(i) + " d: " + str(j))
  21. time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement