Ejemplo n.º 1
0
    async def get_latest_weibos(self):
        try:
            latest_weibos = []
            js = await self.get_weibo_json(1)
            if js['ok']:
                weibos = js['data']['cards']
                for w in weibos:
                    if w['card_type'] == 9:
                        wb = await self.get_one_weibo(w)
                        if wb:
                            if not self.__recent:
                                continue
                            if wb["id"] in self.received_weibo_ids:
                                continue
                            if (not self.filter) or (
                                    'retweet' not in wb.keys()):
                                if len(self.last_5_weibos) == 5:
                                    self.last_5_weibos.pop(0)
                                self.last_5_weibos.append(wb)

                                latest_weibos.append(wb)
                                self.received_weibo_ids.append(wb["id"])
                                #self.print_weibo(wb)
                            
            return latest_weibos
        except Exception as e:
            logger.exception(e)
            return []
async def clan_statistics_api(bm: BattleMaster, apikey):
    try:
        clan = check_clan(bm)
        report = get_report(bm, None, 0)
        mems = bm.list_member()
        members = [{'uid': m['uid'], 'nickname': m['name']} for m in mems]
        groupinfo = {
            'group_id': bm.group,
            'group_name': clan['name'],
            'game_server': SERVER_NAME[clan['server']],
            'battle_id': 0,
        }
        response = await make_response(
            jsonify(
                code=0,
                message='OK',
                api_version=1,
                challenges=report,
                groupinfo=groupinfo,
                members=members,
            ))
        #if (group.privacy & 0x2):
        #    response.headers['Access-Control-Allow-Origin'] = '*'
        return response
    except KeyError as e:
        logger.error(e)
        return jsonify(code=31, message='missing key: ' + str(e))
    except Exception as e:
        logger.exception(e)
        return jsonify(code=40, message='server error')
Ejemplo n.º 3
0
def _load_service_config(service_name):
    config_file = os.path.join(_service_config_dir, f'{service_name}.json')
    if not os.path.exists(config_file):
        return {}  # config file not found, return default config.
    try:
        with open(config_file, encoding='utf8') as f:
            config = json.load(f)
            return config
    except Exception as e:
        logger.exception(e)
        return {}
Ejemplo n.º 4
0
 async def get_one_weibo(self, info):
     """获取一条微博的全部信息"""
     try:
         weibo_info = info['mblog']
         weibo_id = weibo_info['id']
         retweeted_status = weibo_info.get('retweeted_status')
         is_long = weibo_info.get('isLongText')
         if retweeted_status and retweeted_status.get('id'):  # 转发
             retweet_id = retweeted_status.get('id')
             is_long_retweet = retweeted_status.get('isLongText')
             if is_long:
                 weibo = await self.get_long_weibo(weibo_id)
                 if not weibo:
                     weibo = self.parse_weibo(weibo_info)
             else:
                 weibo = self.parse_weibo(weibo_info)
             if is_long_retweet:
                 retweet = await self.get_long_weibo(retweet_id)
                 if not retweet:
                     retweet = self.parse_weibo(retweeted_status)
             else:
                 retweet = self.parse_weibo(retweeted_status)
             retweet['created_at'] = self.standardize_date(
                 retweeted_status['created_at'])
             weibo['retweet'] = retweet
         else:  # 原创
             if is_long:
                 weibo = await self.get_long_weibo(weibo_id)
                 if not weibo:
                     weibo = self.parse_weibo(weibo_info)
             else:
                 weibo = self.parse_weibo(weibo_info)
         weibo['created_at'] = self.standardize_date(
             weibo_info['created_at'])
         return weibo
     except Exception as e:
         logger.exception(e)
         self.__recent = False
def clan_setting_api(bm: BattleMaster, payload):
    try:
        action = payload['action']
        clan = check_clan(bm)
        if action == 'get_setting':
            return jsonify(
                code=0,
                groupData={
                    'group_name': clan['name'],
                    'game_server': SERVER_NAME[clan['server']],
                    'battle_id': 0,
                },
                privacy=3,
                notification=1023,
            )
        elif action == 'put_setting':
            # clan['server'] = payload['game_server']
            # clan['notification = payload['notification']
            # clan['privacy'] = payload['privacy']
            # clan.save()
            # logger.info('网页 成功 {} {} {}'.format(
            #     uid, group_id, action))
            # return jsonify(code=0, message='success')
            return jsonify(code=22, message='unfinished action')
        elif action == 'get_data_slot_record_count':
            # counts = self.get_data_slot_record_count(group_id)
            # logger.info('网页 成功 {} {} {}'.format(
            #     uid, group_id, action))
            # return jsonify(code=0, message='success', counts=counts)
            return jsonify(code=22, message='unfinished action')
        else:
            return jsonify(code=32, message='unknown action')
    except KeyError as e:
        logger.error(e)
        return jsonify(code=31, message='missing key: ' + str(e))
    except Exception as e:
        logger.exception(e)
        return jsonify(code=40, message='server error')
def clan_api(bm: BattleMaster, payload):
    try:
        clan = check_clan(bm)
        zone = bm.get_timezone_num(clan['server'])
        action = payload['action']
        if payload['uid'] == 0:
            # 允许游客查看
            if action not in ['get_member_list', 'get_challenge']:
                return jsonify(code=10, message='Not logged in')
        if action == 'get_member_list':
            mems = bm.list_member()
            members = [{'uid': m['uid'], 'nickname': m['name']} for m in mems]
            return jsonify(code=0, members=members)
        elif action == 'get_data':
            return jsonify(code=0,
                           bossData=get_boss_data(bm),
                           groupData={
                               'group_id': bm.group,
                               'group_name': clan['name'],
                               'game_server': SERVER_NAME[clan['server']],
                               'level_4': False
                           },
                           selfData={
                               'is_admin': False,
                               'user_id': payload['uid'],
                               'today_sl': False
                           })
        elif action == 'get_challenge':
            d = int(
                (datetime.now().timestamp() + (zone - 5) * 3600) / 86400) + 1
            report = get_report(bm, None, payload['ts'])
            if report is None:
                return jsonofy(code=20, message="Group dosen't exist")
            return jsonify(
                code=0,
                challenges=report,
                today=d,
            )
        elif action == 'get_user_challenge':
            report = get_report(bm, payload['target_uid'], 0)
            try:
                visited_user = get_member(bm, payload['target_uid'])
            except:
                return jsonify(code=20, message='user not found')
            return jsonify(code=0,
                           challenges=report,
                           game_server=SERVER_NAME[clan['server']],
                           user_info={
                               'uid': payload['target_uid'],
                               'nickname': visited_user['name']
                           })
        elif action == 'send_remind':

            return jsonify(code=0, notice='发送成功')
        else:
            return jsonify(code=32, message='unknown action')
    except KeyError as e:
        logger.error(e)
        return jsonify(code=31, message='missing key: ' + str(e))
    except Exception as e:
        logger.exception(e)
        return jsonify(code=40, message='server error')