def callback(iq): if iq['type'] != 'result': if iq['error']['type'] == 'auth': self.core.information( 'You are not allowed to see the activity of this contact.', 'Error') else: self.core.information('Error retrieving the activity', 'Error') return seconds = iq['last_activity']['seconds'] status = iq['last_activity']['status'] from_ = iq['from'] msg = '\x19%s}The last activity of %s was %s ago%s' if not safeJID(from_).user: msg = '\x19%s}The uptime of %s is %s.' % ( dump_tuple(get_theme().COLOR_INFORMATION_TEXT), from_, common.parse_secs_to_str(seconds)) else: msg = '\x19%s}The last activity of %s was %s ago%s' % ( dump_tuple(get_theme().COLOR_INFORMATION_TEXT), from_, common.parse_secs_to_str(seconds), (' and their last status was %s' % status) if status else '', ) self.add_message(msg) self.core.refresh_window()
def callback(iq): if iq['type'] != 'result': if iq['error']['type'] == 'auth': self.core.information( 'You are not allowed to see the activity of this contact.', 'Error') else: self.core.information('Error retrieving the activity', 'Error') return seconds = iq['last_activity']['seconds'] status = iq['last_activity']['status'] from_ = iq['from'] msg = '\x19%s}The last activity of %s was %s ago%s' if not safeJID(from_).user: msg = '\x19%s}The uptime of %s is %s.' % ( dump_tuple(get_theme().COLOR_INFORMATION_TEXT), from_, common.parse_secs_to_str(seconds)) else: msg = '\x19%s}The last activity of %s was %s ago%s' % ( dump_tuple(get_theme().COLOR_INFORMATION_TEXT), from_, common.parse_secs_to_str(seconds), (' and his/her last status was %s' % status) if status else '', ) self.add_message(msg) self.core.refresh_window()
def callback(iq): for query in iq.xml.getiterator('{jabber:iq:last}query'): self.api.information( 'Server %s online since %s' % (iq['from'], parse_secs_to_str( int(query.attrib['seconds']))), 'Info') return self.api.information('Could not retrieve uptime', 'Error')
def callback(iq): for query in iq.xml.getiterator('{jabber:iq:last}query'): self.api.information( 'Server %s online since %s' % (iq['from'], parse_secs_to_str(int( query.attrib['seconds']))), 'Info') return self.api.information('Could not retrieve uptime', 'Error')
def command_tasks(self, arg, nocommand=None): if nocommand: s = 'The following tasks were loaded:\n' else: s = 'The following tasks are active:\n' for key in self.tasks: s += 'Task %s: %s every %s.\n' % (key, repr(self.tasks[key][1]), common.parse_secs_to_str(self.tasks[key][0])) if s: self.api.information(s, 'Info')
def command_tasks(self, arg, nocommand=None): if nocommand: s = 'The following tasks were loaded:\n' else: s = 'The following tasks are active:\n' for key in self.tasks: s += 'Task %s: %s every %s.\n' % (key, repr(self.tasks[key][1]), common.parse_secs_to_str( self.tasks[key][0])) if s: self.api.information(s, 'Info')
def callback(iq): "Callback for the last activity" if iq['type'] != 'result': if iq['error']['type'] == 'auth': self.core.information( 'You are not allowed to see the ' 'activity of this contact.', 'Error') else: self.core.information('Error retrieving the activity', 'Error') return seconds = iq['last_activity']['seconds'] status = iq['last_activity']['status'] from_ = iq['from'] if not safeJID(from_).user: msg = 'The uptime of %s is %s.' % ( from_, common.parse_secs_to_str(seconds)) else: msg = 'The last activity of %s was %s ago%s' % ( from_, common.parse_secs_to_str(seconds), (' and his/her last status was %s' % status) if status else '') self.core.information(msg, 'Info')
def command_remind(self, arg): args = common.shell_split(arg) if len(args) < 2: return time = common.parse_str_to_secs(args[0]) if not time: return self.tasks[self.count] = (time, args[1]) timed_event = timed_events.DelayedEvent(time, self.remind, self.count) self.api.add_timed_event(timed_event) self.api.information('Task %s added: %s every %s.' % (self.count, args[1], common.parse_secs_to_str(time)), 'Info') self.count += 1
def command_remind(self, arg): args = common.shell_split(arg) if len(args) < 2: return time = common.parse_str_to_secs(args[0]) if not time: return self.tasks[self.count] = (time, args[1]) timed_event = timed_events.DelayedEvent(time, self.remind, self.count) self.api.add_timed_event(timed_event) self.api.information( 'Task %s added: %s every %s.' % (self.count, args[1], common.parse_secs_to_str(time)), 'Info') self.count += 1
def test_parse_secs_to_str(): assert parse_secs_to_str(3601) == '1h1s' assert parse_secs_to_str(0) == '0s' with pytest.raises(TypeError): parse_secs_to_str('toto')