def checkin( self ): if self.appdisabled: return False try: self.twtaccess = Twitter(auth=OAuth(tininfo.TiNTwOAToken, tininfo.TiNTwOASecret, tininfo.TiNTwConKey, tininfo.TiNTwConSecret)) except: print 'Unable to check into PyRIDE REEM twitter app. Try again in 10mins.' return False self.startupTime = time.localtime() self.updatestatus( time.strftime( "I'm back online at %H:%M to serve ", time.localtime() ) + tininfo.TiNLocation + "." ) self.token = self.lastoken self.getmessages() tinstate.updateStatus( constants.NEW_MESSAGES, len( self.messages ) == 0 ) tid = PyREEM.addTimer( 60, -1, 60 ) self.timercontext[tid] = 'getmsg' timermanager.addTimer( tid, self ) #add purge archive time purgetime = timermanager.calcTimePeriodFromNow( "4:00" ) if purgetime > 0: tid = PyREEM.addTimer( purgetime, -1, 24*60*3600 ) self.timercontext[tid] = 'purgemsg' timermanager.addTimer( tid, self ) return True
def checkin(self): if self.appdisabled: return False try: self.twtaccess = Twitter( auth=OAuth(tininfo.TiNTwOAToken, tininfo.TiNTwOASecret, tininfo.TiNTwConKey, tininfo.TiNTwConSecret)) except: print 'Unable to check into PyRIDE REEM twitter app. Try again in 10mins.' return False self.startupTime = time.localtime() self.updatestatus( time.strftime("I'm back online at %H:%M to serve ", time.localtime()) + tininfo.TiNLocation + ".") self.token = self.lastoken self.getmessages() tinstate.updateStatus(constants.NEW_MESSAGES, len(self.messages) == 0) tid = PyREEM.addTimer(60, -1, 60) self.timercontext[tid] = 'getmsg' timermanager.addTimer(tid, self) #add purge archive time purgetime = timermanager.calcTimePeriodFromNow("4:00") if purgetime > 0: tid = PyREEM.addTimer(purgetime, -1, 24 * 60 * 3600) self.timercontext[tid] = 'purgemsg' timermanager.addTimer(tid, self) return True
def purgearchive(self): if len(self.archive) == 0: PyREEM.say("No archived message to be deleted.") return self.archive = [] tinstate.updateStatus(constants.ARCHIVE_MESSAGES, True) PyREEM.say("All archived message have been deleted.")
def purgearchive( self ): if len(self.archive) == 0: PyREEM.say( "No archived message to be deleted." ) return self.archive = [] tinstate.updateStatus( constants.ARCHIVE_MESSAGES, True ) PyREEM.say( "All archived message have been deleted." )
def onTimer( self, tid ): if tid not in self.timercontext: return if self.timercontext[tid] == 'getmsg': self.getmessages() tinstate.updateStatus( constants.NEW_MESSAGES, len( self.messages ) == 0 ) elif self.timercontext[tid] == 'purgemsg': self.archive = [] tinstate.updateStatus( constants.ARCHIVE_MESSAGES, True )
def announce( self ): self.archive = self.messages + self.archive self.messages = [] #self.announcemsg( self.archive ) if len(self.archive) > 0: self.lastoken = self.archive[0].id self.savestate() tinstate.updateStatus( constants.NEW_MESSAGES, True ) tinstate.updateStatus( constants.ARCHIVE_MESSAGES, len(self.archive) == 0 )
def announce(self): self.archive = self.messages + self.archive self.messages = [] #self.announcemsg( self.archive ) if len(self.archive) > 0: self.lastoken = self.archive[0].id self.savestate() tinstate.updateStatus(constants.NEW_MESSAGES, True) tinstate.updateStatus(constants.ARCHIVE_MESSAGES, len(self.archive) == 0)
def onTimer(self, tid): if tid not in self.timercontext: return if self.timercontext[tid] == 'getmsg': self.getmessages() tinstate.updateStatus(constants.NEW_MESSAGES, len(self.messages) == 0) elif self.timercontext[tid] == 'purgemsg': self.archive = [] tinstate.updateStatus(constants.ARCHIVE_MESSAGES, True)
def getmessages(self): if self.twtaccess == None: return try: if self.token == 0: newmessages = self.twtaccess.direct_messages() else: newmessages = self.twtaccess.direct_messages( since_id=self.token) except: print "Unable to retrieve messages" return if len(newmessages) == 0: return self.token = newmessages[0]['id'] #store only the basic info modmsg = [] for newmsg in newmessages: msg = TextMessage() msg.sender = newmsg['sender']['name'] msg.senderid = newmsg['sender']['id'] msg.created_at = time.localtime( time.mktime( time.strptime(newmsg['created_at'], "%a %b %d %H:%M:%S +0000 %Y")) - time.altzone) msg.text = newmsg['text'].strip() msg.id = newmsg['id'] if msg.text.startswith('#now#'): msg.text = msg.text[5:] PyNAO.say("Urgent message announcement \pau=1000\ ") self.announcemsg([msg]) tinstate.updateStatus(constants.ARCHIVE_MESSAGES, len(self.archive) == 0) elif msg.text.startswith('#qa#'): if time.mktime(msg.created_at) >= time.mktime( self.startupTime ): #ignore all direct requests before startup response = tinmind.respond(msg.text[4:]) if response: self.replymsg(msg.senderid, response) continue modmsg.append(msg) self.messages = modmsg + self.messages
def userLogoff(name): PyPR2.say('%s has logged off.' % name) tinstate.updateStatus(constants.USER_PRESENT, len(PyPR2.listCurrentUsers()) == 0)
def userLogon(name): PyPR2.say('%s has logged on.' % name) tinstate.updateStatus(constants.USER_PRESENT, False)
def userLogoff( name ): PyREEM.say( '%s has logged off.' % name ) tinstate.updateStatus( constants.USER_PRESENT, len(PyREEM.listCurrentUsers()) == 0)
def userLogon( name ): PyREEM.say( '%s has logged on.' % name ) tinstate.updateStatus( constants.USER_PRESENT, False )