Advertisement
Guest User

Untitled

a guest
May 5th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3. import fdb
  4. import re
  5.  
  6. con = fdb.connect(dsn='10.100.2.185/3050:/home/trainee2/Desktop/ice', user='sysdba', password='trainee')
  7. cur = con.cursor()
  8.  
  9. namen = []
  10. voornamen = []
  11. fotos = []
  12. pinnen = []
  13. status = [0] * 12
  14. indexSpatie = 0
  15. inOrOut =0
  16. xcoors = []
  17. ycoors = []
  18. ids = []
  19. controleIds = []
  20. controlepin = [1] * 12
  21. GPIO.setmode(GPIO.BCM)
  22. statement = ""
  23. dagVanVandaag = time.strftime("%d")
  24.  
  25. def getPinnen():
  26.     cur.execute("SELECT PINNUMBER, NAME, PRENAME, FOTOLINK,XAS, YAS, PERSONID FROM ICEUSERS WHERE PERSONID > 29 ")
  27.     for (PINNUMBER, NAME, PRENAME, FOTOLINK, XAS, YAS, PERSONID) in cur:
  28.         PINNUMBER = str(PINNUMBER).replace("(","").replace(",)", "")
  29.         pinnen.append(int(PINNUMBER))
  30.         NAME = str(NAME).replace("(","").replace(",)", "")
  31.         namen.append(NAME)
  32.         PRENAME = str(PRENAME).replace("(","").replace(",)", "")
  33.         voornamen.append(PRENAME)
  34.         FOTOLINK = str(FOTOLINK).replace("(","").replace(")", "")
  35.         fotos.append(FOTOLINK)
  36.         XAS = str(XAS).replace("(","").replace(")", "")
  37.         xcoors.append(XAS)
  38.         YAS = str(YAS).replace("(","").replace(")", "")
  39.         ycoors.append(YAS)
  40.         PERSONID = str(PERSONID).replace("(","").replace(")", "")
  41.         ids.append(PERSONID)       
  42.  
  43. def controleVars():
  44.     cur.execute("SELECT DISTINCT PERSONID FROM ICEDATABASE WHERE PERSONID > 29 and ISPRESENT = 1 and cast(DATUMIN as date) = (select DISTINCT cast ('Now' as date) from icedatabase);")
  45.     for (PERSONID) in cur:
  46.         PERSONID = str(PERSONID).replace("(","").replace(")", "").replace(",","")
  47.         controleIds.append(PERSONID)   
  48.     while (len(controleIds) < 12):
  49.         controleIds.append(" ")
  50.  
  51.        
  52. getPinnen()
  53. controleVars()
  54. for p in range(0,12):
  55.     GPIO.setup(pinnen[p],GPIO.IN)
  56.    
  57. while True:
  58.     for e in range(0,12):
  59.         status[e] = GPIO.input(pinnen[e])
  60.         if (status[e] != controlepin[e]):
  61.             datum = time.strftime("%Y-%m-%d %H:%M")
  62.             uur = time.strftime("%H")
  63.             voornaam = voornamen[e]
  64.             achternaam = namen[e]
  65.             stat = str(status[e])
  66.             foto = fotos[e]
  67.             ycoor = ycoors[e]
  68.             xcoor = xcoors[e]
  69.             id = ids[e]
  70.             if (status[e] == 0):
  71.                 print id
  72.                 if id in controleIds:
  73.                     print "erin"
  74.                     cur.execute("update icedatabase set DATUMIN = ?, ISPRESENT = 1 where PERSONID = ? and cast(DATUMIN as date) = (select DISTINCT cast ('Now' as date) from icedatabase);",(datum,id))
  75.                 else:
  76.                     cur.execute("insert into ICEDATABASE (PRENAME, NAME, DATUMIN, PICTURELINKS, ISPRESENT, XCOR, YCOR, PERSONID) values(?,?,?,?,1,?,?,?)",(voornaam,achternaam,datum,foto,xcoor,ycoor, id))
  77.                     controleIds[e] == id
  78.             else:
  79.                 cur.execute("update icedatabase set DATUMOUT = ?, ISPRESENT = 0 where PERSONID = ? and cast(DATUMIN as date) = (select DISTINCT cast ('Now' as date) from icedatabase);",(datum,id))
  80.                 controleIds[e] = " "
  81.            
  82.    
  83.             if(dagVanVandaag != time.strftime("%d")):
  84.                     controleIds = []
  85.                     controleVars()
  86.  
  87.             con.commit()
  88.             controlepin[e] = status[e]
  89.            
  90.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement