<commit_before>#!/usr/bin/env python

#
# Copyright (C) 2016 <NAME>., <NAME>
#
# This script monitors noo-ebs broker and acts on messages
# It is an initial and temporary bridge to handle messages
#
# Want to be able to handle files in order to send out PSA
#  messages on consideration and subscription

import paho.mqtt.client as mqtt

# Unknown license, code found here:  http://stackoverflow.com/questions/31775450/publish-and-subscribe-with-paho-mqtt-client

# reference to MQTT python found here: http://mosquitto.org/documentation/python/

# requires:  sudo pip install paho-mqtt
# pip requires: sudo apt-get install python-pip

# Should include functionality to gzip and rotate of logs created by mon_mqtt to
# prevent filling all disk space
# 

message = 'ON'
def on_connect(mosq, obj, rc):
#    mqttc.subscribe("aebl/world", 0)
    mqttc.subscribe("nooebs/#", 0)
    print("rc: " + str(rc))

def on_message(mosq, obj, msg):
    global message
    print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
    message = msg.payload
#   Keep tabs on message requests from clients and act on them
#    mqttc.publish("aebl/world",msg.payload);
#    mqttc.publish("aebl/world","uvea/alive - ACK");
#    if 'ACK' in message:
#        mqttc.publish("aebl/alive/chan","NAK");
    if 'played' in message:
#        os.system("echo " + str(message) >> playlog.txt)
#
#       this parses line:
#         echo idetkev played /home/pi/ad/15secPonyOUT.mp4 | grep -o -E 'ad/[^ ]+' | sed 's/.*ad/\//'
#       result is:
#         //15secPonyOUT.mp4

        myFile = open('$HOME/playlog.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
    if 'IPv6' in message:
        myFile = open('$HOME/ipv6log.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
    if 'reboot' in message:
        myFile = open('$HOME/actionlog.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
#        mqttc.publish("test/output","NAK");
#    mqttcb.publish("test/output",msg.payload);


def on_publish(mosq, obj, mid):
    print("mid: " + str(mid))

def on_subscribe(mosq, obj, mid, granted_qos):
    print("Subscribed: " + str(mid) + " " + str(granted_qos))

def on_log(mosq, obj, level, string):
    print(string)

mqttc = mqtt.Client()
# Assign event callbacks
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe

# Connect
# mqttc.connect("localhost", 1883,60)

# eventually, messages should be managed on an aebl broker
# mqttc.connect("aebl.oss", 1883,60)
mqttc.connect("uveais.ca", 1883,60)
# mqttc.connect("fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b", 1883,60)
<commit_msg>Added reference to new small-srvr IPv6<commit_after>#!/usr/bin/env python

#
# Copyright (C) 2016 <NAME>., <NAME>
#
# This script monitors noo-ebs broker and acts on messages
# It is an initial and temporary bridge to handle messages
#
# Want to be able to handle files in order to send out PSA
#  messages on consideration and subscription

import paho.mqtt.client as mqtt

# Unknown license, code found here:  http://stackoverflow.com/questions/31775450/publish-and-subscribe-with-paho-mqtt-client

# reference to MQTT python found here: http://mosquitto.org/documentation/python/

# requires:  sudo pip install paho-mqtt
# pip requires: sudo apt-get install python-pip

# Should include functionality to gzip and rotate of logs created by mon_mqtt to
# prevent filling all disk space
# 

message = 'ON'
def on_connect(mosq, obj, rc):
#    mqttc.subscribe("aebl/world", 0)
    mqttc.subscribe("nooebs/#", 0)
    print("rc: " + str(rc))

def on_message(mosq, obj, msg):
    global message
    print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
    message = msg.payload
#   Keep tabs on message requests from clients and act on them
#    mqttc.publish("aebl/world",msg.payload);
#    mqttc.publish("aebl/world","uvea/alive - ACK");
#    if 'ACK' in message:
#        mqttc.publish("aebl/alive/chan","NAK");
    if 'played' in message:
#        os.system("echo " + str(message) >> playlog.txt)
#
#       this parses line:
#         echo idetkev played /home/pi/ad/15secPonyOUT.mp4 | grep -o -E 'ad/[^ ]+' | sed 's/.*ad/\//'
#       result is:
#         //15secPonyOUT.mp4

        myFile = open('$HOME/playlog.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
    if 'IPv6' in message:
        myFile = open('$HOME/ipv6log.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
    if 'reboot' in message:
        myFile = open('$HOME/actionlog.txt', 'a') # or 'a' to add text instead of truncate
        myFile.write(message + '\n')
        myFile.close()
#        mqttc.publish("test/output","NAK");
#    mqttcb.publish("test/output",msg.payload);


def on_publish(mosq, obj, mid):
    print("mid: " + str(mid))

def on_subscribe(mosq, obj, mid, granted_qos):
    print("Subscribed: " + str(mid) + " " + str(granted_qos))

def on_log(mosq, obj, level, string):
    print(string)

mqttc = mqtt.Client()
# Assign event callbacks
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe

# Connect
# mqttc.connect("localhost", 1883,60)

# eventually, messages should be managed on an aebl broker
# mqttc.connect("aebl.oss", 1883,60)
mqttc.connect("uveais.ca", 1883,60)
# mqttc.connect("fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b", 1883,60)
#
# New small-srvr V6
# mqttc.connect("fc00:db20:35b:7399::5", 1883,60)


{'fraction_non_alphanumeric': 0.14433170048985305, 'fraction_numerical': 0.026067179846046187, 'mean_word_length': 3.4594383775351014, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7524375', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2054, 'n_words': 526}