def get_puuid_list(self, rank):
        try:
            rank = rank.lower()
        except:
            print("ERROR: Entered rank format is wrong!")
            exit()

        print("Started to collect {} puuids...".format(rank))

        if rank == 'challenger':
            puuid_list = self.get_summoner_puuid(
                RiotAPI.get_tft_challenger(self)["entries"])
        elif rank == 'grandmaster':
            puuid_list = self.get_summoner_puuid(
                RiotAPI.get_tft_grandmaster(self)["entries"])
        elif rank == 'master':
            puuid_list = self.get_summoner_puuid(
                RiotAPI.get_tft_master(self)["entries"])
        else:
            print("ERROR: The puuids of the rank [{}] cannot be pulled".format(
                rank))
            exit()

        file_name = 'tft_{0}_list_{1}_{2}.json'.format(rank, self.region,
                                                       self.date)
        with open(file_name, 'w') as f:
            json.dump(puuid_list, f)
        print("------------------------------")
        print("Retrieved {} {} puuids".format(len(puuid_list), rank))
        print("Stored in {}".format(file_name))
        print("------------------------------")
예제 #2
0
파일: main.py 프로젝트: shuyangw/sum-spy
def debug_suite():
	api = RiotAPI(riot.API["key"])
	ps.setup(api)
	# response_fromid = api.get_stats(SHWANGCAT_ID)


	response = api.get_match_info_by_name("ShwangCat")
	print(ps._tojson_beautify_json(response))		
예제 #3
0
    def get_match_info(self, batch_num=0):
        print("Started to retrieve match in-game data...")
        file_name = 'tft_match_ids_{}_{}'.format(self.region, self.date)
        file_format = '.json'

        if batch_num != 0:
            batch_name = '_batch_{}'.format(batch_num)
            try:
                with open(file_name + batch_name + file_format, 'r') as f:
                    self.matchIds = json.load(f)
            except:
                print("ERROR: Loading batch [{}] matchIds file failed!".format(
                    batch_num))
                return
        else:
            try:
                with open(file_name + file_format, 'r') as f:
                    self.matchIds = json.load(f)
            except:
                print("ERROR: Failed to open the match id file!")
                return

        file_name = 'tft_match_info_{}_{}'.format(self.region, self.date)
        retrival_cnt = 0
        failure_cnt = 0
        self.match_info = []
        for matchId in self.matchIds:
            try:
                match = RiotAPI.get_match_by_matchId(self, matchId)
                self.match_info.append(match['info'])
                retrival_cnt += 1
            except:
                failure_cnt += 1
                continue

            if retrival_cnt % 500 == 0:
                print("[{}]: retrieved: {} matches, failed: {}".format(
                    datetime.now().strftime("%d/%m/%Y-%H:%M:%S"), retrival_cnt,
                    failure_cnt))
                if batch_num != 0:
                    with open('tmp_' + file_name + batch_name + file_format,
                              'w') as f:
                        json.dump(self.match_info, f)
                else:
                    with open('tmp_' + file_name + file_format, 'w') as f:
                        json.dump(self.match_info, f)

        if batch_num != 0:
            with open(file_name + batch_name + file_format, 'w') as f:
                json.dump(self.match_info, f)
        else:
            with open(file_name + file_format, 'w') as f:
                json.dump(self.match_info, f)

        print("------------------------------")
        print("Retrieved {} matches with corresponding in-game data".format(
            retrival_cnt))
        print("Failed to retrieve: {}".format(failure_cnt))
        print("Stored in {}".format(file_name + file_format))
        print("------------------------------")
예제 #4
0
    def get_recent_matchIds(self, match_cnt=20):
        print("Started to retrieve matchIds...")
        file_name = 'tft_match_ids_{}_{}.json'.format(self.region, self.date)
        self.matchIds = set()

        retrival_cnt = 0
        failure_cnt = 0

        for player_id in self.puuid_list:
            try:
                tmp_matchIds = RiotAPI.get_matchId_by_puuid(
                    self, player_id, match_cnt)
                retrival_cnt += 1
            except:
                failure_cnt += 1
                continue
            self.matchIds = self.matchIds.union(set(tmp_matchIds))

            if retrival_cnt % 500 == 0:
                print("[{}]: retrieved: {} players, failed: {}".format(
                    datetime.now().strftime("%d/%m/%Y-%H:%M:%S"), retrival_cnt,
                    failure_cnt))
                with open('tmp_' + file_name, 'w') as f:
                    json.dump(list(self.matchIds), f)

        with open(file_name, 'w') as f:
            json.dump(list(self.matchIds), f)

        print("------------------------------")
        print("Retrieved {} match ids, valid: {}".format(
            retrival_cnt * 20, len(self.matchIds)))
        print("Failed to retrieve: {}".format(failure_cnt * 20))
        print("Stored in {}".format(file_name))
        print("------------------------------")
예제 #5
0
class MatchCrawler(object):
    def __init__(self, api_key, persistence_adapter):
        self.api = RiotAPI(api_key)
        self.db = persistence_adapter

    def _process_participant(self, p):
        try:
            self.db.add_summoner(str(p['player']['summonerId']))
        except KeyError as e:
            print e

    def _process_match(self, match):
        id = str(match['matchId'])
        self.db.add_match(id)

    def crawl(self):
        summoners = self.db.get_summoners()
        matches = self.db.get_matches()

        while(len(summoners) > 0 or len(matches) > 0):
            for s in summoners:
                print('crawling summoner ' + str(s))

                try:
                    ml = self.api.matchlist(s)
                    map(self._process_match, ml['matches'])
                    self.db.crawl_summoner(s, pickle.dumps(ml))
                except RiotAPIException as e:
                    print e

            for m in matches:
                print('crawling match ' + m) 

                try:
                    data = self.api.match(m)
                    map(self._process_participant, data['participantIdentities'])
                    self.db.crawl_match(m, pickle.dumps(data))
                except RiotAPIException as e:
                    print e
                except MatchNotFoundException as e:
                    self.db.crawl_match(m, 'Invalid')
                           

            summoners = self.db.get_summoners()
            matches = self.db.get_matches()
 def get_summoner_puuid(self, player_list):
     puuid_list = []
     for entry in player_list:
         try:
             puuid_list.append(
                 RiotAPI.get_summoner_by_summonerId(
                     self, entry['summonerId'])['puuid'])
         except:
             print("Get puuid failed, one summoner is skipped!")
             continue
     return puuid_list
예제 #7
0
from riotapi import RiotAPI

from postgres_adapter import PostgresAdapter

api_key = 'f009af7e-a9a8-4079-9579-8058dff394ed'

db = PostgresAdapter('dbname=lolstats')


api = RiotAPI(api_key)

champs = api.champion()

for c in champs['data'].keys():
    db.sync_champion(str(champs['data'][c]['id']), str(champs['data'][c]['name']))
예제 #8
0
 def __init__(self, api_key, persistence_adapter):
     self.api = RiotAPI(api_key)
     self.db = persistence_adapter