<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

__version__ = "1.1"
'''
Python 2.7
Quick Program to log mqtt data (normally from mcThings modules, but could work with anything)

<NAME> 13th January 2017: V 1.0: Initial Release
<NAME>on15th January 2017: V 1.1: Added Nan Handling. No warning on +/-5s publising delays
'''

#from __future__ import print_function  #if you want python 3 print function

#import mosquitto
import paho.mqtt.client as paho
import json
import datetime
from collections import OrderedDict
import logging
import time
from logging.handlers import RotatingFileHandler

#----------- Start of Classes ------------
        
#----------- End of Classes ------------

#----------- Local Routines ------------

def decode_payload(payload):
    '''
    decode timestamp (if any), and format json for pretty printing
    '''
    indent = master_indent + 31 #number of spaces to indent json data
    try:
        #if it's json data, decode it (use OrderedDict to preserve keys order), else return as is...
        json_data = json.loads(payload.replace(":nan", ":NaN"), object_pairs_hook=OrderedDict)
        if not isinstance(json_data, dict): #if it's not a dictionary, probably just a number
            return json_data
        publish_delay_string = ''
        if "time" in json_data.keys():<commit_msg>Added NaN handling, fix typos<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

__version__ = "1.1"
'''
Python 2.7
Quick Program to log mqtt data (normally from mcThings modules, but could work with anything)

<NAME> 13th January 2017: V 1.0: Initial Release
<NAME> 15th January 2017: V 1.1: Added Nan Handling. No warning on +/-5s publising delays
'''

#from __future__ import print_function  #if you want python 3 print function

#import mosquitto
import paho.mqtt.client as paho
import json
import datetime
from collections import OrderedDict
import logging
import time
from logging.handlers import RotatingFileHandler

#----------- Start of Classes ------------
        
#----------- End of Classes ------------

#----------- Local Routines ------------

def decode_payload(payload):
    '''
    decode timestamp (if any), and format json for pretty printing
    '''
    indent = master_indent + 31 #number of spaces to indent json data
    try:
        #if it's json data, decode it (use OrderedDict to preserve keys order), else return as is...
        json_data = json.loads(payload.replace(":nan", ":NaN"), object_pairs_hook=OrderedDict)
        if not isinstance(json_data, dict): #if it's not a dictionary, probably just a number
            return json_data
        publish_delay_string = ''
        if "time" in json_data.keys():
{'fraction_non_alphanumeric': 0.13435057685150725, 'fraction_numerical': 0.018608113137327874, 'mean_word_length': 2.8181818181818183, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, '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': '2477807', 'n_tokens_mistral': 808, 'n_tokens_neox': 743, 'n_words': 302}