def _botCmd_info(self, bot, update): print(u"INFO!") chat_id = update.message.chat_id if chat_id in self.currentChats: txt = u"<b>Info:</b>" if gv.sd[u"en"] == 1: txt += u"\n{} System <b>ON</b>".format(gv.sd[u"name"]) else: txt += u"\n{} System <b>OFF</b>".format(gv.sd[u"name"]) if gv.sd[u"mm"] == 1: txt += u" - Manual Mode" else: txt += u" - Auto Mode" txt += get_running_programs_pon() txt += "\n--------------------------------------------" if gv.sd[u"lg"]: # Log is enabled, lets get the data from there log = read_log() if len(log) > 0: txt += u"\nLast {} Programs:".format(str(len(log[:5]))) for l in log[:5]: l[u"station"] = gv.snames[l[u"station"]] txt += u"\n <b>{station}</b> - Program: <i>{program}</i>".format( **l ) txt += u"\n {date} {start} Duration: <i>{duration}</i> ".format( **l ) else: txt += u"\nLast program <b>none</b>" else: if gv.lrun[1] == 98: pgr = u"Run-once" elif gv.lrun[1] == 99: pgr = u"Manual" else: pgr = str(gv.lrun[1]) start = time.gmtime(gv.now - gv.lrun[2]) if pgr != u"0": txt += ( u"\nLast program: <b>" + pgr + u"</b>,station: <b>" + str(gv.lrun[0]) + u"</b>,duration: <b>" + timestr(gv.lrun[2]) + u"</b>,start: <b>" + time.strftime(u"%H:%M:%S - %Y-%m-%d", start) + u"</b>" ) else: txt += u"\nLast program <b>none</b>" else: txt = u"I'm sorry Dave I'm afraid I can't do that." bot.sendMessage(chat_id, text=txt, parse_mode=u"HTML")
def _botCmd_info(self, bot, update): print "INFO!" chat_id = update.message.chat_id if chat_id in self.currentChats: txt = "<b>Info:</b>" if gv.sd['en'] == 1: txt += "\n{} System <b>ON</b>".format(gv.sd[u'name']) else: txt += "\n{} System <b>OFF</b>".format(gv.sd[u'name']) if gv.sd['mm'] == 1: txt += " - Manual Mode" else: txt += " - Auto Mode" txt += get_running_programs_pon() txt += '\n--------------------------------------------' if gv.sd['lg']: # Log is enabled, lets get the data from there log = read_log() if len(log) > 0: txt += '\nLast {} Programs:'.format(str(len(log[:5]))) for l in log[:5]: l['station'] = gv.snames[l['station']] txt += "\n <b>{station}</b> - Program: <i>{program}</i>".format( **l) txt += "\n {date} {start} Duration: <i>{duration}</i> ".format( **l) else: txt += '\nLast program <b>none</b>' else: if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) start = time.gmtime(gv.now - gv.lrun[2]) if pgr != '0': txt += ('\nLast program: <b>' + pgr + '</b>,station: <b>' + str(gv.lrun[0]) + '</b>,duration: <b>' + timestr(gv.lrun[2]) + '</b>,start: <b>' + time.strftime("%H:%M:%S - %Y-%m-%d", start) + '</b>') else: txt += '\nLast program <b>none</b>' else: txt = "I'm sorry Dave I'm afraid I can't do that." bot.sendMessage(chat_id, text=txt, parse_mode='HTML')
def log_email(self, subject, body, status): start = time.gmtime(gv.now) if gv.sd['lg']: logline = '{' + time.strftime('"time":"%H:%M:%S","date":"%Y-%m-%d', start) + \ '", "subject":"' + subject + '", "body":"' + body + \ '", "status":"' + status + '"}' lines = [] lines.append(logline + '\n') log = read_log('elog') for r in log: lines.append(json.dumps(r) + '\n') with open('./data/elog.json', 'w') as f: if gv.sd['lr']: f.writelines(lines[:gv.sd['lr']]) else: f.writelines(lines)
def _botCmd_info(self, bot, update): print "INFO!" chat_id = update.message.chat_id if chat_id in self.currentChats: txt = "<b>Info:</b>" if gv.sd['en'] == 1: txt += "\n{} System <b>ON</b>".format(gv.sd[u'name']) else: txt += "\n{} System <b>OFF</b>".format(gv.sd[u'name']) if gv.sd['mm'] == 1: txt += " - Manual Mode" else: txt += " - Auto Mode" txt += get_running_programs_pon() txt += '\n--------------------------------------------' if gv.sd['lg']: # Log is enabled, lets get the data from there log = read_log() if len(log) > 0: txt += '\nLast {} Programs:'.format(str(len(log[:5]))) for l in log[:5]: l['station'] = gv.snames[l['station']] txt += "\n <b>{station}</b> - Program: <i>{program}</i>".format(**l) txt += "\n {date} {start} Duration: <i>{duration}</i> ".format(**l) else: txt += '\nLast program <b>none</b>' else: if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) start = time.gmtime(gv.now - gv.lrun[2]) if pgr != '0': txt += ('\nLast program: <b>' + pgr + '</b>,station: <b>' + str(gv.lrun[0]) + '</b>,duration: <b>' + timestr( gv.lrun[2]) + '</b>,start: <b>' + time.strftime("%H:%M:%S - %Y-%m-%d", start) + '</b>') else: txt += '\nLast program <b>none</b>' else: txt = "I'm sorry Dave I'm afraid I can't do that." bot.sendMessage(chat_id, text=txt, parse_mode='HTML')
def GET(self): qdict = web.input() try: ddict = json.loads(qdict['data']) except: raise web.unauthorized() force_reboot = False info = {} for l in ['wlog', 'elog', 'slog', 'evlog']: if l in ddict and ddict[l]: end = ddict['end_date'] days = ddict['days_before'] start_after = ddict['start_after'] prefix = '' try: if l in ['slog', 'evlog']: prefix = 'sensors/' + gv.plugin_data['ld'][int(ddict['ldi'])]['name'] + '/logs/' except: pass records = read_log(prefix+l, end, days, start_after) info[l] = records for dlog in ['dlogirricloud', 'dlogirricloud_monitor', 'dlogirricloud_net_config']: if dlog in ddict and ddict[dlog]: records = [] try: with gv.log_lock: with open('./logs/' + dlog[4:] + '.out', 'r') as file: records = file.readlines() except: pass info[dlog] = [] for r in records: info[dlog].append(r) if 'lrun' in ddict and ddict['lrun']: info['lrun'] = gv.lrun if 'programs' in ddict: if ddict['programs'] == 1: info['programs'] = gv.pd else: gv.pd = ddict['programs'] jsave(gv.pd, 'programs') info['programs'] = 1 if 'ps' in ddict and ddict['ps']: info['ps'] = gv.ps if 'sbits' in ddict and ddict['sbits']: info['sbits'] = gv.sbits if 'srvals' in ddict and ddict['srvals']: info['srvals'] = gv.srvals if 'sensors' in ddict and 'ld' in gv.plugin_data: if ddict['sensors'] == 1: info['sensors'] = [] try: if 'ldi' not in ddict or int(ddict['ldi']) == -1: info['sensors'] = gv.plugin_data['ld'] else: info['sensors'] = gv.plugin_data['ld'][int(ddict['ldi'])] except: pass info['sensboards'] = i2c.get_vsb_boards().keys() info['remotesensboards'] = get_remote_sensor_boards() else: try: if 'ldi' not in ddict or int(ddict['ldi']) == -1: gv.plugin_data['ld'] = ddict['sensors'] else: gv.plugin_data['ld'][int(ddict['ldi'])] = ddict['sensors'] except: gv.plugin_data['ld'] = ddict['sensors'] jsave(gv.plugin_data['ld'], 'sensors') info['sensors'] = 1 if 'camera' in ddict and 'ca' in gv.plugin_data: if ddict['camera'] == 1: info['camera'] = gv.plugin_data['ca'] if 'cai' in ddict and ddict['cai']: info['cai'] = '' if gv.plugin_data['ca']['enable_camera'] == 'on': try: with open('./static/images/camera.jpg', mode='rb') as file: # b is important -> binary info['cai'] = base64.b64encode(file.read()) except: pass else: gv.plugin_data['ca'] = ddict['camera'] jsave(gv.plugin_data['ca'], 'camera') info['camera'] = 1 if 'sd' in ddict: if ddict['sd'] == 1: sd = gv.sd.copy() del sd['substation_network'] del sd['salt'] del sd['password'] del sd['pwd'] del sd['enable_upnp'] # stuff from base configuration stays as was del sd['subnet_only_substations'] del sd['external_proxy_port'] kill_keys = [] for k,v in sd.iteritems(): if len(k) > 2 and (k[0:2] == 'te' or k[0:2] == 'et'): kill_keys.append(k) for k in kill_keys: del sd[k] # dont send textemail or et_weather stuff info['sd'] = sd else: for field in ddict['sd']: gv.sd[field] = ddict['sd'][field] update_hostname(gv.sd['name']) update_tza(gv.sd['tza']) jsave(gv.sd, 'sd') info['sd'] = 1 force_reboot = True if 'snames' in ddict: if ddict['snames'] == 1: info['snames'] = gv.snames else: gv.snames = ddict['snames'] jsave(gv.snames, 'snames') info['snames'] = 1 if 'snotes' in ddict: if ddict['snotes'] == 1: info['snotes'] = gv.snotes else: gv.snotes = ddict['snotes'] jsave(gv.snotes, 'snotes') info['snotes'] = 1 if 'update_status' in ddict and ddict['update_status']: updatechecker.update_rev_data() info['update_status'] = updatechecker.status web.header('Content-Type', 'application/json') ret_str = json.dumps(info) if force_reboot: reboot(5) # give a few seconds to reply return ret_str
def GET(self): qdict = web.input() try: ddict = json.loads(qdict['data']) except: raise web.unauthorized() force_reboot = False info = {} for l in ['wlog', 'elog', 'slog', 'evlog']: if l in ddict and ddict[l]: end = ddict['end_date'] days = ddict['days_before'] prefix = '' try: if l in ['slog', 'evlog']: prefix = 'sensors/' + gv.plugin_data['ld'][int(ddict['ldi'])]['name'] + '/logs/' except: pass records = read_log(prefix+l, end, days) info[l] = records for dlog in ['dlogirricloud', 'dlogirricloud_monitor', 'dlogirricloud_net_config']: if dlog in ddict and ddict[dlog]: records = [] try: with open('./logs/' + dlog[4:] + '.out', 'r') as file: records = file.readlines() except: pass info[dlog] = [] for r in records: info[dlog].append(r) if 'lrun' in ddict and ddict['lrun']: info['lrun'] = gv.lrun if 'programs' in ddict: if ddict['programs'] == 1: info['programs'] = gv.pd else: gv.pd = ddict['programs'] jsave(gv.pd, 'programs') info['programs'] = 1 if 'ps' in ddict and ddict['ps']: info['ps'] = gv.ps if 'sbits' in ddict and ddict['sbits']: info['sbits'] = gv.sbits if 'srvals' in ddict and ddict['srvals']: info['srvals'] = gv.srvals if 'sensors' in ddict and 'ld' in gv.plugin_data: if ddict['sensors'] == 1: info['sensors'] = [] try: if 'ldi' not in ddict or int(ddict['ldi']) == -1: info['sensors'] = gv.plugin_data['ld'] else: info['sensors'] = gv.plugin_data['ld'][int(ddict['ldi'])] except: pass info['sensboards'] = i2c.get_vsb_boards().keys() info['remotesensboards'] = get_remote_sensor_boards() else: try: if 'ldi' not in ddict or int(ddict['ldi']) == -1: gv.plugin_data['ld'] = ddict['sensors'] else: gv.plugin_data['ld'][int(ddict['ldi'])] = ddict['sensors'] except: gv.plugin_data['ld'] = ddict['sensors'] jsave(gv.plugin_data['ld'], 'sensors') info['sensors'] = 1 if 'camera' in ddict and 'ca' in gv.plugin_data: if ddict['camera'] == 1: info['camera'] = gv.plugin_data['ca'] if 'cai' in ddict and ddict['cai']: info['cai'] = '' if gv.plugin_data['ca']['enable_camera'] == 'on': try: with open('./static/images/camera.jpg', mode='rb') as file: # b is important -> binary info['cai'] = base64.b64encode(file.read()) except: pass else: gv.plugin_data['ca'] = ddict['camera'] jsave(gv.plugin_data['ca'], 'camera') info['camera'] = 1 if 'sd' in ddict: if ddict['sd'] == 1: sd = gv.sd.copy() del sd['substation_network'] del sd['salt'] del sd['password'] del sd['pwd'] del sd['enable_upnp'] # stuff from base configuration stays as was del sd['subnet_only_substations'] del sd['external_proxy_port'] kill_keys = [] for k,v in sd.iteritems(): if len(k) > 2 and (k[0:2] == 'te' or k[0:2] == 'et'): kill_keys.append(k) for k in kill_keys: del sd[k] # dont send textemail or et_weather stuff info['sd'] = sd else: for field in ddict['sd']: gv.sd[field] = ddict['sd'][field] update_hostname(gv.sd['name']) update_tza(gv.sd['tza']) jsave(gv.sd, 'sd') info['sd'] = 1 force_reboot = True if 'snames' in ddict: if ddict['snames'] == 1: info['snames'] = gv.snames else: gv.snames = ddict['snames'] jsave(gv.snames, 'snames') info['snames'] = 1 if 'snotes' in ddict: if ddict['snotes'] == 1: info['snotes'] = gv.snotes else: gv.snotes = ddict['snotes'] jsave(gv.snotes, 'snotes') info['snotes'] = 1 if 'update_status' in ddict and ddict['update_status']: updatechecker.update_rev_data() info['update_status'] = updatechecker.status web.header('Content-Type', 'application/json') ret_str = json.dumps(info) if force_reboot: reboot(5) # give a few seconds to reply return ret_str