Guest User

Untitled

a guest
Nov 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. {'SID':1,'Date':2018/11/18,'Time':12:17:36}
  2. {'SID':2,'Date':2018/11/18,'Time':12:28:02}
  3. ...
  4. ...
  5.  
  6. import pyodbc
  7. import serial
  8. import time
  9. import datetime
  10. import ast
  11. cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
  12. "Server=DESKTOP-H7KQUT1;"
  13. "Database=SAOS1;"
  14. "Trusted_Connection=yes;")
  15. cursor = cnxn.cursor()
  16. arduino = serial.Serial('COM4', 9600, timeout=.1)
  17.  
  18.  
  19. while True:
  20.  
  21. data = arduino.readline()[:-2].decode("utf-8")
  22.  
  23. if data!="":
  24.  
  25. Atd_Date = ast.literal_eval(data)['Date']
  26. Atd_InTime = ast.literal_eval(data)['Time']
  27. SID = ast.literal_eval(data)['SID']
  28. tsql = "INSERT INTO attendance (Atd_Date, Atd_InTime, SID) VALUES (?,?,?);"
  29. with cursor.execute(tsql,Atd_Date,Atd_InTime,SID):
  30. print ('Successfuly Inserted!')
Add Comment
Please, Sign In to add comment