def getkoudai(self): try: INFO('check koudai room') koudai = Koudai() # 检查是否有新消息 if koudai.checkNew(): INFO('have new room msg') # 判断酷Q版本 if self.version == 'air': msgArray = koudai.msgAir() elif self.version == 'pro': msgArray = koudai.msgPro() # 消息序列反向排序 msgArray.reverse() for msg in msgArray: print(msg) for grpid in self.pref3.getqqidarray(): self.bot.send_group_msg_async(group_id=grpid, message=msg, auto_escape=False) time.sleep(0.5) except Exception as e: WARN('error when getRoomMsg', e) raise e finally: INFO('koudai check completed')
def newOrder(stamp10, secondsDelay): msgDict_array = [] pro_id_array = md_init(pref4.getproidarray()) for pro_id_dict in pro_id_array: newOrders = [] # 获取一次订单信息,返回一个dictionary orderDict = getOrders(pro_id_dict['pro_id'], 1) # 查询失败则返回错误信息 if int(orderDict['status']) == 2: WARN("modian newOrder error", "获取订单错误", orderDict['message']) return orderDict['message'] # 20180319,防止空订单,循环查询五次 retry = 0 while not len(orderDict['data']): INFO("modian newOrder info", "疑似空订单") orderDict = getOrders(pro_id_dict['pro_id'], 1) retry += 1 if retry > 5: INFO("modian newOrder info", "订单5次为空,判断为无人集资") break # 查询成功,遍历data for data in orderDict['data']: pay_time = data['pay_time'] # 将字符串时间转换为unix时间戳 data['pay_time'] = int( time.mktime(time.strptime(pay_time, '%Y-%m-%d %H:%M:%S'))) # 筛选订单时间在查询时间前的设定时间段之间的订单 if data['pay_time'] >= stamp10 - secondsDelay and data[ 'pay_time'] < stamp10: newOrders.append(data) msgDict = {} # 有新订单 if newOrders: # 获取项目信息 detail = getDetail(pro_id_dict['pro_id']) # 查询失败则返回错误信息 if int(detail['status']) == 2: WARN("modian newOrder error", "获取项目信息错误", detail['message']) return detail['message'] # 查询成功,初始化消息 msgDict['msg'] = [] msg = '' for newOrder in newOrders: msg = "ID: " + newOrder['nickname'] +\ " 的聚聚刚刚在【" + pro_id_dict['name'] + "】中支持了 ¥" +\ str(newOrder['backer_money']) + '\n' + "感谢这位聚聚的支持" + '\n' msgDict['msg'].append(msg) msgDict['end'] = '【摩点】:' + pro_id_dict['url_short'] + '\n目前集资进度:¥' +\ str(detail['data'][0]['already_raised']) + '\n目标:¥' +\ str(detail['data'][0]['goal']) msgDict_array.append(msgDict) msgDict_array.append(orderDict) return msgDict_array
def getRoomMsg(): try: koudai = Koudai() # 检查是否有新消息 if koudai.checkNew(): # 判断酷Q版本 if version == 'air': msgArray = koudai.msgAir() elif version == 'pro': msgArray = koudai.msgPro() # 消息序列反向排序 msgArray.reverse() for msg in msgArray: for grpid in groupid(): bot.send_group_msg_async( group_id=grpid, message=msg, auto_escape=False) time.sleep(0.5) # print(msg) # 2019 投票播报 ticket_msg = koudai.getVoteMsg(int(interval_kd)) if ticket_msg: ticket_msg.reverse() for msg in ticket_msg: for grpid in groupid(): bot.send_group_msg_async( group_id=grpid, message=msg, auto_escape=False) time.sleep(0.5) except Exception as e: # raise e WARN('error when getRoomMsg', e) else: pass finally: INFO('room-check completed')
def getAllPage(self): roomId, ownerId = setting.roomId() url = "https://pocketapi.48.cn/im/api/v1/chatroom/msg/list/all" form = {'ownerId': int(ownerId), 'roomId': int(roomId)} header = { 'Host': 'pocketapi.48.cn', 'accept': '*/*', 'Accept-Language': 'zh-Hans-CN;q=1', 'User-Agent': 'PocketFans201807/6.0.0 (iPhone; iOS 12.2; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'appInfo': '{"vendor":"apple","deviceId":"0","appVersion":"6.0.0","appBuild":"190409","osVersion":"12.2.0","osType":"ios","deviceName":"iphone","os":"ios"}', 'Content-Type': 'application/json;charset=utf-8', 'Connection': 'keep-alive', 'token': setting.token() } try: response = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=15).json() # return response except Exception as e: WARN("Error when Koudai48.getAllPage", e) return False else: if int(response['status']) != 200: INFO("request fail when Koudai48.getAllPage.status", response) return False return response
def getWeibo(): # bot = CQHttp(api_root='http://127.0.0.1:5700/') try: # INFO(printStrTime() + 'check weibo') INFO('check weibo') global weibo_id_array global firstcheck_weibo wbcontent = '' idcount = -1 if (firstcheck_weibo == 1): # INFO(printStrTime() + 'first check weibo') INFO('first check weibo') weibo_id_array = copy.copy(getidarray()) firstcheck_weibo = False checkwbid = copy.copy(get_5_idarray()) if (firstcheck_weibo == 0): for cardid in checkwbid: idcount += 1 if int(cardid) == 0: continue if cardid not in weibo_id_array: weibo_id_array.append(cardid) retweet = checkretweet(idcount) wbpic = checkpic(idcount) wbscheme = getscheme(idcount) if (retweet): wbcontent = "源源刚刚[转发]了一条微博:" + '\n' + '\n' + getretweetweibo( idcount) + '\n' wbcontent = wbcontent + '\n' + "传送门:" + wbscheme else: wbcontent = "源源刚刚发了一条新微博:" + '\n' + '\n' + getweibo( idcount) + '\n' if (wbpic): wbcontent = wbcontent + getpic(idcount) wbcontent = wbcontent + '\n' + "传送门:" + wbscheme # print(printStrTime() + wbcontent) bot.send_group_msg_async(group_id=groupid(), message=wbcontent, auto_escape=False) except Exception as e: WARN('error when getWeibo') finally: # INFO(printStrTime() + 'weibo check completed') INFO('weibo check completed')
def getModian(): # bot = CQHttp(api_root='http://127.0.0.1:5700/') try: # INFO(printStrTime() + 'check modian') INFO('check modian') stampTime = int(time.time()) msgDict_array = newOrder(stampTime, int(interval_md)) for msgDict in msgDict_array: if msgDict: for msg in msgDict['msg']: msg += msgDict['end'] # print(printStrTime() + msg) bot.send_group_msg_async(group_id=groupid(), message=msg, auto_escape=False) time.sleep(0.1) except Exception as e: WARN('error when getModian') finally: # INFO(printStrTime() + 'modian check completed') INFO('modian check completed')
def getmodian(self): try: INFO('check modian') stampTime = int(time.time()) msgDict_array = newOrder(stampTime, int(self.interval_md)) for msgDict in msgDict_array[0:-1]: if msgDict: for msg in msgDict['msg']: msg += msgDict['end'] print(msg) for grpid in self.pref3.getqqidarray(): self.bot.send_group_msg_async(group_id=grpid, message=msg, auto_escape=False) time.sleep(0.1) except Exception as e: WARN('error when getModian', e, "modian dict:", msgDict_array[-1]) finally: INFO('modian check completed')
def getbilibili(): try: ini = getIni() idols = ini['idols'] QQgroup = ini['QQgroup'] for item in idols: stampTime = int(time.time()) msgDict = bilibili(stampTime, item['idol'], item['host_uid'], item["at"]) if msgDict: QQgroup = item['QQgroup'] if item['QQgroup'] else QQgroup for msg in msgDict: bot.send_group_msg_async(group_id=QQgroup, message=msg, auto_escape=False) time.sleep(.2) INFO(msgDict) time.sleep(1) except: WARN('error when bilibili') finally: INFO('bilibili check completed')
def getIdArray(self): weibo_id_array = [] cards = self.response['data']['cards'] for card in cards: try: weibo_id = card['mblog']['id'] except Exception as e: # 广告位无id,将其置0 weibo_id_array.append("0") else: weibo_id_array.append(weibo_id) INFO("weibo_id_array", weibo_id_array) return weibo_id_array
def getdouying(): try: INFO('check douying') stampTime = int(time.time()) msgDict = douying(stampTime, int(interval_delay)) if msgDict: bot.send_group_msg_async(group_id=QQqun, message=msgDict, auto_escape=False) time.sleep(0.1) except: WARN('error when douying') finally: pass
def getAllPage(self): roomId, ownerId = setting.roomId() url = "https://pocketapi.48.cn/im/api/v1/chatroom/msg/list/all" form = {'ownerId': int(ownerId), 'roomId': int(roomId)} header = self.commonHeader() try: response = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=15).json() # return response except Exception as e: WARN("Error when Koudai48.getAllPage", e) return False else: if int(response['status']) != 200: INFO("request fail when Koudai48.getAllPage.status", response) return False return response
def __init__(self): super(Koudai, self).__init__() # 获取系统时间和配置文件时间 self.sysTime13 = self.getSysTime13() self.cfgTime13 = self.getCfgTime13() # 请求一次口袋房间 res = self.getMainpage() # 请求成功 if res['status'] == 200: # 获取response self.response = res # 获取最新口袋消息时间 self.kdmsgTime13 = self.getKdmsgTime13() elif res['status'] >= 401000: WARN('koudai48.py授权验证失败', res) if not setting.token_verify(): WARN('token失效,尝试获取新token') refresh_token = setting.getNewToken() INFO("get new token ->", refresh_token) else: WARN('获取口袋房间信息出错', res['message'])
def msgPro(self): msg_array = [] datas = self.response['content']['message'] for data in datas: # 判断重复 if data['msgTime'] <= self.cfgTime13: continue # # 文字消息 extInfo = json.loads(data['extInfo']) if data['msgType'] == 'TEXT': if extInfo['messageType'] == 'TEXT': msg = ('%s:%s\n%s' % (extInfo['user']['nickName'], extInfo['text'], self.stamp_to_str(data['msgTime']))) elif extInfo['messageType'] == 'REPLY': msg = ('%s:%s\n%s:%s\n%s' % (extInfo['replyName'], extInfo['replyText'], extInfo['user']['nickName'], extInfo['text'], self.stamp_to_str(data['msgTime']))) elif extInfo['messageType'] == 'LIVEPUSH': playStreamPath, playDetail = self.getlivedetail( extInfo['liveId']) if not playStreamPath: playStreamPath = "暂无" if playDetail['content']['type'] == 1: msg = [{ 'type': 'text', 'data': { 'text': '小偶像开直播啦 \n 直播标题:%s \n直播封面:' % extInfo['liveTitle'] } }, { 'type': 'image', 'data': { 'file': 'https://source.48.cn%s' % extInfo['liveCover'] } }, { 'type': 'text', 'data': { 'text': '直播地址https://h5.48.cn/2019appshare/memberLiveShare/index.html?id=%s \n推流地址:%s开始时间:%s' % (extInfo['liveId'], playStreamPath, self.stamp_to_str(data['msgTime'])) } }] elif playDetail['content']['type'] == 2: msg = [{ 'type': 'text', 'data': { 'text': '小偶像开电台啦 \n 电台标题:%s \n电台封面:' % extInfo['liveTitle'] } }, { 'type': 'image', 'data': { 'file': 'https://source.48.cn%s' % extInfo['liveCover'] } }, { 'type': 'text', 'data': { 'text': '电台地址https://h5.48.cn/2019appshare/memberLiveShare/index.html?id=%s \n推流地址:%s开始时间:%s' % (extInfo['liveId'], playStreamPath, self.stamp_to_str(data['msgTime'])) } }] else: msg = '有未知格式的直播消息' INFO('有未知格式的直播消息') elif extInfo['messageType'] == 'VOTE': msg = ('%s:发起了投票:\n%s\n%s' % (extInfo['user']['nickName'], extInfo['text'], self.stamp_to_str(data['msgTime']))) elif extInfo['messageType'] == 'FLIPCARD': # INFO('idol翻牌') msg = ('%s:%s\n问题内容:%s\n%s' % (extInfo['user']['nickName'], extInfo['answer'], extInfo['question'], self.stamp_to_str(data['msgTime']))) else: msg = '有未知格式的文字消息' INFO('有未知格式的文字消息') INFO(extInfo) # image extInfo['user']['nickName'], bodys['url'], self.stamp_to_str(data['msgTime']) elif data['msgType'] == 'IMAGE': bodys = json.loads(data['bodys']) msg = [{ 'type': 'text', 'data': { 'text': '%s:图片消息' % extInfo['user']['nickName'] } }, { 'type': 'image', 'data': { 'file': '%s' % bodys['url'] } }, { 'type': 'text', 'data': { 'text': '%s' % self.stamp_to_str(data['msgTime']) } }] # voice extInfo['user']['nickName'], bodys['url'], self.stamp_to_str(data['msgTime']) elif data['msgType'] == 'AUDIO': bodys = json.loads(data['bodys']) msg = [{ 'type': 'text', 'data': { 'text': '%s:语音消息' % extInfo['user']['nickName'] } }, { 'type': 'record', 'data': { 'file': '%s' % bodys['url'] } }, { 'type': 'text', 'data': { 'text': '\n%s' % self.stamp_to_str(data['msgTime']) } }] # video elif data['msgType'] == 'VIDEO': bodys = json.loads(data['bodys']) msg = [{ 'type': 'text', 'data': { 'text': '%s:视频消息' % extInfo['user']['nickName'] } }, { 'type': 'text', 'data': { 'text': '%s' % bodys['url'] } }, { 'type': 'text', 'data': { 'text': '\n%s' % self.stamp_to_str(data['msgTime']) } }] elif data['msgType'] == 'EXPRESS': msg = ("%s: 发送了表情\n%s" % (extInfo['user']['nickName'], self.stamp_to_str(data['msgTime']))) else: msg = '有未知类型的消息' INFO('有未知类型的消息') INFO(data) msg_array.append(msg) return msg_array
def msgPro(self): msg_array = [] datas = self.response['content']['data'] for data in datas: # 判断重复 if data['msgTime'] <= self.cfgTime13: continue # # 文字消息 extInfo = json.loads(data['extInfo']) if data['msgType'] == 0: if extInfo['messageObject'] == 'text': msg = ('%s:%s\n%s' % (extInfo['senderName'], extInfo['text'], data['msgTimeStr'])) elif extInfo['messageObject'] == 'faipaiText': # 20171221 16:38 黄子璇(roomid=9108720)发生err:翻牌信息未返回faipaiName try: msg = ('%s:%s\n%s:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], extInfo['faipaiName'], extInfo['faipaiContent'], data['msgTimeStr'])) except Exception: # msg = ('%s:%s\n翻牌:%s\n%s' % ( # extInfo['senderName'], extInfo['messageText'], # extInfo['faipaiContent'], data['msgTimeStr'])) # 20180712更新,增加聚聚id查询nickname juju_nickname = self.showfpname( extInfo["faipaiUserId"]) if juju_nickname: msg = ( '%s:%s\n%s:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], juju_nickname, extInfo['faipaiContent'], data['msgTimeStr'])) else: msg = ( '%s:%s\n翻牌:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], extInfo['faipaiContent'], data['msgTimeStr'])) # elif extInfo['messageObject'] == 'live': msg = [{ 'type': 'text', 'data': { 'text': '小偶像开视频直播啦 \n 直播标题:%s \n \ 直播封面:' % extInfo['referenceContent'] } }, { 'type': 'image', 'data': { 'file': 'https://source.48.cn%s' % extInfo['referencecoverImage'] } }, { 'type': 'text', 'data': { 'text': '开始时间:%s \n 直播地址:https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=%s' % (data['msgTimeStr'], extInfo['referenceObjectId']) } }] elif extInfo['messageObject'] == 'diantai': msg = [{ 'type': 'text', 'data': { 'text': '小偶像开电台啦 \n 电台标题:%s \n 电台封面:' % extInfo['referenceContent'] } }, { 'type': 'image', 'data': { 'file': 'https://source.48.cn%s' % extInfo['referencecoverImage'] } }, { 'type': 'text', 'data': { 'text': '开始时间:%s \n 电台地址:https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=%s' % (data['msgTimeStr'], extInfo['referenceObjectId']) } }] elif extInfo['messageObject'] == 'idolFlip': # INFO('idol翻牌') msg = ('%s:%s\n问题内容:%s\n%s' % (extInfo['senderName'], extInfo['idolFlipTitle'], extInfo['idolFlipContent'], data['msgTimeStr'])) # 自己发的消息 elif extInfo['messageObject'] == 'messageBoard': pass else: msg = '有未知格式的文字消息' INFO('有未知格式的文字消息') INFO(extInfo) # image elif data['msgType'] == 1: bodys = json.loads(data['bodys']) msg = [{ 'type': 'text', 'data': { 'text': '%s:图片消息' % extInfo['senderName'] } }, { 'type': 'image', 'data': { 'file': '%s' % bodys['url'] } }, { 'type': 'text', 'data': { 'text': '%s' % data['msgTimeStr'] } }] # voice elif data['msgType'] == 2: bodys = json.loads(data['bodys']) msg = [{ 'type': 'text', 'data': { 'text': '%s:语音消息' % extInfo['senderName'] } }, { 'type': 'record', 'data': { 'file': '%s' % bodys['url'] } }, { 'type': 'text', 'data': { 'text': '\n%s' % data['msgTimeStr'] } }] # video elif data['msgType'] == 3: bodys = json.loads(data['bodys']) msg = ( '%s:视频消息:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr'])) else: msg = '有未知类型的消息' INFO('有未知类型的消息') INFO(data) msg_array.append(msg) return msg_array
def msgAir(self): msg_array = [] datas = self.response['content']['message'] for data in datas: # 判断重复 if data['msgTime'] <= self.cfgTime13: continue # # 文字消息 extInfo = json.loads(data['extInfo']) if data['msgType'] == 'TEXT': if extInfo['messageType'] == 'TEXT': msg = ('%s:%s\n%s' % (extInfo['user']['nickName'], extInfo['text'], self.stamp_to_str(data['msgTime']))) elif extInfo['messageType'] == 'REPLY': msg = ('%s:%s\n%s:%s\n%s' % (extInfo['replyName'], extInfo['replyText'], extInfo['user']['nickName'], extInfo['text'], self.stamp_to_str(data['msgTime']))) elif extInfo['messageType'] == 'LIVEPUSH': playStreamPath, playDetail = self.getlivedetail( extInfo['liveId']) if not playStreamPath: playStreamPath = "暂无" msg = ( '小偶像开直播啦 \n直播标题:%s \n直播封面:https://source.48.cn%s \n直播地址:https://h5.48.cn/2019appshare/memberLiveShare/index.html?id=%s \n推流地址:%s\n%s' % (extInfo['liveTitle'], extInfo['liveCover'], extInfo['liveId'], playStreamPath, self.stamp_to_str(data['msgTime']))) # elif extInfo['messageObject'] == 'diantai': # msg = ('小偶像开电台啦 \n电台标题:%s \n电台封面:https://source.48.cn%s \n开始时间:%s \n电台地址:https://h5.48.cn/2017appshare/\ # memberLiveShare/index.html?id=%s' % ( # extInfo['referenceContent'], # extInfo['referencecoverImage'], data['msgTimeStr'], # extInfo['referenceObjectId'])) elif extInfo['messageType'] == 'FLIPCARD': # INFO('idol翻牌') msg = ('%s:%s\n问题内容:%s\n%s' % (extInfo['user']['nickName'], extInfo['answer'], extInfo['question'], self.stamp_to_str(data['msgTime']))) else: msg = '有未知格式的文字消息' INFO('有未知格式的文字消息') INFO(data) # image elif data['msgType'] == 'IMAGE': bodys = json.loads(data['bodys']) msg = ('%s:图片消息:%s\n%s' % (extInfo['user']['nickName'], bodys['url'], self.stamp_to_str(data['msgTime']))) # voice elif data['msgType'] == 'AUDIO': bodys = json.loads(data['bodys']) msg = ('%s:语音消息:%s\n%s' % (extInfo['user']['nickName'], bodys['url'], self.stamp_to_str(data['msgTime']))) elif data['msgType'] == 'EXPRESS': msg = ("%s: 发送了表情\n%s" % (extInfo['user']['nickName'], self.stamp_to_str(data['msgTime']))) else: msg = '有未知类型的消息' INFO('有未知类型的消息') INFO(data) msg_array.append(msg) return msg_array
def getWeibo(): weibo = Weibo() try: INFO('check weibo') global weibo_id_array global firstcheck_weibo # 初次启动记录前十条微博id if firstcheck_weibo is True: INFO('first check weibo') weibo_id_array = weibo.IdArray firstcheck_weibo = False if firstcheck_weibo is False: # 取最新的前三条微博 for idcount in range(0, 3): # 广告位微博id为0,忽略 if int(weibo.IdArray[idcount]) == 0: continue # 微博id不在记录的id列表里,判断为新微博 if weibo.IdArray[idcount] not in weibo_id_array: msg = [] # 将id计入id列表 weibo_id_array.append(weibo.IdArray[idcount]) # 检查新微博是否是转发 if weibo.checkRetweet(idcount): msg.append( { 'type': 'text', 'data': {'text': '小偶像刚刚转发了一条微博:\n'}}) msg.append( { 'type': 'text', 'data': {'text': '%s\n' % weibo.getRetweetWeibo(idcount)}}) # 原创微博 else: msg.append( { 'type': 'text', 'data': {'text': '小偶像刚刚发了一条新微博:\n'}}) msg.append( { 'type': 'text', 'data': {'text': '%s\n' % weibo.getWeibo(idcount)}}) # 检查原创微博是否带图 if weibo.checkPic(idcount): # 只取第一张图,pro可以直接发图,air则无 msg.append( { 'type': 'image', 'data': {'file': '%s' % weibo.getPic(idcount)[0]}}) # 播报图的总数 if len(weibo.getPic(idcount)) > 1: msg.append( { 'type': 'text', 'data': {'text': '\n(一共有%d张图喔)\n' % len(weibo.getPic(idcount))}}) msg.append( { 'type': 'text', 'data': {'text': '传送门:%s' % weibo.getScheme(idcount)}}) for grpid in groupid(): bot.send_group_msg_async( group_id=grpid, message=msg, auto_escape=False) time.sleep(0.5) # print(msg) except Exception as e: WARN('error when getWeibo', e) finally: INFO('weibo check completed')
def newOrder(stamp10, secondsDelay): msgDict_array = [] pro_id_array = md_init(setting.pro_id(0)) for pro_id_dict in pro_id_array: newOrders = [] # 获取一次订单信息,返回一个dictionary orderDict = sorted_orders(pro_id_dict['pro_id'], 1) # 查询失败则返回错误信息 if int(orderDict['status']) == 2: WARN("modian newOrder error", "获取订单错误", orderDict['message']) print(orderDict['message']) return msgDict_array # 20180319,防止空订单,循环查询五次 retry = 0 while not len(orderDict['data']): INFO("modian newOrder info", "疑似空订单") orderDict = sorted_orders(pro_id_dict['pro_id'], 1) retry += 1 if retry > 5: INFO("modian newOrder info", "订单5次为空,判断为无人集资") break # 不具备本地order.josn的写法 查询成功,遍历摩点库 # for data in orderDict['data']: # pay_success_time = data['pay_success_time'] # # 将字符串时间转换为unix时间戳 # data['pay_success_time'] = int(time.mktime(time.strptime(pay_success_time, '%Y-%m-%d %H:%M:%S'))) # # 筛选订单时间在查询时间前的设定时间段之间的订单 # if data['pay_success_time'] >= stamp10 - secondsDelay and data['pay_success_time'] < stamp10: # newOrders.append(data) # ------ 20180723具备本地order.json的写法 ------ # 获得本地库 data = setting.openjson("order/" + str(pro_id_dict['pro_id'])) # 判断本地库是都为空 if data == []: newOrders = orderDict["data"] else: # 获得摩点库 alldata = orderDict["data"] # 对摩点库进行排序 alldata = setting.sortOrder(alldata) # 与本地库对比 if alldata[0]["pay_success_time"] == data[0]["pay_success_time"]: pass else: print("发现遗漏订单" + str(pro_id_dict['pro_id'])) # 获取本地库第一个订单的时间转换为时间戳 oneTime = int( time.mktime( time.strptime(data[0]["pay_success_time"], '%Y-%m-%d %H:%M:%S'))) # 循环摩点接口所有订单 for i in range(len(alldata)): # 将摩点订单时间转换为时间戳 iTime = int( time.mktime( time.strptime(alldata[i]["pay_success_time"], '%Y-%m-%d %H:%M:%S'))) # 在摩点库中找到本地最新的那一个订单 if iTime == oneTime: for j in range(i): newOrders.append(alldata[j]) data = newOrders + data setting.writejson(data, "order/" + str(pro_id_dict['pro_id'])) # 有新订单 msgDict = [] if newOrders: # 获取项目信息 detail = getDetail(pro_id_dict['pro_id']) # 查询失败则返回错误信息 if int(detail['status']) == 2: WARN("modian newOrder error", "获取项目信息错误", detail['message']) # return detail['message'] # 查询成功,初始化消息 msg = '' for newOrder in newOrders: msg = "ID:" + newOrder['nickname'] + "\n" +\ "金额:¥ " + str(newOrder['backer_money']) + '\n' +\ "项目:" + pro_id_dict['name'] + "\n" +\ "链接:" + pro_id_dict['url_short'] + "\n" +\ "感谢"+newOrder['nickname']+"对" + setting.idol_name() + "的支持呦~" + \ tool.relay(newOrder['backer_money']) +\ card.DrawCard(newOrder["user_id"],newOrder["nickname"],newOrder["backer_money"]) if str(pro_id_dict['pro_id']) == str( setting.openjson('ini')['modian']['pk']) or ( setting.openjson('ini')['pk']['status'] and not (setting.openjson('ini')['modian']['pk'])): msg += tool.showPk("\n\npk实况:") msgDict.append(msg) msgDict_array.append(msgDict) return msgDict_array
def douying(nowTime, secondsDelay): timeDate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) print("开始查询:" + timeDate) timeArray = [] # 获取用户数据 data = dydata(ini["user_id"], ini["dytk"]) # 判断之前是否记录 if not (ini["aweme_id"]): ini["aweme_id"] = data[0]["aweme_id"] writeData(ini) # 最后一次获取的抖音的id aweme_idS = ini["aweme_id"] if data == []: INFO(str(ini["name"]) + "未获取到数据,请检查用户是否发过抖音") print(str(ini["name"]) + "未获取到数据,请检查用户是否发过抖音") else: test = str(ini["name"]) + ":共有" + str(len(data)) + "条抖音" INFO(test) print(test) msg = "" for i in data: # aweme_id = 当前抖音的id aweme_id = i["aweme_id"] if int(aweme_id) > int(aweme_idS): # 讲这条数据加入待发送数组 timeArray.append(i) if timeArray: print("发现" + str(len(timeArray)) + "条新抖音\n") ini["aweme_id"] = timeArray[0]["aweme_id"] writeData(ini) for i in timeArray: share_desc = i["desc"] cover_img = "https://p9-dy.byteimg.com/img/" + i["video"]["cover"][ "uri"] + "~c5_300x400.jpg" play_addr = "https://aweme.snssdk.com/aweme/v1/play/?video_id=" + i[ "video"]["play_addr"]["uri"] + "&line=0" # msg = ini["name"] + "更新抖音啦!\n" + \ # "标题:" + share_desc + "\n" +\ # "封面:" + cover_img + "\n" +\ # "链接:" + play_addr + "\n" msg = [{ 'type': 'at', 'data': { 'qq': '476297692' } }, { 'type': 'text', 'data': { 'text': '\n%s更新抖音啦!\n标题:%s\n封面:\n' % (ini["name"], share_desc) } }, { 'type': 'image', 'data': { 'file': cover_img } }, { 'type': 'text', 'data': { 'text': '\n链接:%s\n' % play_addr } }] else: INFO("未发现更新\n") print("未发现更新\n") return msg