def main(): try: api = RiotAPI(API_KEY, region="north_america") except NameError as e: print e sys.exit(1) target_api = ["summoner", "by-name"] target_names = { "summonerNames": ["aznchipmunk", "tovrikthethird", "omgnubness", "g0dzspeed"] } try: req = Request(target_api, target_names) get_summoner_response = api.call(req) except Exception as e: print e sys.exit(1) for name in target_names["summonerNames"]: print "{} (id {}):".format(get_summoner_response[name]["name"], get_summoner_response[name]["id"]) target_api = ["league", "by-summoner", "entry"] target_args = {"summonerIds": get_summoner_response[name]["id"]} req = Request(target_api, target_args) try: response = api.call(req) except HTTPError, e: print e sys.exit(1) for item in response[str(get_summoner_response[name]["id"])]: if item["queue"] == "RANKED_SOLO_5x5": try: latest_game = item["entries"][0] print "Most recent match: {}, {} {}, {} LP".format( item["name"], item["tier"], latest_game["division"], latest_game["leaguePoints"]) try: print "In series: {}".format( latest_game["miniSeries"]["progress"]) except: print "Not in series." print "Overall {}W / {}L, {:.2g}%".format( latest_game["wins"], latest_game["losses"], float(100 * latest_game["wins"]) / (latest_game["wins"] + latest_game["losses"])) except: print "No match history found."
def main(): try: api = RiotAPI(API_KEY, region="north_america") except NameError as e: print e sys.exit(1) target_api = ["summoner", "by-name"] target_names = {"summonerNames":["aznchipmunk", "tovrikthethird", "omgnubness", "g0dzspeed"]} try: req = Request(target_api, target_names) get_summoner_response = api.call(req) except Exception as e: print e sys.exit(1) for name in target_names["summonerNames"]: print "{} (id {}):".format(get_summoner_response[name]["name"], get_summoner_response[name]["id"]) target_api = ["league", "by-summoner", "entry"] target_args = {"summonerIds":get_summoner_response[name]["id"]} req = Request(target_api, target_args) try: response = api.call(req) except HTTPError, e: print e sys.exit(1) for item in response[str(get_summoner_response[name]["id"])]: if item["queue"] == "RANKED_SOLO_5x5": try: latest_game = item["entries"][0] print "Most recent match: {}, {} {}, {} LP".format(item["name"], item["tier"], latest_game["division"], latest_game["leaguePoints"]) try: print "In series: {}".format(latest_game["miniSeries"]["progress"]) except: print "Not in series." print "Overall {}W / {}L, {:.2g}%".format( latest_game["wins"], latest_game["losses"], float(100 * latest_game["wins"])/(latest_game["wins"] + latest_game["losses"])) except: print "No match history found."
def main(): for region in REGIONS: try: api_client = RiotAPI(API_KEY, region=region) except NameError as e: print e sys.exit(1) match_req_api = ["match"] for patch in PATCHES: for queueType in QUEUETYPES: input_path = INPUT_PATH_BASE.format(patch=patch, queueType=queueType, region=region) with open(input_path, 'r') as fp: input_matches = json.load(fp) total_count = len(input_matches) batch_count = total_count / MATCHES_PER_FILE print "{} input matches".format(len(input_matches)) print "with {} matches per file, there will be {} batches".format(MATCHES_PER_FILE, batch_count) for fileindex in range(batch_count): combined_resp = {} for sequence in range(MATCHES_PER_FILE): match_index = (fileindex * MATCHES_PER_FILE) + sequence match_id = "{}".format(input_matches[match_index]) print "calling match api on id {}".format(match_id) match_req_ids = {"matchId": match_id, "includeTimeline": "true"} req = Request(match_req_api, match_req_ids) try: resp = api_client.call(req) except Exception as e: print e sys.exit(1) combined_resp["sequence{}".format(sequence)] = resp output_path = OUTPUT_PATH_BASE.format(patch=patch, queueType=queueType, region=region, filepatch=patch.replace(".", ""), filequeue=QUEUETYPES[queueType], fileregion=region.lower(), fileindex=fileindex) print "dumping to {}".format(output_path) with open(output_path, 'w') as fp: json.dump(combined_resp, fp) print "done" sys.exit(0)
ITEM_BUILD_PATH_TABLE = {} for patch in PATCHES: ITEM_BUILD_PATH_TABLE[patch] = {} try: api_client = RiotAPI(API_KEY, region="NA") except NameError as e: print e sys.exit(1) item_req_api = ["lol-static-data", "item"] item_req_params = {"version":"{}.1".format(patch), "itemListData":["from", "into"]} req = Request(item_req_api, item_req_params) resp = api_client.call(req) # build base table for itemId in resp["data"]: ITEM_BUILD_PATH_TABLE[patch][itemId] = {} ITEM_BUILD_PATH_TABLE[patch][itemId]["id"] = itemId ITEM_BUILD_PATH_TABLE[patch][itemId]["name"] = resp["data"][itemId]["name"] if "from" in resp["data"][itemId]: ITEM_BUILD_PATH_TABLE[patch][itemId]["from"] = resp["data"][itemId]["from"] else: ITEM_BUILD_PATH_TABLE[patch][itemId]["from"] = [] if "into" in resp["data"][itemId]: ITEM_BUILD_PATH_TABLE[patch][itemId]["into"] = resp["data"][itemId]["into"] else: ITEM_BUILD_PATH_TABLE[patch][itemId]["into"] = []
def main(): for region in REGIONS: try: api = RiotAPI(API_KEY, region=region) except NameError as e: print e sys.exit(1) for patch in PATCHES: check_path = INPUT_PATH_BASE.format(patch=patch, region=region, filepatch=patch.replace( ".", ""), fileregion=region.lower(), fileindex="0") if not os.path.isfile(check_path): print "no such path, skipping ({})".format(check_path) continue for fileindex in range(TOTAL_MATCH_FILES_PER_PATCH): input_path = INPUT_PATH_BASE.format(patch=patch, region=region, filepatch=patch.replace( ".", ""), fileregion=region.lower(), fileindex=fileindex) print "reading from " + input_path with open(input_path, 'r') as fp: match_data = json.load(fp) for sequence in range(MATCHES_PER_FILE): sequence_field = "sequence{}".format(sequence) current_ids = [] for participantId in match_data[sequence_field][ "participantIdentities"]: current_ids.append("{}".format( participantId["player"]["summonerId"])) league_req_api = ["league", "by-summoner", "entry"] league_req_ids = {"summonerIds": current_ids} req = Request(league_req_api, league_req_ids) try: resp = api.call(req) ''' NOTE: a 404 indicates that the player is UNRANKED. However when requesting with 10 summonerIDs at once, they just don't return any response for that ID ''' except Exception as e: print e sys.exit(1) result = {} for player_idx in range(PLAYERS_PER_MATCH): if current_ids[player_idx] in resp: result[current_ids[ player_idx]] = convertRankToRawPoints( resp[current_ids[player_idx]][0] ["tier"], resp[current_ids[player_idx]] [0]["entries"][0]["division"]) else: result[current_ids[ player_idx]] = convertRankToRawPoints( "UNRANKED") ''' by default integers will evaluate division to the lower value e.g. 6/5 = 1 so we will convert to float and use the ceil of the result this means that matches on the edge such as GOLD I vs PLAT V will side towards being marked as PLAT V ''' avg = 0 for key, value in result.items(): avg += value rounded_avg = int( math.ceil(float(avg) / float(PLAYERS_PER_MATCH))) addMatch(match_data[sequence_field], convertRawPointsToRank(rounded_avg), patch, region) flushFinalMatches(patch, region) print "done" sys.exit(0)