Commit 2fd4e564 authored by Robert Figueroa's avatar Robert Figueroa
Browse files

S'han creat funcions que servian psteriorment per encendre el led i s'ha...

 S'han creat funcions que servian psteriorment per encendre el led i s'ha capturat el CTRL-c per sortir del programa
parent 14b4cd3e
DILLUNS 9:00 9:30
DIMECRES 12:00 12:30
Dijous 13:00 13:45
Dimecres 10:50 11:04
#Moduls a importar
import datetime
import signal
import sys
#Funcions
def recompilar_info():
......@@ -17,6 +19,16 @@ def recompilar_info():
info=[]
return info
def reg_on():
print 'REG ON'
def reg_off():
print 'REG OFF'
def signal_handler(signal, frame):
print('Adeu!')
sys.exit(0)
#Proves
if __name__ == "__main__":
i = recompilar_info()
......
#Moduls a iportar
from funcions import *
import time
#Variables
dies_setmana = ['DILLUNS', 'DIMARTS', 'DIMECRES', 'DIJOUS', 'DIVENDRES', 'DISSABTE', 'DIUMENGE']
if __name__ == "__main__":
info = recompilar_info()
for dia_reg in info:
i = datetime.datetime.today().weekday()
if dia_reg[0] == dies_setmana[i]:
print 'Avui toca regar'
hora_inici = dia_reg[1].split(':')
hora_fi = dia_reg[2].split(':')
now = datetime.datetime.now()
start = now.replace(hour = int(hora_inici[0]), minute = int(hora_inici[1]), second=0, microsecond=0)
end = now.replace(hour = int(hora_fi[0]), minute = int(hora_fi[1]), second=0, microsecond=0)
if now >= start and now < end:
print 'ESTARIA REGANT'
else:
print 'no estaria regant encara'
signal.signal(signal.SIGINT, signal_handler)
while(True):
info = recompilar_info()
if len(info) == 0:
reg_off()
else:
print 'Avui no es el dia de regar'
for dia_reg in info:
i = datetime.datetime.today().weekday()
if dia_reg[0] == dies_setmana[i]:
hora_inici = dia_reg[1].split(':')
hora_fi = dia_reg[2].split(':')
now = datetime.datetime.now()
start = now.replace(hour = int(hora_inici[0]), minute = int(hora_inici[1]), second=0, microsecond=0)
end = now.replace(hour = int(hora_fi[0]), minute = int(hora_fi[1]), second=0, microsecond=0)
if now >= start and now < end:
reg_on()
else:
reg_off()
else:
reg_off()
time.sleep(60)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment