Copier de code
#!/usr/bin/python3 import time import datetime import mysql.connector as c import cv2 from pyzbar.pyzbar import decode import RPi.GPIO as GPIO from gtts import gTTS from mpyg321.mpyg321 import MPyg321Player import PySimpleGUI as sg sg.LOOK_AND_FEEL_TABLE['MyCreatedTheme'] = {'BACKGROUND': '#34495E', 'TEXT': '#FFCC66', 'INPUT': '#339966', 'TEXT_INPUT': '#000000', 'SCROLL': '#99CC99', 'BUTTON': ('#003333', '#FFCC66'), 'PROGRESS': ('#D1826B', '#CC8019'), 'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0, } sg.theme('MyCreatedTheme') layout1 = [[sg.Text('Welcome to Library book manager',justification='center',size=(80,4),font=("Helvetica", 20))], [sg.Text(size=(100,3),justification='center',key='-OUTPUT-',font=("Helvetica", 15))], [sg.Text(justification='center',size=(100,4),key='-LEFT-',font=("Helvetica", 13))]] window = sg.Window(title="Library book manager",layout=layout1,size=(600,700),resizable=True,use_custom_titlebar=True, alpha_channel=.5,right_click_menu = None, grab_anywhere=False,no_titlebar=True).finalize() window.Maximize() sensor1 = 20 sensor2 = 21 language="en" #welcometext="Welcome to Automatic Library book management system!" #myobj = gTTS(text=welcometext, lang=language, slow=False) #myobj.save("welcome.mp3") ##placebooktext="Please Place Book which you want to issue or re issue!" #myobj1 = gTTS(text=placebooktext, lang=language, slow=False) #myobj1.save("placebook.mp3") #placereturnbooktext="Please Place Book which you want to Return!" #myobj1 = gTTS(text=placereturnbooktext, lang=language, slow=False) #myobj1.save("placereturnbook.mp3") #placecardtext="Please Place Your LIBRARY ID CARD!" #myobj2 = gTTS(text=placecardtext, lang=language, slow=False) #myobj2.save("placecard.mp3") #bookissuetext="Book has been issued to you!" #myobj3 = gTTS(text=bookissuetext, lang=language, slow=False) #myobj3.save("bookissue.mp3") #bookreissuetext="Book has been re issued to you!" #myobj4 = gTTS(text=bookreissuetext, lang=language, slow=False) #myobj4.save("bookreissue.mp3") #bookreturntext="Book has been succesfully Returned!" #myobj5 = gTTS(text=bookreturntext, lang=language, slow=False) #myobj5.save("bookreturn.mp3") #morebooktext="YOU CANNOT ISSUE BOOKS MORE THAN 5" #myobj6 = gTTS(text=morebooktext, lang=language, slow=False) #myobj6.save("morebook.mp3") #nobooktext="Book Not Registered in Database" #myobj7 = gTTS(text=nobooktext, lang=language, slow=False) #myobj7.save("nobook.mp3") #nousertext="Book Not Registered in Database" #myobj8 = gTTS(text=nousertext, lang=language, slow=False) #myobj8.save("nouser.mp3") #errortext="You can only Return book after 7 Days" #myobj9 = gTTS(text=errortext, lang=language, slow=False) #myobj9.save("error.mp3") #error2text="Book is not isued to you or something went wrong" #myobj10 = gTTS(text=error2text, lang=language, slow=False) #myobj10.save("error2.mp3") player = MPyg321Player() player.play_song("welcome.mp3") GPIO.setmode(GPIO.BCM) GPIO.setup(sensor1,GPIO.IN) GPIO.setup(sensor2,GPIO.IN) cap = cv2.VideoCapture(0) cap.set(3, 320) cap.set(4, 240) flag1 = True flag2 = False flag3 = True flag4 = False con = c.connect(host="hostname", user="username", passwd="password", database="database name", port=3306 ) def mohit(frame): global flag1 global flag2 global bookname global bookuid global bookissuedto global cursor con.commit() if flag1 == True: for code in decode(frame): print(code.type) print(code.data.decode('utf-8')) id = code.data.decode('utf-8') cursor.execute("Select uid, bookname , available , issuedto FROM bookdatabase WHERE uid="+str(id)) result = cursor.fetchone() #print(result[2]) if result is not(None): if result[2] == 1: bookname = result[1] bookuid = result[0] bookissuedto = result[3] #cv2.destroyAllWindows() flag2= True function2(result[2]) flag1= False elif result is None: flag1=False print("Book not Registered!!") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Is Not Registered !!") window.finalize() player.play_song("nobook.mp3") def function2(res): if res == 1: print("Place Your LIBRARY ID CARD!!") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Place Your LIBRARY ID CARD !!") window.finalize() player.play_song("placecard.mp3") count = 0 maurya(count) def maurya(count): global flag1 global flag2 time.sleep(10) count_f_stop = 0 while count <= 100: if count_f_stop == 0: while count_f_stop <= 10: success, frame1 = cap.read() count_f_stop = count_f_stop + 1 count = count + 1 success, frame1 = cap.read() read(frame1) #cv2.imshow('test', frame) #cv2.waitKey(1) flag1 = True main() def read(frame1): global flag1 global flag2 global bookname global bookuid global intissuefine global cursor con.commit() if flag2 == True: for code1 in decode(frame1): print(code1.type) print(code1.data.decode('utf-8')) uid = code1.data.decode('utf-8') if uid == bookissuedto or bookissuedto == str(0): cursor.execute("Select lid, name , issued,fine FROM usersdatabase WHERE lid="+str(uid)) result1 = cursor.fetchone() if result1 is not(None): flag2 = False usedlid = result1[0] username = result1[1] userissued = result1[2] issuefine1 = result1[3] intissuefine = int(issuefine1) if userissued == 0: tday = datetime.date.today() tdelta = datetime.timedelta(days=14) returndate = tday + tdelta newuserissued = userissued + 1 query = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s,issued=%s WHERE lid = %s """ data = (bookname,bookuid,tday,returndate,newuserissued,uid) cursor.execute(query, data) con.commit() bquery = """ UPDATE bookdatabase SET issuedto=%s WHERE uid = %s """ bdata = (uid,bookuid) cursor.execute(bquery,bdata) con.commit() print("Book Has been issued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been issued to "+str(username)+"\nReturn Date : "+str(returndate)) window.finalize() player.play_song("bookissue.mp3") if userissued == 1: tday = datetime.date.today() tdelta = datetime.timedelta(days=14) returndate = tday + tdelta cursor.execute("Select lid, name ,b1returndate,b1issuedate,issued FROM usersdatabase WHERE b1uid="+str(bookuid)) result2 = cursor.fetchone() if result2 is not(None): m1 = result2[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days #print(remainderday) if remainderday < 7 and remainderday >= 0: reissuequery1 = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s WHERE b1uid = %s """ newreturndate = returndate + remainderdate data1 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery1,data1) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery2 = """ UPDATE usersdatabase SET b1name = %s,b1uid = %s,b1issuedate=%s,b1returndate=%s,fine=%s WHERE b1uid = %s """ newreturndate = returndate + remainderdate data2 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery2,data2) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b2returndate,b2issuedate,issued FROM usersdatabase WHERE b2uid="+str(bookuid)) result17 = cursor.fetchone() if (result17 is not(None)) and (result2 is None): m1 = result17[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery3 = """ UPDATE usersdatabase SET b2name = %s,b2uid = %s,b2issuedate=%s,b2returndate=%s WHERE b2uid = %s """ newreturndate = returndate + remainderdate data3 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery3,data3) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery4 = """ UPDATE usersdatabase SET b2name = %s,b2uid = %s,b2issuedate=%s,b2returndate=%s,fine=%s WHERE b2uid = %s """ newreturndate = returndate + remainderdate data4 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery4,data4) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b3returndate,b3issuedate,issued FROM usersdatabase WHERE b3uid="+str(bookuid)) result18 = cursor.fetchone() if (result18 is not(None)) and (result17 is None) and (result2 is None): m1 = result18[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery5 = """ UPDATE usersdatabase SET b3name = %s,b3uid = %s,b3issuedate=%s,b3returndate=%s WHERE b3uid = %s """ newreturndate = returndate + remainderdate data5 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery5,data5) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery6 = """ UPDATE usersdatabase SET b3name = %s,b3uid = %s,b3issuedate=%s,b3returndate=%s,fine=%s WHERE b3uid = %s """ newreturndate = returndate + remainderdate data6 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery6,data6) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date : "+str(newreturndate)+"\nTotal Fine: "+str(fine)) window.finalize() player.play_song("bookreissue.mp3") cursor.execute("Select lid, name ,b4returndate,b4issuedate,issued FROM usersdatabase WHERE b4uid="+str(bookuid)) result19 = cursor.fetchone() if (result19 is not(None)) and (result2 is None) and (result17 is None) and (result18 is None): m1 = result19[2] ynew1 = m1[0:4] yint1 = int(ynew1) mnew1 = m1[5:7] mint1 = int(mnew1) dnew1 = m1[8:10] dint1 = int(dnew1) previousreturndate1 = datetime.date(yint1,mint1,dint1) tday = datetime.date.today() remainderdate=previousreturndate1 - tday remainderday = remainderdate.days if remainderday < 7 and remainderday >= 0: reissuequery7 = """ UPDATE usersdatabase SET b4name = %s,b4uid = %s,b4issuedate=%s,b4returndate=%s WHERE b4uid = %s """ newreturndate = returndate + remainderdate data7 = (bookname,bookuid,tday,newreturndate,bookuid) cursor.execute(reissuequery7,data7) con.commit() print("Book Has been reissued to you") window['-LEFT-'].update(value="") window.finalize() window['-OUTPUT-'].update(value="Book Has been reissued to "+str(username)+"\nReturn Date :"+str(newreturndate)) window.finalize() player.play_song("bookreissue.mp3") elif remainderday < 0 : absremainderday = abs(remainderday) fine = intissuefine + 2 * absremainderday reissuequery8 = """ UPDATE usersdatabase SET b4name = %s,b4uid = %s,b4issuedate=%s,b4returndate=%s,fine=%s WHERE b4uid = %s """ newreturndate = returndate + remainderdate data8 = (bookname,bookuid,tday,returndate,fine,bookuid) cursor.execute(reissuequery8,data8)
Retrouvez l’histoire de Raspberry Pi dans cette vidéo :

