from button import *
from squid import *
import time
import urllib.request
import os

rgb = Squid(18, 23, 24)
        
b = Button(17)
b2 = Button(13)
b3 = Button(21)

yourKey = "YOUR KEY HERE" // This will need to be a string like "KEY"

while True:
    if b.is_pressed():
        print("Button 1 took: ")
        print(time.time())
        rgb.set_color(RED)
        time.sleep(0.2)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/desklight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/desklight_bright/with/key/' + yourKey).read()
        rgb.set_color(OFF)
        
    elif b2.is_pressed():
        print("Button 2 took: ")
        print(time.time())
        rgb.set_color(GREEN)
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/desklight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/desklight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_bright/with/key/' + yourKey).read()
        rgb.set_color(OFF)
        
    elif b3.is_pressed():
        print("Button 3 took: ")
        print(time.time())
        rgb.set_color(CYAN)
        time.sleep(0.2)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bedlight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/mainlight_bright/with/key/' + yourKey).read()
        time.sleep(1)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bathlight_dim/with/key/' + yourKey).read()
        time.sleep(3)
        urllib.request.urlopen('https://maker.ifttt.com/trigger/bathlight_bright/with/key/' + yourKey).read()
        rgb.set_color(OFF)
        
    else:
        rgb.set_color(OFF)
