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 /muell.py | |
parent | 07a6791de368e16cc0864d2676fd255eba522cee (diff) |
muell: init
Diffstat (limited to 'muell.py')
-rwxr-xr-x | muell.py | 62 |
1 files changed, 62 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() |