瀏覽代碼

Best practice

master
Pete Shadbolt 3 年之前
父節點
當前提交
236a61e644
共有 1 個文件被更改,包括 48 次插入5 次删除
  1. +48
    -5
      xmas.py

+ 48
- 5
xmas.py 查看文件

@@ -3,6 +3,36 @@ 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()
@@ -22,23 +52,36 @@ def turn_off():

def check_connectivity():
""" Flick the switch """
for i in range(10):
print("Checking connectivity:")
for i in range(2):
turn_on()
time.sleep(.3)
time.sleep(2)
turn_off()
time.sleep(.3)
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("17:00").do(turn_on)
schedule.every().day.at("23:59").do(turn_off)
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):


Loading…
取消
儲存