def __parse_message(self,message,data): if data is None: return message # Some dirty cleanup... :( try: del(data['timer_min']['time_table']) except: pass try: del(data['timer_max']['time_table']) except: pass data = terrariumUtils.flatten_dict(data) data['now'] = datetime.datetime.now().strftime('%c') for dateitem in ['timer_min_lastaction','timer_max_lastaction','last_update']: if dateitem in data: data[dateitem] = datetime.datetime.fromtimestamp(int(data[dateitem])).strftime('%c') for item in terrariumNotification.__regex_parse.findall(message): if 'raw_data' == item: message = message.replace('%' + item + '%',str(data) .replace(', ',"\n") .replace('\': ','\':') .replace('{','') .replace('}','')) elif item in data: message = message.replace('%' + item + '%',str(data[item])) return message.encode('utf8')
def save_environment(self, data): '''Save the terrariumPI environment config ''' config = {} for key, value in terrariumUtils.flatten_dict(data).items(): config[key] = value self.__config.remove_section('environment') return self.__update_config('environment', config, [])