| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 
 | import RPi.GPIO as GPIO
from twilio.rest import TwilioRestClient
import time
import datetime
import threading
import MySQLdb
 
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.setup(38, GPIO.OUT)
 
db = MySQLdb.connect(host="localhost",    # your host, usually localhost
                    user="root",         # your username
                   passwd="Orel_27130",  # your password
                    db="projet")        # name of the data base
 
 
 
 
day = datetime.datetime.now()
day = day.isoweekday()
 
 
if day == 3 :
    while day == 3:
        # calcul du time delta + affichage de l'heure actuelle au format H24
        midnight = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
        now_relative = datetime.datetime.now() - midnight
        print time.strftime("%H:%M:%S")
 
        # Requete SQL
        cursor1 = db.cursor()
        cursor1.execute("SELECT time_open FROM time WHERE id = 3")
        time_open = cursor1.fetchone()
        cursor2 = db.cursor()
        cursor2.execute("SELECT time_close FROM time WHERE id = 3")
        time_close = cursor2.fetchone()
 
 
        # Si Time open est superieur ou egale a l'heure actuelle et si time close est inferieur a l'heure actuelle
        if(time_open[0] >= now_relative and time_close[0] < now_relative):
            print ("Fermee")
            GPIO.output(38, False)
            GPIO.output(40, True)   
        else:
            print ("Ouvert")
            GPIO.output(38, True)
            GPIO.output(40, False) | 
Partager