def getMainpage(self): roomId, ownerId = setting.roomId() url = "https://pocketapi.48.cn/im/api/v1/chatroom/msg/list/homeowner" 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: raise e
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() } res = requests.post(url, data=json.dumps(form), headers=header, verify=False).json() return res
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() } res = requests.post(url, data=json.dumps(form), headers=header, verify=False).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
def commonHeader(self, hasToken=True, hasPa=True): header = { 'Host': 'pocketapi.48.cn', 'accept': '*/*', 'Accept-Language': 'zh-Hans-CN;q=1', 'User-Agent': 'PocketFans201807/6.0.13 (iPhone; iOS 10.3.3; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'appInfo': '{"osType":"ios","vendor":"apple","os":"ios","appVersion":"6.0.13","osVersion":"10.3.3","deviceName":"iPhone 5","appBuild":"200513","deviceId":"DDDD-DDDD-DDDD-DDDD-DDDD"}', 'Content-Type': 'application/json;charset=utf-8', 'Connection': 'keep-alive', } if hasToken: header['token'] = setting.token() if hasPa: header['pa'] = self.getPa() return header
def main(): # set params parser = argparse.ArgumentParser() args = parser.parse_args() # init setting setting.dir_init() batch_size = setting.batch_size or 100 student_follow = setting.student_follow or 20 token = setting.token() snapshop_token = setting.snapshop_token() # dataset paths (x_train, y_train), (x_test, y_test) = cifar10.load_data() x_train = x_train.astype('float32') / 255.0 x_test= x_test.astype('float32') / 255.0 y_train = to_categorical(y_train) y_test = to_categorical(y_test) def plot(_data): import matplotlib.pyplot as plt plt.plot(_data) plt.show() # training with tf.device('gpu:0'): save_as = '%s_%s.h5' % (random.randint(0,10000), datetime.now().strftime('%Y-%m-%d')) teacher = Alpha(save_path='%s/%s' % (dir_path, setting.teacher_save)) student_zero = Beta(save_path='%s/%s' % (dir_path, setting.student_save_zero)) student = Beta(save_path='%s/%s' % (dir_path, setting.student_save)) student_second = Beta(save_path='%s/%s' % (dir_path, setting.student_save_second)) Evaluate_record = setting.Evaluate_record measure(teacher.model, 'Teacher') measure(student, 'Student') for circle in range(10): iter_size = int(len(x_train) / setting.slice_number) for idx in range(setting.slice_number): x_train_slice = x_train[idx*iter_size : (idx + 1)*iter_size] y_train_slice = y_train[idx*iter_size : (idx + 1)*iter_size] # teacher if circle < 5: teacher.save_history( teacher.model.fit(x_train_slice, y_train_slice, epochs=15, batch_size=setting.batch_size, validation_split = 0.1, verbose=1) ) format_plot( [teacher.format_history_by_key('acc')], save_name='Teacher_train_accuracy.png', title='Teacher_train_accuracy' ) # student model but no teacher print(x_train_slice.shape) print(y_train_slice.shape) student_zero.save_history( student_zero.model.fit(x_train_slice, y_train_slice, epochs=15, batch_size=setting.batch_size, validation_split = 0.1, verbose=1) ) format_plot( [student_zero.format_history_by_key('acc')], save_name='Student_zero_train_accuracy.png', title='Student_zero_train_accuracy' ) print('Iter (%s, %s)'.ljust(120, '-') % (circle, idx)) teacher_predictions = teacher.model.predict(x_train_slice) # student follow to train if setting.student_follow: # and circle < 3: student.save_history( student.model.fit(x_train_slice, teacher_predictions, epochs=15, batch_size=setting.batch_size, validation_split = 0.1, verbose=1) ) format_plot( [student.format_history_by_key('acc')], save_name='Student_training_from_teacher.png', title='Student_training_from_teacher' ) # student second if circle > 4: student_second.save_history( student_second.model.fit(x_train_slice, teacher_predictions, epochs=15, batch_size=setting.batch_size, validation_split = 0.1, verbose=1) ) format_plot( [student_second.format_history_by_key('acc')], save_name='Second_student_training_from_teacher.png', title='Second_student_training_from_teacher' ) # evaluate def format_eval(name, acc): print(''.ljust(40, '-')) print('%s eval_acc: %s' % (name, acc)) print() _, t_acc = teacher.model.evaluate(x_test, y_test) print(teacher.model) format_eval('Teacher', t_acc) _, s0_acc = student_zero.model.evaluate(x_test, y_test) print(student_zero.model) format_eval('Student zero', t_acc) _, s_acc = student.model.evaluate(x_test, y_test) print(student.model) format_eval('Student', t_acc) _, s2_acc = student_second.model.evaluate(x_test, y_test) print(student_second.model) format_eval('Student Two', t_acc) Evaluate_record['t_acc'].append(t_acc) Evaluate_record['s0_acc'].append(s0_acc) Evaluate_record['s_acc'].append(s_acc) if circle > 1: Evaluate_record['s2_acc'].append(s2_acc) else: Evaluate_record['s2_acc'].append(0) format_plot( [Evaluate_record['t_acc'], Evaluate_record['s0_acc'], Evaluate_record['s_acc'], Evaluate_record['s2_acc']], legends=['Teacher', 'Student_zero', 'Student', 'Student_second'], save_name='Evaluate.png', title='Teacher, Student to test data accuracy', xlabel='Slice No' ) teacher.save_model() student.save_model() student_zero.save_model() student_second.save_model() # evaluate accuracy, save picture loss, acc = teacher.model.evaluate(x_test, y_test) print('Training over'.ljust(120, '-')) print('Loss %s' % loss) print('Acc %s' % acc) print('Training success, mdoel saved')
def get_juju(bot): global msgTime_array global firstcheck_juju # 仅需修改播报的qq群昵称 gl = bot.List('group', groupid) if gl is not None: for group in gl: ajax_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() } response = requests.post(ajax_url, data=json.dumps(form), headers=header, verify=False).json() if response['status'] == 200: datas = response['content']['data'] # first check if firstcheck_juju == 0: for data in datas: msgTime_array.append(data['msgTime']) firstcheck_juju = 1 # # 控制list长度 msgTime_array = msgTime_array[-10:] # for data in datas: msg = '' # 判断重复 msgTime_array = sorted(msgTime_array) if data['msgTime'] in msgTime_array or data[ 'msgTime'] < msgTime_array[0]: continue else: msgTime_array.append(data['msgTime']) # # 文字消息 extInfo = json.loads(data['extInfo']) if data['msgType'] == 0: if extInfo['messageObject'] == 'text': msg = ('[%s]\n【口袋48房间消息】\n %s:%s' % (data['msgTimeStr'], extInfo['senderName'], extInfo['text'])) elif extInfo['messageObject'] == 'faipaiText': # 20171221 16:38 黄子璇(roomid=9108720)发生err:翻牌信息未返回faipaiName try: msg = ( '[%s]\n【口袋48房间翻牌】\n %s:%s\n 【被翻牌】%s:%s\n' % (data['msgTimeStr'], extInfo['senderName'], extInfo['messageText'], extInfo['faipaiName'], extInfo['faipaiContent'])) except: msg = ( '[%s]\n【口袋48房间翻牌】\n %s:%s\n 【被翻牌】%s\n' % (data['msgTimeStr'], extInfo['senderName'], extInfo['messageText'], extInfo['faipaiContent'])) # elif extInfo['messageObject'] == 'live': msg = ( '小偶像开视频直播啦 \n 直播标题:%s \n 直播封面:%s \n开始时间:%s \n 直播地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId'])) elif extInfo['messageObject'] == 'diantai': msg = ( '小偶像开电台啦 \n 电台标题:%s \n 电台封面:%s \n开始时间:%s \n 电台地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId'])) else: msg = '有未知格式的文字消息' WARN('有未知格式的文字消息') WARN(data) # image elif data['msgType'] == 1: bodys = json.loads(data['bodys']) msg = ('[%s]\n【口袋48房间图片】\n %s:%s' % (data['msgTimeStr'], extInfo['senderName'], bodys['url'])) # voice elif data['msgType'] == 2: bodys = json.loads(data['bodys']) msg = ('[%s]\n【口袋48房间语音】\n %s:%s' % (data['msgTimeStr'], extInfo['senderName'], bodys['url'])) else: msg = '有未知类型的消息' WARN('有未知类型的消息') WARN(data) bot.SendTo(group, msg) else: WARN('获取口袋房间信息出错') WARN(response['message'])
def get_juju(bot): global msgTime_array global firstcheck_juju # 仅需修改播报的qq群昵称 gl = bot.List('group', groupid) if gl is not None: ajax_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() } response = requests.post( ajax_url, data=json.dumps(form), headers=header, verify=False, proxies=setting.proxy() ).json() INFO('聚聚房间request一次') if response['status'] == 200: datas = response['content']['data'] # first check if firstcheck_juju == 0: for data in datas: msgTime_array.append(data['msgTime']) firstcheck_juju = 1 # # 控制list长度 msgTime_array = msgTime_array[-10:] # # 初始化消息队列 msg_array = [] # for data in datas: msg = '' # 判断重复 msgTime_array = sorted(msgTime_array) if data['msgTime'] in msgTime_array or data['msgTime'] < msgTime_array[0]: continue else: msgTime_array.append(data['msgTime']) # # 文字消息 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: msg = ('%s:%s\n翻牌:%s\n%s' % (extInfo['senderName'], extInfo['messageText'], extInfo['faipaiContent'], data['msgTimeStr'])) # elif extInfo['messageObject'] == 'live': msg = ('小偶像开视频直播啦 \n 直播标题:%s \n 直播封面:%s \n开始时间:%s \n 直播地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId'])) elif extInfo['messageObject'] == 'diantai': msg = ('小偶像开电台啦 \n 电台标题:%s \n 电台封面:%s \n开始时间:%s \n 电台地址:%s' % (extInfo['referenceContent'], 'https://source.48.cn' + extInfo['referencecoverImage'], data['msgTimeStr'], 'https://h5.48.cn/2017appshare/memberLiveShare/index.html?id=' + extInfo['referenceObjectId'])) elif extInfo['messageObject'] == 'idolFlip': # INFO('idol翻牌') msg = ('%s:%s\n问题内容:%s\n%s' % (extInfo['senderName'], extInfo['idolFlipTitle'], extInfo['idolFlipContent'], data['msgTimeStr'])) pass else: msg = '有未知格式的文字消息' WARN('有未知格式的文字消息') WARN(data) # image elif data['msgType'] == 1: bodys = json.loads(data['bodys']) msg = ('【口袋48房间图片】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr'])) # voice elif data['msgType'] == 2: bodys = json.loads(data['bodys']) msg = ('【口袋48房间语音】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr'])) # video elif data['msgType'] == 3: bodys = json.loads(data['bodys']) msg = ('【口袋48房间视频】\n %s:%s\n%s' % (extInfo['senderName'], bodys['url'], data['msgTimeStr'])) else: msg = '有未知类型的消息' WARN('有未知类型的消息') WARN(data) msg_array.append(msg) # 获取失败,检查token elif response['status'] == 401 and response['message'] == '授权验证失败': WARN('koudai48.py授权验证失败') if not setting.token_verify(): WARN('token失效,尝试获取新token') setting.getNewToken() else: WARN('获取口袋房间信息出错') WARN(response['message']) for group in gl: if msg_array: msg_array.reverse() for msgdata in msg_array: bot.SendTo(group, msgdata)