示例#1
0
    def send(self, ttt, data, deta=-1):
        if(deta == -1):
            deta = tools.getRandom(self.detaTime, self.detaTimeMin)
        sendTime = tool.getNowTime()
        preTime = sendTime + deta
        sendTimeT = tool.parseTime(sendTime/1000, "%D %H:%M:%S")
        preTimeT = tool.parseTime(preTime/1000, "%D %H:%M:%S")

        # self.sendList1.append((sendTime, deta, preTime, type, data))
        # sendTime添加时间, type消息类型, msg发送消息体, deta间隔发送时间, preTime预期发送时间节点
        self.db.execute("insert into cochat values(?,?,?,?,?,?,?,?,?)", str(self.id), str(sendTime),str(sendTimeT), str(deta), str(preTime),str(preTimeT), str(ttt), str(data),'0')

        return
示例#2
0
 def timeSend(self):
     self.out("开启定时任务 发送队列!")
     self.nowNight = 0
     while (True):
         time.sleep(5)  #每分钟扫描 只对非凌晨时间处理 延时一小时发送
         timeNow = tool.getNowTime()
         hour = tool.parseTime(timeNow / 1000, "%H:%M")
         if (hour >= "23:30" or hour <= "07:40" or self.ifOk == False):
             if (self.nowNight != 1):
                 self.out("不是白天 或者 没有登录 now:" + str(hour))
             self.nowNight = 1
             continue
         self.nowNight = 0
         try:
             # self.sendList1.append((sendTime, deta, preTime, type, data))
             self.sendList = self.db.executeQuery(
                 "select * from cochat where preTime<=? and flag=0 and id=?",
                 timeNow, str(self.id))
             i = len(self.sendList) - 1
             while (i >= 0):
                 obj = self.sendList[i]
                 sendTime = int(obj.get("sendTime", 0))
                 #                    deta = int(obj.get("deta", 0))
                 preTime = int(obj.get("preTime", 0))
                 type = str(obj.get("type", ""))
                 data = ast.literal_eval((str(obj.get("msg", ""))))
                 info = ""
                 hour = tool.parseTime(preTime / 1000, "%D %H:%M:%S")
                 info = str(timeNow) + "->" + str(preTime) + " 推送时刻:" + str(
                     hour)
                 if (timeNow >= preTime):
                     info += " 触发"
                     self.sendTrue(type, data)
                     # self.sendList.pop(i)
                 else:
                     info += " "
                 self.out(
                     tool.parseTime(timeNow / 1000, "%D %H:%M:%S") + "." +
                     str(type) + "." + str(data) + "." + info)
                 i = i - 1
             self.db.execute(
                 "update cochat set flag='1' where preTime<=? and flag=0 and id=? ",
                 timeNow, str(self.id))
         except Exception as e:
             self.out(traceback.format_exc())
     return