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 getlivedetail(self, liveId): url = "https://pocketapi.48.cn/live/api/v1/live/getLiveOne" form = {"liveId": str(liveId)} 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' } try: response = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=15).json() if response['status'] == 200: playStreamPath = response['content']['playStreamPath'] return playStreamPath, response else: return False, False except Exception as e: # raise e WARN("error when getlivedetail", e) return False, False
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 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 getMainpage(self): url = 'https://pjuju.48.cn/imsystem/api/im/v1/member/room/message/mainpage' header = { 'Host': 'pjuju.48.cn', 'version': '5.0.1', 'os': 'android', 'Accept-Encoding': 'gzip', 'IMEI': '866716037825810', 'User-Agent': 'Mobile_Pocket', 'Content-Length': '67', 'Connection': 'Keep-Alive', 'Content-Type': 'application/json;charset=utf-8', 'token': setting.token() } form = { "lastTime": 0, "limit": 10, "chatType": 0, "roomId": setting.roomId() } try: res = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=5).json() return res except Exception as identifier: WARN('getMainpage error', identifier) raise identifier
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'] == 401: WARN('koudai48.py授权验证失败') if not setting.token_verify(): WARN('token失效,尝试获取新token') setting.getNewToken() else: WARN('获取口袋房间信息出错', res['message'])
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 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 getlivedetail(self, liveId): url = "https://pocketapi.48.cn/live/api/v1/live/getLiveOne" form = {"liveId": str(liveId)} header = self.commonHeader(False, False) try: response = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=15).json() if response['status'] == 200: playStreamPath = response['content']['playStreamPath'] return playStreamPath, response else: return False, False except Exception as e: # raise e WARN("error when getlivedetail", e) return False, False
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 getVoteMsg(self, interval_sec): response = self.getAllPage() if not response: return False datas = response['content']['message'] msg_array = [] try: for data in datas: # 去掉旧于大于一个查询间隔的消息 if data['msgTime'] <= self.sysTime13 - 1000.0 * interval_sec: continue msg = "" extInfo = json.loads(data['extInfo']) if data['msgType'] == 'TEXT' and extInfo[ 'messageType'] == 'PRESENT_TEXT': # present msg if extInfo['giftInfo']['isVote']: # vote msg msg = [{ 'type': 'text', 'data': { 'text': '%s:投出了%d票' % (extInfo['user']['nickName'], int(extInfo['giftInfo']['giftNum'])) } }, { 'type': 'text', 'data': { 'text': '\n%s' % self.stamp_to_str(data['msgTime']) } }] msg_array.append(msg) except Exception as e: WARN("Error when Koudai48.getAllPage.cmts_array", e) return False else: if msg_array: return msg_array else: return False
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 rank(type): msg_array = [] err = False err_msg = '返回rank错误\n' pro_id_array = md_init(setting.pro_id()) for pro_id_dict in pro_id_array: msg = '' detail = getDetail(pro_id_dict['pro_id']) # type=1:总额榜 if type == 1: msg = msg + pro_id_dict['name'] + '·聚聚榜TOP20\n' + '------------\n' dic = getRankings(pro_id_dict['pro_id'], 1, 1) if int(dic['status']) == 0: for data in dic['data']: msg = msg + '【第' + \ str(data['rank']) + '名】: ' + data['nickname'] + \ '支持了' + str(data['backer_money']) + '元\n' elif int(dic['status']) == 2: err = True err_msg += dic['message'] elif type == 2: msg = msg + pro_id_dict['name'] + '·打卡榜TOP20\n' + '------------\n' dic = getRankings(pro_id_dict['pro_id'], 2, 1) if int(dic['status']) == 0: for data in dic['data']: msg = msg + '【第' + \ str(data['rank']) + '名】: ' + data['nickname'] + \ '已打卡' + str(data['support_days']) + '天\n' elif int(dic['status']) == 2: err = True err_msg += dic['message'] msg = msg + '------------\n【摩点】:' + pro_id_dict['url_short'] + '\n目前集资进度:¥' +\ str(detail['data'][0]['already_raised']) + '\n目标:¥' +\ detail['data'][0]['goal'] msg_array.append(msg) if err is True: WARN("modian rank error", err_msg) return err_msg elif err is False: return msg_array
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 getboardpage(self): cmts = [] url = 'https://pjuju.48.cn/imsystem/api/im/v1/member/room/message/boardpage' header = { 'Host': 'pjuju.48.cn', 'version': '5.0.1', 'os': 'android', 'Accept-Encoding': 'gzip', 'IMEI': '866716037825810', 'User-Agent': 'Mobile_Pocket', 'Content-Length': '67', 'Connection': 'Keep-Alive', 'Content-Type': 'application/json;charset=utf-8', 'token': setting.token() } form = { "lastTime": 0, "limit": 30, "isFirst": True, "roomId": setting.roomId() } try: res = requests.post(url, data=json.dumps(form), headers=header, verify=False, timeout=5).json() for data in res['content']['data']: extInfo = json.loads(data['extInfo']) if "giftId" in extInfo and "voteticket" in extInfo['giftId']: cmts.append((extInfo['senderName'], extInfo['giftName'], data['msgTimeStr'], data['msgTime'])) return cmts except Exception as identifier: WARN("getboardpage error", identifier) return []
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
print("未发现更新\n") return msg 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 try: sched.add_job(getdouying, 'interval', seconds=interval_delay, misfire_grace_time=interval_delay, coalesce=True, max_instances=15) except Exception as e: WARN('error when start thread') # 开始调度任务 sched.start()