async def rlstats(self, steamidinput): """Retrieves Rocekt League Statistics from rocketleaguestats.com using their API""" rocket = RocketLeague(api_key='ZEP7NZ0WLD9AFJ8WU15JZU5XD1XKM3TO') steamid = str(steamidinput) response = rocket.players.player(id=steamid, platform=1) signatureUrl = response.json()['signatureUrl'] await self.bot.say(signatureUrl)
def checker_stats(text): """распознавание рангов пользователя""" # массив возможных рангов Ranks = [ 'Unranked', 'Bronze I', 'Bronze II', 'Bronze III', 'Silver I', 'Silver II', 'Silver III', 'Gold I', 'Gold II', 'Gold III', 'Platinum I', 'Platinum II', 'Platinum III', 'Diamond I', 'Diamond II', 'Diamond III', 'Champion I', 'Champion II', 'Champion III', 'Grand Champion' ] # получаем ссылку и пускаем через обработчик url = steam_url(text) rocket = RocketLeague(api_key=RLApi_token) # получаем инфу об игроке в json файлике info = rocket.players.player(id=url, platform=1).json() # достаём всё что нужно ranked_seasons = info['rankedSeasons'] currentSeason = ranked_seasons[max(ranked_seasons)] # 1c, 2c, 3cc, 3c duelRank = Ranks[currentSeason['10']['tier']] + '({})'.format( currentSeason['10']['rankPoints']) doubleRank = Ranks[currentSeason['11']['tier']] + '({})'.format( currentSeason['11']['rankPoints']) soloStandartRank = Ranks[currentSeason['12']['tier']] + '({})'.format( currentSeason['12']['rankPoints']) StandartRank = Ranks[currentSeason['13']['tier']] + '({})'.format( currentSeason['13']['rankPoints']) return duelRank, doubleRank, soloStandartRank, StandartRank
def getrank(self, platform, gamertag): """Retrieves Rocket League Stats image from rocketleaguestats.com using their API sends image back""" apikey = self.parsejson(self.apikey)[1] #call the API key from json file rocket = RocketLeague(api_key=apikey) platformlegend = {'pc' : 1, 'ps4' : 2, 'xbox' : 3} for k,v in platformlegend.items(): #using the platform legend, find the platform ID if platform == k: platformid = v break try: platformid except NameError: return "getrank NameError - ask an admin" else: try: playerdata = rocket.players.player(id=gamertag, platform=platformid) #use the gamertag and platform ID to find the json formatted player data except rls.exceptions.ResourceNotFound: error = "Fail. There was an issue finding your gamertag in the <http://rocketleaguestats.com/> database." return error else: rank = playerdata.json()['rankedSeasons'] with open(self.json, "w") as f: #save the json to a file for later (might not need to do this) json.dump(playerdata.json(), f) opener=urllib.request.build_opener() #download and save the rocket league signature image opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1941.0 Safari/537.36')] urllib.request.install_opener(opener) urllib.request.urlretrieve(playerdata.json()['signatureUrl'], self.image) if "displayName" in playerdata.json(): return rank elif "code" in playerdata.json(): error = "Fail. Error: " + playerdata.json()['code'] + ". " + playerdata.json()['message'] return error else: return "Fail. Not sure how we got here."
def checkRocketID(platform1, id1, returnFull=False): if(not platform1): return False if(platform1=="1" and str(steam.SteamID(id1)) != id1): #Check if id was inputted as custom url testID = steam.steamid.steam64_from_url("http://steamcommunity.com/id/"+id1) if(testID): id1 = testID else: testID = steam.steamid.steam64_from_url(id1) if(testID): id1 = testID #Use the RL api to check if the ID exists try: rl = RocketLeague(api_key='3PE3QPQJDC6RTQOEI76ALAAW3KO6GI9F') response = rl.players.player(id=id1, platform=platform1) if returnFull: return response.json() else: return id1 except Exception as e: #Check if not found, raise if any other error occours if(str(type(e))=="<class 'rls.exceptions.ResourceNotFound'>"): return False else: raise e
import json from rls.rocket import RocketLeague key = 'KITT7IJON8TT7XAEABU1PF8DJZ2GDIMH' rocket = RocketLeague(api_key=key) response = rocket.players.player(id='76561198064487811', platform=1) print(json.dumps(response.json(), indent=4))
def handleButton(self): key = 'KITT7IJON8TT7XAEABU1PF8DJZ2GDIMH' rocket = RocketLeague(api_key=key) response = rocket.players.player(id='76561198064487811', platform=1) responseJson = response.json() print(json.dumps(responseJson, indent=4))
def test_rocket(): rocket = RocketLeague(API_KEY) response = rocket.players.player(id='76561198079681869', platform=1) assert response.status_code == 200
def test_rocket_missing_api(): rocket = RocketLeague(API_KEY) with pytest.raises(ConfigError) as exc: rocket.fake.fake() assert str(exc.value) == "Configuration not available in api_map for this call"
def test_rocket_missing_params(): rocket = RocketLeague(API_KEY) with pytest.raises(MissingParam) as exc: rocket.players.player(id='76561198079681869') assert str(exc.value) == "Missing 'platform' parameter"