-
Notifications
You must be signed in to change notification settings - Fork 1
/
ranges.py
43 lines (32 loc) · 834 Bytes
/
ranges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Micropython Http Server
# Erni Tron ernitron@gmail.com
# Copyright (c) 2016
import time
import json
class Ranges():
def __init__(self):
self.ranges = []
def set(self, config_ranges):
self.ranges = []
for r in config_ranges.split(','):
startend = r.split('-')
try:
start = int(startend[0])
end = int(startend[1])
except:
print('skip range ', startend)
continue
if start > end: continue
self.ranges.append([start, end])
def inrange(self):
#Get time now
(y, m, d, h, mm, s, c, u, _) = time.localtime()
for s, e in self.ranges:
if e < s: continue
if h in range(s,e):
print('ON')
return True
print('OFF')
return False
# Range initialized to None
ranges = None