Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created July 11, 2020 20:11
Show Gist options
  • Save chand1012/556678153586ad1d6e431f99247ba475 to your computer and use it in GitHub Desktop.
Save chand1012/556678153586ad1d6e431f99247ba475 to your computer and use it in GitHub Desktop.
Scheduling System from Ian's Blinds project.
from json import loads
from datetime import datetime
from time import sleep
def operate_blinds(opened=False):
# operate the blinds
# write your blind operation code here
print(f"Blinds state: {opened}")
if __name__=="__main__":
while True:
# gets the data from the json file.
# This can be moved above the loop
# to make it access from memory instead
# of from the file every 10 seconds
data = {}
with open("schedule.json") as f:
data = loads(f.read())
weekday = datetime.now.weekday()
# this gets the data for the specified weekday integer
# from the data.
schedule = data[str(weekday)]
# the 'open' and 'close' fields in the JSON
# are both lists so you can specify multiple times to open and close
# them.
for item in schedule.get('open'):
if datetime.now.hour is item.get('hour') and datetime.now.minute is item.get('minute'):
operate_blinds(opened=True)
for item in schedule.get('close'):
if datetime.now.hour is item.get('hour') and datetime.now.minute is item.get('minute'):
operate_blinds(opened=False)
# you don't need this running that fast
# waits 10 seconds
sleep(10)
{
"0":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"1":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"2":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"3":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"4":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"5":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
},
"6":{
"open":[
{"hour":"", "minute":""}
],
"close": [
{"hour":"", "minute":""}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment