Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {'SID':1,'Date':2018/11/18,'Time':12:17:36}
- {'SID':2,'Date':2018/11/18,'Time':12:28:02}
- ...
- ...
- import pyodbc
- import serial
- import time
- import datetime
- import ast
- cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
- "Server=DESKTOP-H7KQUT1;"
- "Database=SAOS1;"
- "Trusted_Connection=yes;")
- cursor = cnxn.cursor()
- arduino = serial.Serial('COM4', 9600, timeout=.1)
- while True:
- data = arduino.readline()[:-2].decode("utf-8")
- if data!="":
- Atd_Date = ast.literal_eval(data)['Date']
- Atd_InTime = ast.literal_eval(data)['Time']
- SID = ast.literal_eval(data)['SID']
- tsql = "INSERT INTO attendance (Atd_Date, Atd_InTime, SID) VALUES (?,?,?);"
- with cursor.execute(tsql,Atd_Date,Atd_InTime,SID):
- print ('Successfuly Inserted!')
Add Comment
Please, Sign In to add comment