diff options
author | makefu <github@syntax-fehler.de> | 2017-07-19 22:22:36 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2017-07-19 22:22:36 +0200 |
commit | 2eb4b8aaee4278ab03d8aad510cce364d8cacb64 (patch) | |
tree | 54ece7a0b46b7965495e1fbb27e87fc4073c0398 | |
parent | 07a6791de368e16cc0864d2676fd255eba522cee (diff) |
muell: init
-rwxr-xr-x | muell.py | 62 | ||||
-rw-r--r-- | muelldata.json | 50 |
2 files changed, 112 insertions, 0 deletions
diff --git a/muell.py b/muell.py new file mode 100755 index 0000000..3b84f02 --- /dev/null +++ b/muell.py @@ -0,0 +1,62 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i python3 -p python3 python35Packages.docopt python35Packages.requests2 +""" usage: ampel [options] TIMEFILE + + --esp=HOST esp8266 ip [Default: 192.168.1.23] + --sleepval=SEC seconds to sleep [Default: 900] + +TIMEFILE refers to a json file which contains all the dates where the bus +drives + +""" +from docopt import docopt +from fade import calc_chain +import time +from time import sleep +import json +import sys +from datetime import datetime, timedelta +import requests + +# time before the day +timebefore = timedelta(hours=24) + +colors = { + "gelber_sack": [ 255,255,0 ], + "orchis": [ 45, 255, 0 ], + "papiermuell": [ 0,0,255 ], + "restmuell": [ 0, 255, 15 ], + "kehrwoche": [ 226, 96, 255 ], + "fallback": [ 66, 220, 244] +} + +def next_date(now,db): + # now = datetime.now() + for e in db: #times are sorted + name = list(e.keys())[0] + times = e[name] + for time in times: + y,m,d = [ int(i) for i in time.split("-") ] + t = datetime.now().replace(year=y,month=m,day=d, + hour=9,minute=0,second=0,microsecond=0) + if (t - timebefore) < now < t: + return name + return "fallback" + +def to_payload(arr): + return {"r":arr[0],"g":arr[1],"b":arr[2]} + +def main(): + args = docopt(__doc__) + times = json.load(open(args['TIMEFILE'])) + sleepval = float(args["--sleepval"]) + esp = args["--esp"] + while True: + now = datetime.now() + t = next_date(now,times) + print(t) + requests.get("http://{}/color".format(esp),params=to_payload(colors[t])) + sleep(sleepval) + +if __name__ == "__main__": + main() diff --git a/muelldata.json b/muelldata.json new file mode 100644 index 0000000..c87b8a9 --- /dev/null +++ b/muelldata.json @@ -0,0 +1,50 @@ +{ + "gelber_sack": [ + "2017-01-02", + "2017-01-23", + "2017-02-13", + "2017-03-06", + "2017-03-27", + "2017-04-22", + "2017-05-08", + "2017-05-29", + "2017-06-19", + "2017-07-10", + "2017-07-31", + "2017-08-21", + "2017-09-11", + "2017-10-02", + "2017-10-23", + "2017-11-13", + "2017-12-04", + "2017-12-23", + "2018-01-15" + ], + "papiermuell": [ + ], + "restmuell": [ + ], + "kehrwoche": [ + "2017-05-21", + "2017-05-22", + "2017-06-11", + "2017-06-12", + "2017-07-02", + "2017-07-03", + "2017-07-23", + "2017-07-24", + "2017-08-13", + "2017-08-14", + "2017-09-03", + "2017-10-15", + "2017-10-16", + "2017-11-05", + "2017-11-06", + "2017-11-26", + "2017-11-27", + "2017-12-07", + "2017-12-08", + "2017-12-28", + "2017-12-29" + ] +} |