Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- from datetime import date, datetime
- import random, time
- import mysql.connector
- cnx = mysql.connector.connect(user='root', host='localhost', password='mynewpassword', database='Kim_IoTDatabase')
- cursor = cnx.cursor()
- add_record = ("INSERT INTO Temperature_Readings "
- "(Device_ID, Temperature_Far, Temperature_Cel, Insert_Date)"
- "VALUES (%s, %s, %s, %s)")
- for i in range(20):
- timestamp = datetime.now().strftime('%y-%m-%d %H:%M:%S')
- for j in range(10):
- f = round(random.uniform(57, 92), 2)
- c = (f - 32) * (5.0/9.0)
- data_record = ("device"+str(j), f, c, timestamp)
- cursor.execute(add_record, data_record)
- cnx.commit()
- print("r: " + str(i) + " d: " + str(j))
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement