Exemplo n.º 1
0
    def dump(self):
        arrBytes = self.data.split(sep=IPMSG.PACKET_SEP)
        if len(arrBytes) < 5:
            logger.error('来自%s的报文不正确,报文内容%s' %
                         (self.ip, self.data.decode(IPMSG.ENCODETYPE)))

        self.version = arrBytes[0].decode(IPMSG.ENCODETYPE)

        arrVersion = self.version.split('#')
        self.mac = arrVersion[2]

        self.packno = int(arrBytes[1])

        self.loginname = arrBytes[2].decode(IPMSG.ENCODETYPE)

        self.hostname = arrBytes[3].decode(IPMSG.ENCODETYPE)

        self.cmd = int(arrBytes[4].decode(IPMSG.ENCODETYPE))

        if len(arrBytes) > 5:
            tmpExtra = IPMSG.PACKET_SEP.join(arrBytes[5:])
            lastIndex = tmpExtra.rfind(b'\0')
            if lastIndex != -1:
                self.extra = tmpExtra[:lastIndex]
            else:
                self.extra = tmpExtra
 def get_null_birthdays(self):
     try:
         logger.info("Getting Null birthday ids")
         null_birthday_data = self.cur.execute(
             "SELECT * FROM events WHERE birthday_event_id is null")
     except sqlite3.Error as error:
         logger.error(f"Error getting null birthday data: {error}")
     else:
         null_data = null_birthday_data.fetchall()
         return null_data
 def get_event(self, contact_event_id):
     try:
         logger.info(f"Getting birthday for contact_ID {contact_event_id}")
         data = self.cur.execute(
             "SELECT * FROM events WHERE contact_event_id=?",
             (contact_event_id, ))
     except sqlite3.Error as error:
         logger.error(
             f"Error getting event for contact_id {contact_event_id}: {error}"
         )
     else:
         return data
 def update_birthday_id(self, id, birthday_event_id):
     try:
         logger.info(f"Updating birthday event id for id: {id}")
         self.cur.execute(
             "UPDATE events SET birthday_event_id=? WHERE id=?",
             (birthday_event_id, id),
         )
     except sqlite3.Error as error:
         logger.error(f"Error updating birthday_event_id for {id}: {error}")
     else:
         logger.info(f"Updated birthday_event_id for {id}")
         self.conn.commit()
 def insert_contact_birthday(self, contact_event_id, full_name, date,
                             event_name, event_type):
     try:
         logger.info("Inserting contact birthday")
         self.cur.execute(
             "INSERT INTO events (full_name,date,event_name,event_type,contact_event_id) VALUES (?,?,?,?,?)",
             (full_name, date, event_name, event_type, contact_event_id),
         )
     except sqlite3.IntegrityError as error:
         logger.error(f"Error inserting contact birthday: {error}")
     else:
         logger.info(f"Inserted {contact_event_id} into events")
         self.conn.commit()
Exemplo n.º 6
0
def update_birthdays():
    null_data = calendar_db.get_null_birthdays()
    for null_row in null_data:
        date = null_row['date']
        id = null_row['id']
        event_name = null_row['summary']
        event_data = {'summary':event_name,'description':event_name,'start':{'date':date},'recurrence':['RRULE:FREQ=YEARLY']}
        try:
            result = calendar_service.events().insert(calendarId=BIRTHDAY_CALENDAR_ID,body=event_data).execute()
        except  Exception as error:
            logger.error(f'Error updating birthday for {id}: {error}')
        else:
            birthday_id = result['id']
            calendar_db.update_birthday_id(id,birthday_id)
 def does_contact_exist(self, contact_event_id):
     try:
         logger.info(
             f"Checking if contact_event_id exists: {contact_event_id}")
         data = self.cur.execute(
             "SELECT * FROM events WHERE contact_event_id=?",
             (contact_event_id, ))
     except sqlite3.Error as error:
         logger.error(
             f"Error checking contact id {contact_event_id}:{error}")
     else:
         rows = data.fetchall()
         if len(rows) > 0:
             return True
         else:
             return False
Exemplo n.º 8
0
    def sendTextContent(self, content: PacketContent, useEncrypt=True):
        addr = self.usermanager.getAddr(content.peer)
        if addr is None:
            logger.error('发送任务失败,无法获取需要发送的地址:%s' % content.peer)
            return
        if useEncrypt:
            sender = EncryptTxtSender(content)
        else:
            sender = TextSender(content)

        sender.setData(self.me, addr[0], addr[1])

        # 超时后发送消息
        def sendTimeout():
            self.onPacketTimeout(content)

        #发送数据
        def send():
            #批量发送文本
            self.BatchCreateDelayTask(self.__func_send(sender),
                                      str(sender.packet.packno), '批量发送文本', 0,
                                      1000, 4)

            #准备到期超时消息,5000ms后超时
            self.CreateDelayTask(sendTimeout, 5000, '消息超时',
                                 str(sender.packet.packno))

        if not useEncrypt or SecurtInstance.hsaKey(content.peer):
            send()
        else:
            rsaSender = ReqRsaSender()
            rsaSender.setData(self.me, addr[0], addr[1])
            self.CreateImmediatelyTask(self.__func_send(rsaSender),
                                       "请求RAS PUBKEY",
                                       'PUBKEY_' + content.peer)

            self.CreateSwitchTask(send, sendTimeout, 'PUBKEY_' + content.peer,
                                  5000, '请求密钥后发送消息任务')
Exemplo n.º 9
0
 def onPacketTimeout(self, content):
     logger.error('发送报文超时---->%s' % content)