예제 #1
0
 def __str__(self):
     tx = self.database.new_transaction()
     me = tx.schema.message_event('me')
     m = tx.schema.message('m')
     query = tx.schema.select(me.handled, me.time_to_fire, m.text).from_(m, me).where(
                                                                       (m.id == me.message_id) &
                                                                       (me.handled != _STATUS_HANDLED)
                                                                       ).order_by(me.time_to_fire).ascending()                    
     return "\n".join(["\t%s at %s: '%s'" % (st, _s_to_dt(s), text.strip()) for (st, s, text) in tx.execute(query)])
예제 #2
0
 def __str__(self):
     tx = self.database.new_transaction()
     me = tx.schema.message_event('me')
     m = tx.schema.message('m')
     query = tx.schema.select(me.handled, me.time_to_fire, m.text).from_(
         m, me).where((m.id == me.message_id)
                      & (me.handled != _STATUS_HANDLED)).order_by(
                          me.time_to_fire).ascending()
     return "\n".join([
         "\t%s at %s: '%s'" % (st, _s_to_dt(s), text.strip())
         for (st, s, text) in tx.execute(query)
     ])
예제 #3
0
    def digest(self, metadata):
        """digest <day or week> :- give a summary of today's events"""
        tx = metadata.tx

        s = tx.schema

        me = s.message_event("me")
        m = s.message("m")

        user_id = metadata['user_id']
        tz_offset = metadata.get('tz_offset', 0)
        mdt = metadata.get('event_datetime', datetime.now())

        mdt = mdt - timedelta(0, tz_offset)
        start_time = _dt_to_s(mdt)

        # this should be keyed of the message somewhere, but defaulted to the whole day.
        duration = metadata.get('digest_duration', 'today')
        delta = 3600 * 24
        if duration is 'week':
            delta *= 7

        messages = tx.execute(s.select(me.time_to_fire, m.text).\
                              from_(me, m).\
                              where(
                                    (me.message_id == m.id) &
                                    (m.user_id == user_id) &
                                    (me.handled != _STATUS_HANDLED) &
                                    (me.time_to_fire >= start_time) &
                                    (me.time_to_fire <= start_time + delta)
                                    ).order_by(me.time_to_fire).ascending()
                              )

        events = list()
        sb = list()

        for time_to_fire, message in messages:
            dt = _s_to_dt(time_to_fire + tz_offset)
            events.append((dt, message))
            sb.append("%s : %s" % (dt, message))

        string = "\n".join(sb) if len(sb) else "Nothing"

        print string
        metadata['command'] = 'digest_command'
        metadata['event_tuples'] = events
예제 #4
0
    def digest(self, metadata):
        """digest <day or week> :- give a summary of today's events"""
        tx = metadata.tx
        
        s = tx.schema
        
        me = s.message_event("me")
        m = s.message("m")
    
        user_id = metadata['user_id']
        tz_offset = metadata.get('tz_offset', 0)
        mdt =  metadata.get('event_datetime', datetime.now())
        
        mdt = mdt - timedelta(0, tz_offset)
        start_time = _dt_to_s(mdt)
        
        # this should be keyed of the message somewhere, but defaulted to the whole day.
        duration = metadata.get('digest_duration', 'today')
        delta = 3600 * 24
        if duration is 'week':
            delta *= 7
        
        messages = tx.execute(s.select(me.time_to_fire, m.text).\
                              from_(me, m).\
                              where(
                                    (me.message_id == m.id) & 
                                    (m.user_id == user_id) & 
                                    (me.handled != _STATUS_HANDLED) & 
                                    (me.time_to_fire >= start_time) &
                                    (me.time_to_fire <= start_time + delta)
                                    ).order_by(me.time_to_fire).ascending()
                              )
        
        events = list()
        sb = list()
        
        for time_to_fire, message in messages:
            dt = _s_to_dt(time_to_fire + tz_offset)
            events.append((dt, message))
            sb.append("%s : %s" % (dt, message))
            
        string = "\n".join(sb) if len(sb) else "Nothing" 

        print string
        metadata['command'] = 'digest_command'
        metadata['event_tuples'] = events