commit 552ae66601024f962d53fac1cc2fbcaee8fce322 Author: Jaro Date: Fri Oct 30 19:21:36 2020 +0100 Init commit for python scripts diff --git a/bell-push-talk.py b/bell-push-talk.py new file mode 100755 index 0000000..b26541f --- /dev/null +++ b/bell-push-talk.py @@ -0,0 +1,65 @@ +#!/usr/bin/python3.8 + +import paho.mqtt.client as mqtt #import the client1 +from mqtt_print import get_message as M +from datetime import datetime +import time +import signal +import json +import requests +import logging +from daemonize import Daemonize + + +broker_address="172.16.1.254" +topic="heme/bell/ring" +scroller_topic="home/scroller" +user="bot" +password="push1234" +url="https://nuc.bh.ttx.sk/ocs/v2.php/apps/spreed/api/v1/chat/dahgo5em" + +pid = "/tmp/bell.pid" +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) +logger.propagate = False +fh = logging.FileHandler("/tmp/bell.log", "w") +fh.setLevel(logging.DEBUG) +logger.addHandler(fh) +keep_fds = [fh.stream.fileno()] + +def signal_handler(signal_number, frame): + logger.debug("Proceed ...") + +def on_message(client, userdata, message): + logger.debug("message received %s" ,str(message.payload.decode("utf-8"))) + logger.debug("message topic=%s",message.topic) + logger.debug("message qos=%s",message.qos) + logger.debug("message retain flag=%s",message.retain) + + d = {} + strdate = datetime.now().ctime() + d["message"] = "Bell ringing in time: " + strdate + headers = {'OCS-APIRequest': 'true'} + + r = requests.post(url, headers=headers,json=d,auth=(user,password)) + client.publish(scroller_topic,M("ZVONI",color=0)); + +def main_program(): + logger.debug("Start") + logger.debug("creating new instance") + client = mqtt.Client("NUC-client-talk") #create new instance + logger.debug("connecting to broker") + client.connect(broker_address) #connect to broker + logger.debug("Subscribing to topic",topic) + client.subscribe(topic) + client.on_message=on_message + + client.loop_start() + signal.signal(signal.SIGINT, signal_handler) + signal.pause() + client.loop_stop() + +daemon = Daemonize(app="bell_talk_app", pid=pid, action=main_program, keep_fds=keep_fds) +daemon.start() +#broker_address="iot.eclipse.org" + diff --git a/covid.py b/covid.py new file mode 100755 index 0000000..7573a96 --- /dev/null +++ b/covid.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +from urllib import request +import json +import pprint +url = "https://covid-19.nczisk.sk/webapi/v1/kpi" + +param = { "k5" : "vysetreni", "k7":"vylieceny","k8":"umrti", "k9":"hospitalizovany", "k23" : "testovany" } +md = {} +def get_covid_stats(): + j = request.urlopen(url).read() + d = json.loads(j) + # pprint.pprint(d) + for p in param.keys(): + md[param[p]] = {} + n = len(d["tiles"][p]["data"]["d"]) + md[param[p]]["last"] = d["tiles"][p]["data"]["d"][n-1]["v"] + md[param[p]]["delta"] = d["tiles"][p]["data"]["d"][n-1]["v"] - d["tiles"][p]["data"]["d"][n-2]["v"] + return md + +if __name__ == "__main__": + print(get_covid_stats()) + + diff --git a/mqtt-print-time.py b/mqtt-print-time.py new file mode 100755 index 0000000..b6b711d --- /dev/null +++ b/mqtt-print-time.py @@ -0,0 +1,81 @@ +#!/usr/bin/python3.8 + +import paho.mqtt.client as mqtt #import the client1 +from mqtt_print import get_message as M +from slovak_calendar import slovak_name_calendar as names +from datetime import datetime +import time +from pyowm import OWM +from covid import get_covid_stats + +def on_message(client, userdata, message): + print("message received " ,str(message.payload.decode("utf-8"))) + print("message topic=",message.topic) + print("message qos=",message.qos) + print("message retain flag=",message.retain) + + client.publish("home/scroller",M("ZVONI",color=0)); + + +def print_time(format='%H:%M',color=1): + t = time.strftime(format) + print("format time = ",format," ",M(t,color=color)) + client.publish("home/scroller",M(t,color=color)); + +def print_weather(color=1): + owm = OWM('d15c61931a053026e98769dd9fc46ba3') + mgr = owm.weather_manager() + observation = mgr.weather_at_place('Trnava,SK') + weather = observation.weather + s = weather.status + " " + str(weather.temperature('celsius')['temp']) + "C " + str(weather.humidity) + "%" + print("Weather:",s) + print("Humidity:",weather.humidity) + client.publish("home/scroller",M(s,color=color,speed=100)); + +def print_name(color=0): + dt = datetime.today() + for name in names: + (m,d,n) = name + if m == dt.month and d == dt.day: + print("Name:",M(n,color=color,speed=100)) + client.publish("home/scroller",M(n,color=color,speed=100)); + +def print_covid(color=0): + d = get_covid_stats() + msg = "Umrt {:d} {:d}".format(d["umrti"]["last"],d["umrti"]["delta"]) + print(msg) + client.publish("home/scroller",M(msg,color=color,speed=100)) + time.sleep(10) + msg = "Test {:d} {:d}".format(d["testovany"]["last"],d["testovany"]["delta"]) + print(msg) + client.publish("home/scroller",M(msg,color=color,speed=100)) + msg = "Pozi {:d} {:d}".format(d["vysetreni"]["last"],d["vysetreni"]["delta"]) + print(msg) + client.publish("home/scroller",M(msg,color=color,speed=100)) + time.sleep(10) + + +broker_address="172.16.1.254" +#broker_address="iot.eclipse.org" +print("creating new instance") +client = mqtt.Client("NUC-client-home") #create new instance +print("connecting to broker") +client.connect(broker_address) #connect to broker +print("Subscribing to topic","home/bell/ring") +client.subscribe("home/bell/ring") + +client.on_message=on_message +client.loop_start() + +print_time() +time.sleep(5) +print_time("%d.%m",color=2) +time.sleep(5) +print_weather(color=1) +time.sleep(12) +print_name() +time.sleep(7) +print_covid() +time.sleep(10) + +client.loop_stop() diff --git a/mqtt-print-weather.py b/mqtt-print-weather.py new file mode 100755 index 0000000..117b3b2 --- /dev/null +++ b/mqtt-print-weather.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +import paho.mqtt.client as mqtt #import the client1 +import time + +def on_message(client, userdata, message): + print("message received " ,str(message.payload.decode("utf-8"))) + print("message topic=",message.topic) + print("message qos=",message.qos) + print("message retain flag=",message.retain) + + client.publish("home/scroller","ZVONI"); + + +def print_time(format='%H:%M'): + t = time.strftime(format) + print("format time = ",format," ",t) + client.publish("home/scroller",t); + +broker_address="172.16.1.254" +#broker_address="iot.eclipse.org" +print("creating new instance") +client = mqtt.Client("NUC-client-home") #create new instance +print("connecting to broker") +client.connect(broker_address) #connect to broker +print("Subscribing to topic","home/bell/ring") +client.subscribe("home/bell/ring") + +client.on_message=on_message +client.loop_start() + +print_time() + +client.loop_stop() + + + + diff --git a/mqtt_print.py b/mqtt_print.py new file mode 100644 index 0000000..f4e8188 --- /dev/null +++ b/mqtt_print.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +opt = { "color" : ("c",1), "time_on" : ("on",1000), "time_off": ("off",1000), "brightness": ("b",10), "speed" : ("s",100) } + +def get_message(msg,**kwargs): + print("Sending, message to mqtt") + param = [] + for item in kwargs.keys(): + if item in opt: + param.append(opt[item][0]) + param.append(kwargs[item]) + + parameter = ':'.join(list(map(lambda x: str(x), param))) + + if len(parameter): + return parameter + ';' + msg + else: + return msg + + diff --git a/slovak_calendar.py b/slovak_calendar.py new file mode 100644 index 0000000..a5cc029 --- /dev/null +++ b/slovak_calendar.py @@ -0,0 +1,366 @@ +#!/usr/bin/python3 + +slovak_name_calendar = ( +(1, 2, "Alexandra, Karina" ), +( 1, 3, "Daniela" ), +( 1, 4, "Drahoslav" ), +( 1, 5, "Andrea" ), +( 1, 6, "Antonia" ), +( 1, 7, "Bohuslava" ), +( 1, 8, "Severin" ), +( 1, 9, "Alexej" ), +( 1, 10, "Dasa" ), +( 1, 11, "Malvina" ), +( 1, 12, "Ernest" ), +( 1, 13, "Rastislav" ), +( 1, 14, "Radovan" ), +( 1, 15, "Dobroslav" ), +( 1, 16, "Kristina" ), +( 1, 17, "Natasa" ), +( 1, 18, "Bohdana" ), +( 1, 19, "Drahomira, Mario" ), +( 1, 20, "Dalibor" ), +( 1, 21, "Vincent" ), +( 1, 22, "Zora" ), +( 1, 23, "Milos" ), +( 1, 24, "Timotej" ), +( 1, 25, "Gejza" ), +( 1, 26, "Tamara" ), +( 1, 27, "Bohus" ), +( 1, 28, "Alfonz" ), +( 1, 29, "Gaspar" ), +( 1, 30, "Ema" ), +( 1, 31, "Emil" ), +( 2, 1, "Tatiana" ), +( 2, 2, "Erika, Erik" ), +( 2, 3, "Blazej" ), +( 2, 4, "Veronika" ), +( 2, 5, "Agata" ), +( 2, 6, "Dorota" ), +( 2, 7, "Vanda" ), +( 2, 8, "Zoja" ), +( 2, 9, "Zdenko" ), +( 2, 10, "Gabriela" ), +( 2, 11, "Dezider" ), +( 2, 12, "Perla" ), +( 2, 13, "Arpad" ), +( 2, 14, "Valentin" ), +( 2, 15, "Pravoslav" ), +( 2, 16, "Ida, Liana" ), +( 2, 17, "Miloslava" ), +( 2, 18, "Jaromir" ), +( 2, 19, "Vlasta" ), +( 2, 20, "Livia" ), +( 2, 21, "Eleonora" ), +( 2, 22, "Etela" ), +( 2, 23, "Roman, Romana" ), +( 2, 24, "Matej" ), +( 2, 25, "Frederik, Frederika" ), +( 2, 26, "Viktor" ), +( 2, 27, "Alexander" ), +( 2, 28, "Zlatica" ), +( 2, 29, "Radomir" ), +( 3, 1, "Albin" ), +( 3, 2, "Anezka" ), +( 3, 3, "Bohumil, Bohumila" ), +( 3, 4, "Kazimir" ), +( 3, 5, "Fridrich" ), +( 3, 6, "Radoslav, Radoslava" ), +( 3, 7, "Tomas" ), +( 3, 8, "Alan, Alana" ), +( 3, 9, "Frantiska" ), +( 3, 10, "Bruno, Branislav" ), +( 3, 11, "Angela, Angelika" ), +( 3, 12, "Gregor" ), +( 3, 13, "Vlastimil" ), +( 3, 14, "Matilda" ), +( 3, 15, "Svetlana" ), +( 3, 16, "Boleslav" ), +( 3, 17, "Lubica" ), +( 3, 18, "Eduard" ), +( 3, 19, "Jozef" ), +( 3, 20, "Vitazoslav, Klaudius" ), +( 3, 21, "Blahoslav" ), +( 3, 22, "Benadik" ), +( 3, 23, "Adrian" ), +( 3, 24, "Gabriel" ), +( 3, 25, "Marian" ), +( 3, 26, "Emanuel" ), +( 3, 27, "Alena" ), +( 3, 28, "Sona" ), +( 3, 29, "Miroslav" ), +( 3, 30, "Vieroslava" ), +( 3, 31, "Benjamin" ), +( 4, 1, "Hugo" ), +( 4, 2, "Zita" ), +( 4, 3, "Richard" ), +( 4, 4, "Izidor" ), +( 4, 5, "Miroslava" ), +( 4, 6, "Irena" ), +( 4, 7, "Zoltan" ), +( 4, 8, "Albert" ), +( 4, 9, "Milena" ), +( 4, 10, "Igor" ), +( 4, 11, "Julius" ), +( 4, 12, "Estera" ), +( 4, 13, "Ales" ), +( 4, 14, "Justina" ), +( 4, 15, "Fedor" ), +( 4, 16, "Dana, Danica" ), +( 4, 17, "Rudolf, Rudolfa" ), +( 4, 18, "Valer" ), +( 4, 19, "Jela" ), +( 4, 20, "Marcel" ), +( 4, 21, "Ervin" ), +( 4, 22, "Slavomir" ), +( 4, 23, "Vojtech" ), +( 4, 24, "Juraj" ), +( 4, 25, "Marek" ), +( 4, 26, "Jaroslava" ), +( 4, 27, "Jaroslav" ), +( 4, 28, "Jarmila" ), +( 4, 29, "Lea" ), +( 4, 30, "Anastazia" ), +( 5, 2, "Zigmund" ), +( 5, 3, "Galina, Timea" ), +( 5, 4, "Florian" ), +( 5, 5, "Lesia, Lesana" ), +( 5, 6, "Hermina" ), +( 5, 7, "Monika" ), +( 5, 8, "Ingrida" ), +( 5, 9, "Roland" ), +( 5, 10, "Viktoria" ), +( 5, 11, "Blazena" ), +( 5, 12, "Pankrac" ), +( 5, 13, "Servac" ), +( 5, 14, "Bonifac" ), +( 5, 15, "Zofia, Sofia" ), +( 5, 16, "Svetozar" ), +( 5, 17, "Gizela, Aneta" ), +( 5, 18, "Viola" ), +( 5, 19, "Gertruda" ), +( 5, 20, "Bernard" ), +( 5, 21, "Zina" ), +( 5, 22, "Julia, Juliana" ), +( 5, 23, "Zelmira" ), +( 5, 24, "Ela" ), +( 5, 25, "Urban, Vivien" ), +( 5, 26, "Dusan" ), +( 5, 27, "Iveta" ), +( 5, 28, "Viliam" ), +( 5, 29, "Vilma" ), +( 5, 30, "Ferdinand" ), +( 5, 31, "Petrana, Petronela" ), +( 6, 1, "Zaneta" ), +( 6, 2, "Xenia, Oxana" ), +( 6, 3, "Karolina" ), +( 6, 4, "Lenka" ), +( 6, 5, "Laura" ), +( 6, 6, "Norbert" ), +( 6, 7, "Robert, Roberta" ), +( 6, 8, "Medard" ), +( 6, 9, "Stanislava" ), +( 6, 10, "Margareta, Greta" ), +( 6, 11, "Dobroslava" ), +( 6, 12, "Zlatko" ), +( 6, 13, "Anton" ), +( 6, 14, "Vasil" ), +( 6, 15, "Vit" ), +( 6, 16, "Blanka, Bianka" ), +( 6, 17, "Adolf" ), +( 6, 18, "Vratislav" ), +( 6, 19, "Alfred" ), +( 6, 20, "Valeria" ), +( 6, 21, "Alojz" ), +( 6, 22, "Paulina" ), +( 6, 23, "Sidonia" ), +( 6, 24, "Jan" ), +( 6, 25, "Olivia, Tadeas" ), +( 6, 26, "Adriana" ), +( 6, 27, "Ladislav, Ladislava" ), +( 6, 28, "Beata" ), +( 6, 29, "Peter, Pavol, Petra" ), +( 6, 30, "Melania" ), +( 7, 1, "Diana" ), +( 7, 2, "Berta" ), +( 7, 3, "Miloslav" ), +( 7, 4, "Prokop" ), +( 7, 5, "Cyril, Metod" ), +( 7, 6, "Patrik, Patricia" ), +( 7, 7, "Oliver" ), +( 7, 8, "Ivan" ), +( 7, 9, "Lujza" ), +( 7, 10, "Amalia" ), +( 7, 11, "Milota" ), +( 7, 12, "Nina" ), +( 7, 13, "Margita" ), +( 7, 14, "Kamil" ), +( 7, 15, "Henrich" ), +( 7, 16, "Drahomir, Rut" ), +( 7, 17, "Bohuslav" ), +( 7, 18, "Kamila" ), +( 7, 19, "Dusana" ), +( 7, 20, "Ilja, Elias" ), +( 7, 21, "Daniel" ), +( 7, 22, "Magdalena" ), +( 7, 23, "Olga" ), +( 7, 24, "Vladimir" ), +( 7, 25, "Jakub, Timur" ), +( 7, 26, "Anna, Hana, Anita" ), +( 7, 27, "Bozena" ), +( 7, 28, "Kristof" ), +( 7, 29, "Marta" ), +( 7, 30, "Libusa" ), +( 7, 31, "Ignac" ), +( 8, 1, "Bozidara" ), +( 8, 2, "Gustav" ), +( 8, 3, "Jergus" ), +( 8, 4, "Dominika, Dominik" ), +( 8, 5, "Hortenzia" ), +( 8, 6, "Jozefina" ), +( 8, 7, "Stefania" ), +( 8, 8, "Oskar" ), +( 8, 9, "Lubomira" ), +( 8, 10, "Vavrinec" ), +( 8, 11, "Zuzana" ), +( 8, 12, "Darina" ), +( 8, 13, "Lubomir" ), +( 8, 14, "Mojmir" ), +( 8, 15, "Marcela" ), +( 8, 16, "Leonard" ), +( 8, 17, "Milica" ), +( 8, 18, "Elena, Helena" ), +( 8, 19, "Lydia" ), +( 8, 20, "Anabela, Liliana" ), +( 8, 21, "Jana" ), +( 8, 22, "Tichomir" ), +( 8, 23, "Filip" ), +( 8, 24, "Bartolomej" ), +( 8, 25, "Ludovit" ), +( 8, 26, "Samuel" ), +( 8, 27, "Silvia" ), +( 8, 28, "Augustin" ), +( 8, 29, "Nikola, Nikolaj" ), +( 8, 30, "Ruzena" ), +( 8, 31, "Nora" ), +( 9, 1, "Drahoslava" ), +( 9, 2, "Linda, Rebeka" ), +( 9, 3, "Belo" ), +( 9, 4, "Rozalia" ), +( 9, 5, "Regina" ), +( 9, 6, "Alica" ), +( 9, 7, "Marianna" ), +( 9, 8, "Miriama" ), +( 9, 9, "Martina" ), +( 9, 10, "Oleg" ), +( 9, 11, "Bystrik" ), +( 9, 12, "Maria, Marlena" ), +( 9, 13, "Ctibor" ), +( 9, 14, "Ludomil" ), +( 9, 15, "Jolana" ), +( 9, 16, "Ludmila" ), +( 9, 17, "Olympia" ), +( 9, 18, "Eugenia" ), +( 9, 19, "Konstantin" ), +( 9, 20, "Luboslav, Luboslava" ), +( 9, 21, "Matus" ), +( 9, 22, "Moric" ), +( 9, 23, "Zdenka" ), +( 9, 24, "Lubos, Lubor" ), +( 9, 25, "Vladislav, Vladislava" ), +( 9, 26, "Edita" ), +( 9, 27, "Cyprian" ), +( 9, 28, "Vaclav" ), +( 9, 29, "Michal, Michaela" ), +( 9, 30, "Jarolim" ), +( 10, 1, "Arnold" ), +( 10, 2, "Levoslav" ), +( 10, 3, "Stela" ), +( 10, 4, "Frantisek" ), +( 10, 5, "Viera" ), +( 10, 6, "Natalia" ), +( 10, 7, "Eliska" ), +( 10, 8, "Brigita" ), +( 10, 9, "Dionyz" ), +( 10, 10, "Slavomira" ), +( 10, 11, "Valentina" ), +( 10, 12, "Maximilian" ), +( 10, 13, "Koloman" ), +( 10, 14, "Boris" ), +( 10, 15, "Terezia" ), +( 10, 16, "Vladimira" ), +( 10, 17, "Hedviga" ), +( 10, 18, "Lukas" ), +( 10, 19, "Kristian" ), +( 10, 20, "Vendelin" ), +( 10, 21, "Ursula" ), +( 10, 22, "Sergej" ), +( 10, 23, "Alojzia" ), +( 10, 24, "Kvetoslava" ), +( 10, 25, "Aurel" ), +( 10, 26, "Demeter" ), +( 10, 27, "Sabina" ), +( 10, 28, "Dobromila" ), +( 10, 29, "Klara" ), +( 10, 30, "Simon, Simona" ), +( 10, 31, "Aurelia" ), +( 11, 1, "Denis, Denisa" ), +( 11, 3, "Hubert" ), +( 11, 4, "Karol" ), +( 11, 5, "Imrich" ), +( 11, 6, "Renata" ), +( 11, 7, "Rene" ), +( 11, 8, "Bohumir" ), +( 11, 9, "Teodor" ), +( 11, 10, "Tibor" ), +( 11, 11, "Martin, Maros" ), +( 11, 12, "Svatopluk" ), +( 11, 13, "Stanislav" ), +( 11, 14, "Irma" ), +( 11, 15, "Leopold" ), +( 11, 16, "Agnesa" ), +( 11, 17, "Klaudia" ), +( 11, 18, "Eugen" ), +( 11, 19, "Alzbeta" ), +( 11, 20, "Felix" ), +( 11, 21, "Elvira" ), +( 11, 22, "Cecilia" ), +( 11, 23, "Klement" ), +( 11, 24, "Emilia" ), +( 11, 25, "Katarina" ), +( 11, 26, "Kornel" ), +( 11, 27, "Milan" ), +( 11, 28, "Henrieta" ), +( 11, 29, "Vratko" ), +( 11, 30, "Ondrej, Andrej" ), +( 12, 1, "Edmund" ), +( 12, 2, "Bibiana" ), +( 12, 3, "Oldrich" ), +( 12, 4, "Barbora, Barbara" ), +( 12, 5, "Oto" ), +( 12, 6, "Mikulas" ), +( 12, 7, "Ambroz" ), +( 12, 8, "Marina" ), +( 12, 9, "Izabela" ), +( 12, 10, "Raduz" ), +( 12, 11, "Hilda" ), +( 12, 12, "Otilia" ), +( 12, 13, "Lucia" ), +( 12, 14, "Branislava, Bronislava" ), +( 12, 15, "Ivica" ), +( 12, 16, "Albina" ), +( 12, 17, "Kornelia" ), +( 12, 18, "Slava" ), +( 12, 19, "Judita" ), +( 12, 20, "Dagmara" ), +( 12, 21, "Bohdan" ), +( 12, 22, "Adela" ), +( 12, 23, "Nadezda" ), +( 12, 24, "Adam, Eva" ), +( 12, 26, "Stefan" ), +( 12, 27, "Filomena" ), +( 12, 28, "Ivana, Ivona" ), +( 12, 29, "Milada" ), +( 12, 30, "David" ), +( 12, 31, "Silvester" ) +);