当前位置: 首页>>代码示例>>Python>>正文


Python ApiWrapper.issue_api_call方法代码示例

本文整理汇总了Python中api_wrapper.ApiWrapper.issue_api_call方法的典型用法代码示例。如果您正苦于以下问题:Python ApiWrapper.issue_api_call方法的具体用法?Python ApiWrapper.issue_api_call怎么用?Python ApiWrapper.issue_api_call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在api_wrapper.ApiWrapper的用法示例。


在下文中一共展示了ApiWrapper.issue_api_call方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UrfSummonerCrawler

# 需要导入模块: from api_wrapper import ApiWrapper [as 别名]
# 或者: from api_wrapper.ApiWrapper import issue_api_call [as 别名]

#.........这里部分代码省略.........
            else:
                setattr(self, dat, default)

    def _save_persistance(self):
        for dat, fname, _ in DATS_FILES_AND_DEFAULTS:
            with open(fname, 'wb') as f:
                pickle.dump(getattr(self, dat), f)

    def _insert_row(self, summoner, summ_champion, win):
        self.cur.execute(''' INSERT INTO test_data
                        (summ_id, champ_id, result)
                        VALUES (?, ?, ?)
                    ''', (summoner, summ_champion, win))

    def _extract_summ(self, game):
        summ_team = game['teamId']
        win = game['stats']['win']
        summ_champion = game['championId']
        return (summ_team, win, summ_champion)

    def _extract_fellow(self, fellow):
        fsumm = fellow['summonerId']
        fchamp = fellow['championId']
        fteam = fellow['teamId']
        return (fsumm, fchamp, fteam)

    def crawl(self):
        self.cur = self.conn.cursor()
        print('''
                 Beginning crawl...
                 From previous session (if one existed):
                 Processed games: {}
                 Prcesssed Summoners: {}
                 Summoners left to process: {} (This will grow as execution continues)

              '''.format(len(self.processed_games),
                         len(self.processed_summs),
                         len(self.summoners)))

        while self.summoners and len(self.processed_games) <= MAX_GAMES_TO_PROCESS:
            summoner = self.summoners.popleft()
            if summoner in self.processed_summs:
                # skip if we've looked at summ's recent games already
                continue

            url = self.api.game_by_summoner(summoner)

            recent_games = self.api.api_call(url)['games']
            for game in recent_games:
                game_id = game['gameId']
                # only parse URF games we haven't seen before
                if game['subType'] == 'URF' and game_id not in self.processed_games:
                    summ_team, win, summ_champion = self._extract_summ(game)
                    self._insert_row(summoner, summ_champion, win)

                    # Go through each fellow player
                    # and calculate if they won or lost based on if they
                    # are on the current summoners team.
                    for fellow in game['fellowPlayers']:
                        fsumm, fchamp, fteam = self._extract_fellow(fellow)
                        # Winners are fellows on the summoners team
                        if fteam == summ_team:
                            fwin = win
                        else:
                            fwin = not win

                        self._insert_row(fsumm, fchamp, fwin)
                        # Add the summoner to the list of summoners to process later
                        # because they've probably played more urf games
                        if summoner not in self.processed_summs:
                            self.summoners.append(fsumm)

                    self.processed_games.add(game_id)

                    if len(self.processed_games) % 100 == 0:
                        # Every 100 games, write info to db
                        print('Completed ', str(len(self.processed_games)), 'games')
                        self.conn.commit()
                        self._save_persistance()

            self.processed_summs.add(summoner)

        self.conn.commit()
        self._save_persistance()

    def make_champ_list(self):
        data = self.api.issue_api_call('https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion?dataById=true&champData=info&api_key=%s' % (API_KEY, ))
        cur = self.conn.cursor()
        cur.execute('''CREATE TABLE IF NOT EXISTS champ_data(
                                champ_id integer,
                                name text)
                           ''')
        cur.execute('DELETE FROM champ_data')

        for key, value in data["data"].items():
            cur.execute(''' INSERT INTO champ_data
                            (champ_id, name)
                            VALUES (?, ?)
                        ''', (int(value["id"]), value["name"]))
        self.conn.commit()
开发者ID:Charleezy,项目名称:WinrateForFamiliarChamps,代码行数:104,代码来源:urf_by_summoner.py


注:本文中的api_wrapper.ApiWrapper.issue_api_call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。