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 sms_check(self): """Control and processing SMS""" data = get_sms_options() # Load data from json file tel1 = data['tel1'] tel2 = data['tel2'] comm1 = data['txt1'] comm2 = data['txt2'] comm3 = data['txt3'] comm4 = data['txt4'] comm5 = data['txt5'] comm6 = data['txt6'] sm = gammu.StateMachine() sm.ReadConfig() try: sm.Init() print "Checking SMS..." except: print "Error: SMS modem fault" status = sm.GetSMSStatus() remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed'] sms = [] start = True while remain > 0: if start: cursms = sm.GetNextSMS(Start=True, Folder=0) start = False else: cursms = sm.GetNextSMS(Location=cursms[0]['Location'], Folder=0) remain = remain - len(cursms) sms.append(cursms) data = gammu.LinkSMS(sms) for x in data: v = gammu.DecodeSMS(x) m = x[0] print '%-15s: %s' % ('Sender', m['Number']) print '%-15s: %s' % ('Date', str(m['DateTime'])) print '%-15s: %s' % ('State', m['State']) print '%-15s: %s' % ('SMS command', m['Text']) if (m['Number'] == tel1) or (m['Number'] == tel2): # If telephone is admin 1 or admin 2 self.add_status( time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ' SMS from admin') if m['State'] == "UnRead": # If SMS is unread if m['Text'] == comm1: # If command = comm1 (info - send SMS to admin phone1 and phone2) self.add_status('Command ' + comm1 + ' is processed') 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': logline = ' {program: ' + pgr + ',station: ' + str( gv.lrun[0]) + ',duration: ' + timestr( gv.lrun[2]) + ',start: ' + time.strftime( "%H:%M:%S - %Y-%m-%d", start) + '}' else: logline = ' Last program none' revision = ' Rev: ' + gv.ver_date datastr = ('On ' + time.strftime( "%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + '. Run time: ' + uptime() + ' IP: ' + get_ip() + logline + revision) message = { 'Text': datastr, 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm1 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) self.add_status('SMS text: ' + datastr) sm.DeleteSMS(m['Folder'], m['Location']) # SMS deleted self.add_status('Received SMS was deleted') elif m['Text'] == comm2: # If command = comm2 (stop - system OSPi off) self.add_status('Command ' + comm2 + ' is processed') gv.sd['en'] = 0 # disable system OSPi jsave(gv.sd, 'sd') # save en = 0 message = { 'Text': 'Command: ' + comm2 + ' was processed', 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm2 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'] == comm3: # If command = comm3 (start - system ospi on) self.add_status('Command ' + comm3 + ' is processed') gv.sd['en'] = 1 # enable system OSPi jsave(gv.sd, 'sd') # save en = 1 message = { 'Text': 'Command: ' + comm3 + ' was processed', 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm3 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'] == comm4: # If command = comm4 (reboot system) self.add_status('Command ' + comm4 + ' is processed') message = { 'Text': 'Command: ' + comm4 + ' was processed', 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm4 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status( 'Received SMS was deleted and system is now reboot') self._sleep(10) reboot() # restart linux system elif m['Text'] == comm5: # If command = comm5 (poweroff system) self.add_status('Command ' + comm5 + ' is processed') message = { 'Text': 'Command: ' + comm5 + ' was processed', 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm5 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status( 'Received SMS was deleted and system is now poweroff') self._sleep(10) poweroff() # poweroff linux system elif m['Text'] == comm6: # If command = comm6 (update ospi system) self.add_status('Command ' + comm6 + ' is processed') message = { 'Text': 'Command: ' + comm6 + ' was processed', 'SMSC': { 'Location': 1 }, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm6 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) try: from plugins.system_update import perform_update perform_update() self.add_status( 'Received SMS was deleted, update was performed and program will restart' ) except ImportError: self.add_status( 'Received SMS was deleted, but could not perform update' ) sm.DeleteSMS(m['Folder'], m['Location']) else: # If SMS command is not defined sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received command ' + m['Text'] + ' is not defined!') else: # If SMS was read sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted - SMS was read') else: # If telephone number is not admin 1 or admin 2 phone number sm.DeleteSMS(m['Folder'], m['Location']) self.add_status( 'Received SMS was deleted - SMS was not from admin')
def sms_check(self): """Control and processing SMS""" data = get_sms_options() # Load data from json file tels = data['tels'] comm1 = data['txt1'] comm2 = data['txt2'] comm3 = data['txt3'] comm4 = data['txt4'] comm5 = data['txt5'] comm6 = data['txt6'] comm7 = data['txt7'] sm = gammu.StateMachine() sm.ReadConfig() try: sm.Init() print "Checking SMS..." except: print "Error: SMS modem fault" status = sm.GetSMSStatus() remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed'] sms = [] start = True while remain > 0: if start: cursms = sm.GetNextSMS(Start=True, Folder=0) start = False else: cursms = sm.GetNextSMS(Location=cursms[0]['Location'], Folder=0) remain = remain - len(cursms) sms.append(cursms) data = gammu.LinkSMS(sms) for x in data: v = gammu.DecodeSMS(x) m = x[0] print '%-15s: %s' % ('Sender', m['Number']) print '%-15s: %s' % ('Date', str(m['DateTime'])) print '%-15s: %s' % ('State', m['State']) print '%-15s: %s' % ('SMS command', m['Text']) if m['Number'] in tels: # If telephone in admin lists self.add_status(time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ' SMS from admin') if m['State'] == "UnRead": # If SMS is unread if m['Text'].upper().strip() == comm1.upper(): # If command = comm1 (info - send SMS to admin phone1 and phone2) self.add_status('Command ' + comm1 + ' is processed') # Current Status logline = "Status: " if gv.srvals == [0] * len(gv.srvals): logline += "Idle. " elif gv.sd['mm'] == 1: # manual mode logline += "Manual Mode." for sid in range(len(gv.srvals)): if gv.srvals[sid]: if gv.rs[sid][1] == float('inf'): end_time = 'inf' else: end_time = time.strftime('%m-%d %H:%M', time.gmtime(gv.rs[sid][1])) logline += '\n st: ' + str(sid + 1) + ' dur: ' + end_time logline += "\n" else: logline += "Auto Mode." for sid in range(len(gv.srvals)): if gv.srvals[sid]: if gv.rs[sid][1] == float('inf'): end_time = 'inf' else: end_time = time.strftime('%m-%d %H:%M', time.gmtime(gv.rs[sid][1])) logline += '\n st: ' + str(sid + 1 ) + ' dur: ' + end_time logline += "\n" # Last RUN 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': logline += 'Last RUN: { prg: ' + pgr + ',st: ' + str(gv.lrun[0]) + ',dur: ' + timestr( gv.lrun[2]) + ',start: ' + time.strftime("%H:%M - %m-%d", start) + '}' else: logline += ' Last program none' # revision = ' Rev: ' + gv.ver_date datastr = ('On ' + time.strftime("%d.%m.%Y at %H:%M", time.localtime( time.time())) + '. ' + logline) msgs=[""] idx = 0 for line in datastr.splitlines(): if (len(msgs[idx]) + len(line)) < 140: msgs[idx] += line + "\n" else: msgs[idx] += "{continues....}" idx += 1 msgs.append(line) for txt in msgs: message = { 'Text': txt, 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm1 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) self.add_status('SMS text: ' + datastr) sm.DeleteSMS(m['Folder'], m['Location']) # SMS deleted self.add_status('Received SMS was deleted') self.add_status('Command ' + comm2 + ' is processed') stop_stations() time.sleep(3) gv.sd['en'] = 0 # disable system SIP jsave(gv.sd, 'sd') # save en = 0 message = { 'Text': 'Command: ' + comm2 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm2 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'].upper().strip() == comm3.upper(): # If command = comm3 (start - system sip on) self.add_status('Command ' + comm3 + ' is processed') gv.sd['en'] = 1 # enable system SIP stop_stations() gv.sd['mm'] = 0 # Put in auto mode jsave(gv.sd, 'sd') # save en = 1 message = { 'Text': 'Command: ' + comm3 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm3 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'].upper().strip() == comm4.upper(): # If command = comm4 (reboot system) self.add_status('Command ' + comm4 + ' is processed') message = { 'Text': 'Command: ' + comm4 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm4 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted and system is now reboot') self._sleep(10) reboot() # restart linux system elif m['Text'].upper().strip() == comm5.upper(): # If command = comm5 (poweroff system) self.add_status('Command ' + comm5 + ' is processed') message = { 'Text': 'Command: ' + comm5 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm5 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted and system is now poweroff') self._sleep(10) poweroff() # poweroff linux system elif m['Text'].upper().strip() == comm6.upper(): # If command = comm6 (update sip system) self.add_status('Command ' + comm6 + ' is processed') message = { 'Text': 'Command: ' + comm6 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm6 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) try: from plugins.system_update import perform_update perform_update() self.add_status('Received SMS was deleted, update was performed and program will restart') except ImportError: self.add_status('Received SMS was deleted, but could not perform update') sm.DeleteSMS(m['Folder'], m['Location']) elif m['Text'].strip().split()[0].upper() == comm7.upper(): # If command = comm7 (manual mode) self.add_status('Command ' + comm7 + ' is processed') message = "" command = m['Text'].strip().split()[1].upper() if (gv.sd['en'] == 0 or gv.sd['mm'] == 0 ) and command != "ON": message = { 'Text': 'Command: ' + comm7 + ' cannot continue, enable manual mode first with: ' +comm7+ ' on', 'SMSC': {'Location': 1}, 'Number': m['Number'], } elif command == "ON": # enable manual mode stop_stations() gv.sd['en'] = 1 gv.sd['mm'] = 1 jsave(gv.sd, 'sd') message = { 'Text': 'Command: ' + comm7 + ' manual mode enabled', 'SMSC': {'Location': 1}, 'Number': m['Number'], } else : # check the correct formatting # should be a pair of int separated by comma stations_duration = [0] * len(gv.srvals) try: for c in m['Text'].split()[1:]: station,duration = c.split(',') if not (0 < (int(station) -1) < len(stations_duration)): # out of range raise ValueError("Out of Range station ID") stations_duration[int(station) - 1 ] = int(duration)*60 except ValueError: message = { 'Text': 'Command: ' + comm7 + ' cannot continue, wrong command formatting, should be ' 'station,duration (in minutes)\n Example: ' + comm7 + ' 2,10 3,10', 'SMSC': {'Location': 1}, 'Number': m['Number'], } self.add_status('Command ' + comm7 + ' has formatting errors') if message == "": # logic copied from webpages.get_set_station for sid in range(len(stations_duration)): print "sid: " + str(sid) if sid == gv.sd['mas'] - 1: continue duration = stations_duration[sid] print "duration: " + str(duration) if duration > 0: gv.rs[sid][0] = gv.now # set start time to current time gv.rs[sid][2] = duration gv.rs[sid][1] = gv.rs[sid][0] + duration # stop time = start time + duration gv.rs[sid][3] = 99 # set program index gv.ps[sid][1] = duration gv.sd['bsy'] = 1 elif duration <= 0 and gv.srvals[sid]: # we should stop the running station gv.rs[sid][1] = gv.now time.sleep(1) message = { 'Text': 'Command: ' + comm7 + ' Processed OK ', 'SMSC': {'Location': 1}, 'Number': m['Number'], } self.add_status('Command ' + comm7 + ' Command OK') sm.SendSMS(message) self.add_status( 'Command: ' + comm7 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') self._sleep(10) else: # If SMS command is not defined sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received command ' + m['Text'] + ' is not defined!') else: # If SMS was read sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted - SMS was read') else: # If telephone number is not admin 1 or admin 2 phone number sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted - SMS was not from admin')
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 sms_check(self): """Control and processing SMS""" data = get_sms_options() # Load data from json file tel1 = data["tel1"] tel2 = data["tel2"] comm1 = data["txt1"] comm2 = data["txt2"] comm3 = data["txt3"] comm4 = data["txt4"] comm5 = data["txt5"] comm6 = data["txt6"] sm = gammu.StateMachine() sm.ReadConfig() try: sm.Init() print("Checking SMS...") except: print("Error: SMS modem fault") status = sm.GetSMSStatus() remain = status["SIMUsed"] + status["PhoneUsed"] + status["TemplatesUsed"] sms = [] start = True while remain > 0: if start: cursms = sm.GetNextSMS(Start=True, Folder=0) start = False else: cursms = sm.GetNextSMS(Location=cursms[0]["Location"], Folder=0) remain = remain - len(cursms) sms.append(cursms) data = gammu.LinkSMS(sms) for x in data: v = gammu.DecodeSMS(x) m = x[0] print("%-15s: %s" % ("Sender", m["Number"])) print("%-15s: %s" % ("Date", str(m["DateTime"]))) print("%-15s: %s" % ("State", m["State"])) print("%-15s: %s" % ("SMS command", m["Text"])) if (m["Number"] == tel1) or (m["Number"] == tel2): # If telephone is admin 1 or admin 2 self.add_status( time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + " SMS from admin") if m["State"] == "UnRead": # If SMS is unread if ( m["Text"] == comm1 ): # If command = comm1 (info - send SMS to admin phone1 and phone2) self.add_status("Command " + comm1 + " is processed") 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": logline = ( " {program: " + pgr + ",station: " + str(gv.lrun[0]) + ",duration: " + timestr(gv.lrun[2]) + ",start: " + time.strftime("%H:%M:%S - %Y-%m-%d", start) + "}") else: logline = " Last program none" revision = " Rev: " + gv.ver_date datastr = ("On " + time.strftime( "%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ". Run time: " + uptime() + " IP: " + get_ip() + logline + revision) message = { "Text": datastr, "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm1 + " was processed and confirmation was sent as SMS to: " + m["Number"]) self.add_status("SMS text: " + datastr) sm.DeleteSMS(m["Folder"], m["Location"]) # SMS deleted self.add_status("Received SMS was deleted") elif m["Text"] == comm2: # If command = comm2 (stop - system SIP off) self.add_status("Command " + comm2 + " is processed") gv.sd["en"] = 0 # disable system SIP jsave(gv.sd, "sd") # save en = 0 message = { "Text": "Command: " + comm2 + " was processed", "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm2 + " was processed and confirmation was sent as SMS to: " + m["Number"]) sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status("Received SMS was deleted") elif m["Text"] == comm3: # If command = comm3 (start - system SIP on) self.add_status("Command " + comm3 + " is processed") gv.sd["en"] = 1 # enable system SIP jsave(gv.sd, "sd") # save en = 1 message = { "Text": "Command: " + comm3 + " was processed", "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm3 + " was processed and confirmation was sent as SMS to: " + m["Number"]) sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status("Received SMS was deleted") elif m["Text"] == comm4: # If command = comm4 (reboot system) self.add_status("Command " + comm4 + " is processed") message = { "Text": "Command: " + comm4 + " was processed", "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm4 + " was processed and confirmation was sent as SMS to: " + m["Number"]) sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status( "Received SMS was deleted and system is now reboot") self._sleep(10) reboot() # restart linux system elif m["Text"] == comm5: # If command = comm5 (poweroff system) self.add_status("Command " + comm5 + " is processed") message = { "Text": "Command: " + comm5 + " was processed", "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm5 + " was processed and confirmation was sent as SMS to: " + m["Number"]) sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status( "Received SMS was deleted and system is now poweroff") self._sleep(10) poweroff() # poweroff linux system elif m["Text"] == comm6: # If command = comm6 (update SIP system) self.add_status("Command " + comm6 + " is processed") message = { "Text": "Command: " + comm6 + " was processed", "SMSC": { "Location": 1 }, "Number": m["Number"], } sm.SendSMS(message) self.add_status( "Command: " + comm6 + " was processed and confirmation was sent as SMS to: " + m["Number"]) try: from plugins.system_update import perform_update perform_update() self.add_status( "Received SMS was deleted, update was performed and program will restart" ) except ImportError: self.add_status( "Received SMS was deleted, but could not perform update" ) sm.DeleteSMS(m["Folder"], m["Location"]) else: # If SMS command is not defined sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status("Received command " + m["Text"] + " is not defined!") else: # If SMS was read sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status("Received SMS was deleted - SMS was read") else: # If telephone number is not admin 1 or admin 2 phone number sm.DeleteSMS(m["Folder"], m["Location"]) self.add_status( "Received SMS was deleted - SMS was not from admin")
def sms_check(self): """Control and processing SMS""" data = get_sms_options() # Load data from json file tel1 = data['tel1'] tel2 = data['tel2'] comm1 = data['txt1'] comm2 = data['txt2'] comm3 = data['txt3'] comm4 = data['txt4'] comm5 = data['txt5'] comm6 = data['txt6'] sm = gammu.StateMachine() sm.ReadConfig() try: sm.Init() print "Checking SMS..." except: print "Error: SMS modem fault" status = sm.GetSMSStatus() remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed'] sms = [] start = True while remain > 0: if start: cursms = sm.GetNextSMS(Start=True, Folder=0) start = False else: cursms = sm.GetNextSMS(Location=cursms[0]['Location'], Folder=0) remain = remain - len(cursms) sms.append(cursms) data = gammu.LinkSMS(sms) for x in data: v = gammu.DecodeSMS(x) m = x[0] print '%-15s: %s' % ('Sender', m['Number']) print '%-15s: %s' % ('Date', str(m['DateTime'])) print '%-15s: %s' % ('State', m['State']) print '%-15s: %s' % ('SMS command', m['Text']) if (m['Number'] == tel1) or (m['Number'] == tel2): # If telephone is admin 1 or admin 2 self.add_status(time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ' SMS from admin') if m['State'] == "UnRead": # If SMS is unread if m['Text'] == comm1: # If command = comm1 (info - send SMS to admin phone1 and phone2) self.add_status('Command ' + comm1 + ' is processed') 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': logline = ' {program: ' + pgr + ',station: ' + str(gv.lrun[0]) + ',duration: ' + timestr( gv.lrun[2]) + ',start: ' + time.strftime("%H:%M:%S - %Y-%m-%d", start) + '}' else: logline = ' Last program none' revision = ' Rev: ' + gv.ver_date datastr = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime( time.time())) + '. Run time: ' + uptime() + ' IP: ' + get_ip() + logline + revision) message = { 'Text': datastr, 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm1 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) self.add_status('SMS text: ' + datastr) sm.DeleteSMS(m['Folder'], m['Location']) # SMS deleted self.add_status('Received SMS was deleted') elif m['Text'] == comm2: # If command = comm2 (stop - system SIP off) self.add_status('Command ' + comm2 + ' is processed') gv.sd['en'] = 0 # disable system SIP jsave(gv.sd, 'sd') # save en = 0 message = { 'Text': 'Command: ' + comm2 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm2 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'] == comm3: # If command = comm3 (start - system SIP on) self.add_status('Command ' + comm3 + ' is processed') gv.sd['en'] = 1 # enable system SIP jsave(gv.sd, 'sd') # save en = 1 message = { 'Text': 'Command: ' + comm3 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm3 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted') elif m['Text'] == comm4: # If command = comm4 (reboot system) self.add_status('Command ' + comm4 + ' is processed') message = { 'Text': 'Command: ' + comm4 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm4 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted and system is now reboot') self._sleep(10) reboot() # restart linux system elif m['Text'] == comm5: # If command = comm5 (poweroff system) self.add_status('Command ' + comm5 + ' is processed') message = { 'Text': 'Command: ' + comm5 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm5 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted and system is now poweroff') self._sleep(10) poweroff() # poweroff linux system elif m['Text'] == comm6: # If command = comm6 (update SIP system) self.add_status('Command ' + comm6 + ' is processed') message = { 'Text': 'Command: ' + comm6 + ' was processed', 'SMSC': {'Location': 1}, 'Number': m['Number'], } sm.SendSMS(message) self.add_status( 'Command: ' + comm6 + ' was processed and confirmation was sent as SMS to: ' + m['Number']) try: from plugins.system_update import perform_update perform_update() self.add_status('Received SMS was deleted, update was performed and program will restart') except ImportError: self.add_status('Received SMS was deleted, but could not perform update') sm.DeleteSMS(m['Folder'], m['Location']) else: # If SMS command is not defined sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received command ' + m['Text'] + ' is not defined!') else: # If SMS was read sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted - SMS was read') else: # If telephone number is not admin 1 or admin 2 phone number sm.DeleteSMS(m['Folder'], m['Location']) self.add_status('Received SMS was deleted - SMS was not from admin')
def run(self): time.sleep( randint(3, 10) ) # Sleep some time to prevent printing before startup information dataeml = get_email_options() # load data from file subject = u"Report from " + gv.sd[u"name"] # Subject in email last_rain = 0 was_running = False self.status = u"" self.add_status(u"Email plugin is started") if dataeml[u"emllog"] != u"off": # if eml_log send email is enable (on) body = ( u"On " + time.strftime(u"%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + u": System was powered on." ) self.try_mail(subject, body, u"data/log.json") while True: try: # send if rain detected if dataeml[u"emlrain"] != u"off": # if eml_rain send email is enable (on) if ( gv.sd[u"rs"] != last_rain ): # send email only 1x if gv.sd rs change last_rain = gv.sd[u"rs"] if ( gv.sd[u"rs"] and gv.sd[u"urs"] ): # if rain sensed and use rain sensor body = ( u"On " + time.strftime( u"%d.%m.%Y at %H:%M:%S", time.localtime(time.time()) ) + u": System detected rain." ) self.try_mail( subject, body ) # send email without attachments if dataeml[u"emlrun"] != u"off": # if eml_rain send email is enable (on) running = False for b in range(gv.sd[u"nbrd"]): # Check each station once a second for s in range(8): sid = b * 8 + s # station index if gv.srvals[sid]: # if this station is on running = True was_running = True if was_running and not running: was_running = False if gv.lrun[1] == 98: pgr = u"Run-once" elif gv.lrun[1] == 99: pgr = u"Manual" else: pgr = str(gv.lrun[1]) dur = str(timestr(gv.lrun[2])) start = time.gmtime(gv.now - gv.lrun[2]) body = ( u"On " + time.strftime( u"%d.%m.%Y at %H:%M:%S", time.localtime(time.time()) ) + u"\n" u"SIP has run: Station " + str(gv.lrun[0] + 1) + u", " + gv.snames[gv.lrun[0]] + u"\n" u"Program: " + pgr + u"\n" u"Start time: " + time.strftime(u"%d.%m.%Y at %H:%M:%S", start) + u"\n" u"Duration: " + dur ) self.try_mail(subject, body) # send email without attachment self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = "".join( traceback.format_exception(exc_type, exc_value, exc_traceback) ) self.add_status(u"Email plugin encountered an error: " + err_string) self._sleep(60)
def run(self): time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information dataeml = get_email_options() # load data from file subject = "Report from OSPy" # Subject in email last_rain = 0 was_running = False self.status = "" self.add_status("Email plugin is started") if dataeml["emllog"] != "off": # if eml_log send email is enable (on) body = ( "On " + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ": System was powered on." ) self.try_mail(subject, body, "/home/pi/OSPy/data/log.json") while True: try: # send if rain detected if dataeml["emlrain"] != "off": # if eml_rain send email is enable (on) if gv.sd["rs"] != last_rain: # send email only 1x if gv.sd rs change last_rain = gv.sd["rs"] if gv.sd["rs"] and gv.sd["urs"]: # if rain sensed and use rain sensor body = ( "On " + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ": System detected rain." ) self.try_mail(subject, body) # send email without attachments if dataeml["emlrun"] != "off": # if eml_rain send email is enable (on) running = False for b in range(gv.sd["nbrd"]): # Check each station once a second for s in range(8): sid = b * 8 + s # station index if gv.srvals[sid]: # if this station is on running = True was_running = True if was_running and not running: was_running = False if gv.lrun[1] == 98: pgr = "Run-once" elif gv.lrun[1] == 99: pgr = "Manual" else: pgr = str(gv.lrun[1]) dur = str(timestr(gv.lrun[2])) start = time.gmtime(gv.now - gv.lrun[2]) body = ( "On " + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ": System last run: " + "Station " + str(gv.lrun[0]) + ", Program " + pgr + ", Duration " + dur + ", Start time " + time.strftime("%d.%m.%Y at %H:%M:%S", start) ) self.try_mail(subject, body) # send email without attachment self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)) self.add_status("Email plugin encountered error: " + err_string) self._sleep(60)
def run(self): time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information gv.plugin_data['te'] = get_email_options() # load data from file subject = "Report from SIP" # Subject in email last_rain = 0 was_running = False self.start_status('Email plugin is started') if gv.plugin_data['te']['telog'] != 'off': # if telog send email is enable (on) body = ('On ' + dtstring() + ': System was powered on.') self.try_mail(subject, body, "data/log.json") while True: try: # send if rain detected if gv.plugin_data['te']['terain'] != 'off': # if terain send email is enable (on) if gv.sd['rs'] != last_rain: # send email only 1x if gv.sd rs change last_rain = gv.sd['rs'] if gv.sd['rs'] and gv.sd['urs']: # if rain sensed and use rain sensor body = ('On ' + dtstring() + ': System detected rain.') self.try_mail(subject, body) # send email without attachments # send if leak triggered if gv.plugin_data['te']['teleak'] != 'off' and \ 'ld' in gv.plugin_data: # TODO figure out to report leaks pass if gv.plugin_data['te']['terun'] != 'off': # if terun send email is enable (on) running = False with gv.output_srvals_lock: for sid in range(gv.sd['nst']): # Check each station once a second if gv.output_srvals[sid]: # if this station is on running = True was_running = True if was_running and not running: was_running = False if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) dur = str(timestr(gv.lrun[2])) start = time.gmtime(gv.now - gv.lrun[2]) body = 'On ' + dtstring() + ': System last run: ' + 'Station ' + str(gv.lrun[0]+1) + \ ', Program ' + pgr + \ ', Duration ' + dur + \ ', Start time ' + dtstring(start) self.try_mail(subject, body) # send email without attachment self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) self.add_status('Text/Email plugin encountered error: ' + err_string) self._sleep(60)
def get_LCD_print(self, report): """Print messages to LCD 16x2""" find_i2c = 'True' lcd_adr = 0 pcf_type = 'None' import pylcd2 # Library for LCD 16x2 PCF8574 import smbus bus = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0) # find i2c adress for addr in range(32, 39): # PCF8574 range 0x20-0x27 if (find_i2c == 'True'): try: bus.write_quick(addr) lcd_adr = addr find_i2c = 'False' pcf_type = 'PCF8574' self.add_status('Find: ' + pcf_type + ' on adress 0x' + ('%02x' % lcd_adr)) except: find_i2c = 'True' for addr in range(56, 63): # PCF8574A range 0x38-0x3F if (find_i2c == 'True'): try: bus.write_quick(addr) lcd_adr = addr find_i2c = 'False' pcf_type = 'PCF8574A' self.add_status('Find: ' + pcf_type + ' on adress 0x' + ('%02x' % lcd_adr)) except: find_i2c = 'True' if (find_i2c == 'False'): lcd = pylcd2.lcd(lcd_adr, 1 if get_rpi_revision() >= 2 else 0) # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB) if report == 0: lcd.lcd_clear() lcd.lcd_puts("Open Sprinkler", 1) lcd.lcd_puts("Irrigation syst.", 2) self.add_status('Open Sprinkler / Irrigation syst.') elif report == 1: lcd.lcd_clear() lcd.lcd_puts("Software OSPy:", 1) lcd.lcd_puts(gv.ver_date, 2) self.add_status('Software OSPy: / ' + gv.ver_date) elif report == 2: lcd.lcd_clear() ip = get_ip() lcd.lcd_puts("My IP is:", 1) lcd.lcd_puts(str(ip), 2) self.add_status('My IP is: / ' + str(ip)) elif report == 3: lcd.lcd_clear() lcd.lcd_puts("Port IP:", 1) lcd.lcd_puts("8080", 2) self.add_status('Port IP: / 8080') elif report == 4: lcd.lcd_clear() temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu'] lcd.lcd_puts("CPU temperature:", 1) lcd.lcd_puts(temp, 2) self.add_status('CPU temperature: / ' + temp) elif report == 5: lcd.lcd_clear() da = time.strftime('%d.%m.%Y', time.gmtime(gv.now)) ti = time.strftime('%H:%M:%S', time.gmtime(gv.now)) lcd.lcd_puts(da, 1) lcd.lcd_puts(ti, 2) self.add_status(da + ' ' + ti) elif report == 6: lcd.lcd_clear() up = uptime() lcd.lcd_puts("System run time:", 1) lcd.lcd_puts(up, 2) self.add_status('System run time: / ' + up) elif report == 7: lcd.lcd_clear() if gv.sd['rs']: rain_sensor = "Active" else: rain_sensor = "Inactive" lcd.lcd_puts("Rain sensor:", 1) lcd.lcd_puts(rain_sensor, 2) self.add_status('Rain sensor: / ' + rain_sensor) elif report == 8: lcd.lcd_clear() try: from pressure_adj import get_check_pressure state_press = get_check_pressure() if state_press: lcd.lcd_puts("Pressure sensor:", 1) lcd.lcd_puts("GPIO is HIGH", 2) self.add_status('Pressure sensor: / GPIO is HIGH') else: lcd.lcd_puts("Pressure sensor:", 1) lcd.lcd_puts("GPIO is LOW", 2) self.add_status('Pressure sensor: / GPIO is LOW') except: lcd.lcd_puts("Pressure sensor:", 1) lcd.lcd_puts("Not used", 2) self.add_status('Pressure sensor: / Not used') elif report == 9: lcd.lcd_clear() if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) stop = time.gmtime(gv.lrun[2]) if pgr != '0': logline2 = 'P' + pgr + ' ' + timestr(gv.lrun[2]) else: logline2 = 'None' lcd.lcd_puts('Last program', 1) lcd.lcd_puts(logline2, 2) self.add_status('Last program / ' + logline2) #------- end text to 16x2 ----------------- elif report == 100: # start text to 16x1 lcd.lcd_clear() lcd.lcd_puts("Open Sprinkler", 1) self.add_status('Open Sprinkler') elif report == 101: lcd.lcd_clear() lcd.lcd_puts("Irrigation syst.", 1) self.add_status('Irrigation syst.') elif report == 102: lcd.lcd_clear() lcd.lcd_puts("Software OSPy:", 1) self.add_status('Software OSPy:') elif report == 103: lcd.lcd_clear() lcd.lcd_puts(gv.ver_date, 1) self.add_status(gv.ver_date) elif report == 104: lcd.lcd_clear() lcd.lcd_puts("My IP is:", 1) self.add_status('My IP is:') elif report == 105: lcd.lcd_clear() ip = get_ip() lcd.lcd_puts(str(ip), 1) self.add_status(str(ip)) elif report == 106: lcd.lcd_clear() lcd.lcd_puts("Port IP:", 1) self.add_status('Port IP:') elif report == 107: lcd.lcd_clear() lcd.lcd_puts("8080", 1) self.add_status('8080') elif report == 108: lcd.lcd_clear() lcd.lcd_puts("CPU temperature:", 1) self.add_status('CPU temperature:') elif report == 109: lcd.lcd_clear() temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu'] lcd.lcd_puts(temp, 1) self.add_status(temp) elif report == 110: lcd.lcd_clear() da = time.strftime('%d.%m.%Y', time.gmtime(gv.now)) lcd.lcd_puts("Date: " + da, 1) self.add_status('Date: ' + da) elif report == 111: lcd.lcd_clear() ti = time.strftime('%H:%M:%S', time.gmtime(gv.now)) lcd.lcd_puts("Time: " + ti, 1) self.add_status('Time: ' + ti) elif report == 112: lcd.lcd_clear() lcd.lcd_puts("System run time:", 1) self.add_status('System run time:') elif report == 113: lcd.lcd_clear() up = uptime() lcd.lcd_puts(up, 1) self.add_status(up) elif report == 114: lcd.lcd_clear() lcd.lcd_puts("Rain sensor:", 1) self.add_status('Rain sensor:') elif report == 115: lcd.lcd_clear() if gv.sd['rs']: rain_sensor = "Active" else: rain_sensor = "Inactive" lcd.lcd_puts(rain_sensor, 1) self.add_status(rain_sensor) elif report == 116: lcd.lcd_clear() lcd.lcd_puts('Last program', 1) self.add_status('Last program') elif report == 117: lcd.lcd_clear() if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) stop = time.gmtime(gv.lrun[2]) if pgr != '0': logline2 = 'P' + pgr + ' ' + timestr(gv.lrun[2]) else: logline2 = 'none' lcd.lcd_puts(logline2, 1) self.add_status(logline2) elif report == 118: lcd.lcd_clear() lcd.lcd_puts("Pressure sensor:", 1) self.add_status('Pressure sensor:') elif report == 119: lcd.lcd_clear() try: from pressure_adj import get_check_pressure state_press = get_check_pressure() if state_press: lcd.lcd_puts("GPIO is HIGH", 1) self.add_status('GPIO is HIGH') else: lcd.lcd_puts("GPIO is LOW", 1) self.add_status('GPIO is LOW') except: lcd.lcd_puts("Not used", 1) self.add_status('Not used') else: self.add_status('No find PCF8574 controller.')
def run(self): time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information dataeml = get_email_options() # load data from file subject = "Report from " + gv.sd['name'] # Subject in email last_rain = 0 was_running = False self.status = '' self.add_status('Email plugin is started') if dataeml["emllog"] != "off": # if eml_log send email is enable (on) body = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ': System was powered on.') self.try_mail(subject, body, "data/log.json") while True: try: # send if rain detected if dataeml["emlrain"] != "off": # if eml_rain send email is enable (on) if gv.sd['rs'] != last_rain: # send email only 1x if gv.sd rs change last_rain = gv.sd['rs'] if gv.sd['rs'] and gv.sd['urs']: # if rain sensed and use rain sensor body = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + ': System detected rain.') self.try_mail(subject, body) # send email without attachments if dataeml["emlrun"] != "off": # if eml_rain send email is enable (on) running = False for b in range(gv.sd['nbrd']): # Check each station once a second for s in range(8): sid = b * 8 + s # station index if gv.srvals[sid]: # if this station is on running = True was_running = True if was_running and not running: was_running = False if gv.lrun[1] == 98: pgr = 'Run-once' elif gv.lrun[1] == 99: pgr = 'Manual' else: pgr = str(gv.lrun[1]) dur = str(timestr(gv.lrun[2])) start = time.gmtime(gv.now - gv.lrun[2])\ body = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(time.time())) + '\n' 'SIP has run: Station ' + str(gv.lrun[0]+1) +", " + gv.snames[gv.lrun[0]] + '\n' 'Program: ' + pgr + '\n' 'Start time: ' + time.strftime("%d.%m.%Y at %H:%M:%S", start) + '\n' 'Duration: ' + dur) self.try_mail(subject, body) # send email without attachment self._sleep(1) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback)) self.add_status('Email plugin encountered error: ' + err_string) self._sleep(60)