|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import schedule
- import time
- import datetime
- import pifacedigitalio as p
-
- TREE = """
- * ,
- _/^\_
- < >
- * /.-.\ *
- * `/&\` *
- ,@.*;@,
- /_o.I %_\ *
- * (`'--:o(_@;
- /`;--.,__ `') *
- ;@`o % O,*`'`&\ *
- * (`'--)_@ ;o %'()\ *
- /`;--._`''--._O'@;
- /&*,()~o`;-.,_ `""`)
- * /`,@ ;+& () o*`;-';\ *
- (`""--.,_0 +% @' &()\ *
- /-.,_ ``''--....-'`) *
- * /@%;o`:;'--,.__ __.'\
- ;*,&(); @ % &^;~`"`o;@(); *
- /(); o^~; & ().o@*&`;&%O\
- jgs `"="==""==,,,.,="=="==="`
- __.----.(\-''#####---...___...-----._
- '` \)_`'''''`
- .--' ')
- o( )_-
- `'''` `
- """
-
- START = datetime.time(17, 0, 0)
- END = datetime.time(23, 59, 0)
-
- def timestamp():
- return datetime.datetime.now()
-
-
- def turn_on():
- """ Turn on the christmas tree """
- print("{} ON".format(timestamp()))
- p.digital_write(0, 1)
-
-
- def turn_off():
- """ Turn off the christmas tree """
- print("{} OFF".format(timestamp()))
- p.digital_write(0, 0)
-
-
- def check_connectivity():
- """ Flick the switch """
- print("Checking connectivity:")
- for i in range(2):
- turn_on()
- time.sleep(2)
- turn_off()
- time.sleep(2)
-
-
- # Turn on if we are in the correct interval
- now = datetime.datetime.now().time()
- if START <= now <= END:
- turn_on()
-
-
- if __name__ == "__main__":
- # Connect to PiFace
- print(TREE)
- p.init()
-
- # Check connectivity
- check_connectivity()
-
- # Message
- print()
- print("Starting scheduler:")
- print("Xmas enabled between {} and {}.".format(START.strftime("%H:%M"), END.strftime("%H:%M")))
-
- # Set up the schedule
- schedule.every().day.at(START.strftime("%H:%M")).do(turn_on)
- schedule.every().day.at(END.strftime("%H:%M")).do(turn_off)
-
- # Run the event loop
- while(True):
- schedule.run_pending()
- time.sleep(1)
|