Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 17:27

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Sample] LoL Riot API with AutoIT

Discussion on [Sample] LoL Riot API with AutoIT within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1


 
buFFy!'s Avatar
 
elite*gold: 1826
Join Date: Mar 2009
Posts: 4,314
Received Thanks: 6,262
Arrow [Sample] LoL Riot API with AutoIT

So i was kinda bored and all i have at work is AutoIT so i wrote a messy wrapper for the Riot API.

Code:
Global Const $V_SUMMONER = "v1.4/summoner/"
Global Const $V_LEAGUE = "v2.4/league/"

Func CreateAPIObject($region, $key)
	Dim $ret = ["https://" & $region & ".api.pvp.net/api/lol/" & $region & "/", $key]
	Return $ret
EndFunc   ;==>CreateAPIObject

Func CleanReturn($s)
	Return StringRegExpReplace($s, '[{}"]', "")
EndFunc   ;==>CleanReturn

Func GetSummonerByName($oAPI, $sSummonerName)
	Local Const $sURL = $oAPI[0] & $V_SUMMONER & "by-name/" & $sSummonerName & "?api_key=" & $oAPI[1]
	;Return CleanReturn(BinaryToString(InetRead($sURL)))
	Return StringSplit(CleanReturn(BinaryToString(InetRead($sURL))), ",")
EndFunc   ;==>GetSummonerByName

Func GetSummonerIdBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[1], ":")[3]
EndFunc   ;==>GetSummonerIdBySummoner

Func GetSummonerNameBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[2], ":")[2]
EndFunc   ;==>GetSummonerNameBySummoner

Func GetSummonerIconBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[3], ":")[2]
EndFunc   ;==>GetSummonerIconBySummoner

Func GetSummonerLevelBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[4], ":")[2]
EndFunc   ;==>GetSummonerLevelBySummoner

Func GetLeaguesBySummonerId($oAPI, $summonerId)
	Local Const $sURL = $oAPI[0] & $V_LEAGUE & "by-summoner/" & $summonerId & "?api_key=" & $oAPI[1]
	Return StringSplit(CleanReturn(BinaryToString(InetRead($sURL))), ',')
EndFunc   ;==>GetLeaguesBySummonerId

Func GetSummonerRankingInLeague($aLeagues, $summonerId, $sLeague = "RANKED_SOLO_5x5")
	If Not IsArray($aLeagues) Then Return "N/A"
	Local $sRanking = ""
	Local $found = 0

	For $i = 0 To $aLeagues[0]
		$found = StringInStr($aLeagues[$i], $sLeague)
		If $found Then
			$sRanking &= StringSplit($aLeagues[$i - 1], ":")[2] & " "
			ExitLoop
		EndIf
	Next

	If Not $found Then Return "N/A"

	For $i = 0 To $aLeagues[0]
		If StringInStr($aLeagues[$i], $summonerId, 0, 1, $found) Then
			$sRanking &= StringSplit($aLeagues[$i + 2], ":")[2]
			ExitLoop
		EndIf
	Next

	Return $sRanking

EndFunc   ;==>GetSummonerRankingInLeague

$oAPI = CreateAPIObject("euw", "7ca3259a-302a-49c7-95d8-censored")
$mySummoner = GetSummonerByName($oAPI, "Saintwitch")
$mySummonerId = GetSummonerIdBySummoner($mySummoner)
$mySummonerName = GetSummonerNameBySummoner($mySummoner)
$mySummonerLevel = GetSummonerLevelBySummoner($mySummoner)

$myLeagues = GetLeaguesBySummonerId($oAPI, $mySummonerId)
$myRanking = GetSummonerRankingInLeague($myLeagues, $mySummonerId)

ConsoleWrite("Name: " & $mySummonerName & @CRLF)
ConsoleWrite("Level: " & $mySummonerLevel & @CRLF)
ConsoleWrite("Id: " & $mySummonerId & @CRLF)
ConsoleWrite("Elo: " & $myRanking & @CRLF)
Output:
Code:
Name: Saintwitch
Level: 30
Id: 24685246
Elo: DIAMOND V
It's obivously better to use proper json parsing and GET (does inetread do that? i think so).
Whatever - feel free to extend it!

greetz, buFFy
buFFy! is offline  
Thanks
3 Users
Old 07/22/2014, 22:55   #2


 
Lawliet's Avatar
 
elite*gold: 2
Join Date: Jul 2009
Posts: 14,456
Received Thanks: 4,685
#moved
Lawliet is offline  
Old 12/07/2018, 23:04   #3
 
elite*gold: 0
Join Date: Oct 2018
Posts: 110
Received Thanks: 13
Quote:
Originally Posted by buFFy! View Post
So i was kinda bored and all i have at work is AutoIT so i wrote a messy wrapper for the Riot API.

Code:
Global Const $V_SUMMONER = "v1.4/summoner/"
Global Const $V_LEAGUE = "v2.4/league/"

Func CreateAPIObject($region, $key)
	Dim $ret = ["https://" & $region & ".api.pvp.net/api/lol/" & $region & "/", $key]
	Return $ret
EndFunc   ;==>CreateAPIObject

Func CleanReturn($s)
	Return StringRegExpReplace($s, '[{}"]', "")
EndFunc   ;==>CleanReturn

Func GetSummonerByName($oAPI, $sSummonerName)
	Local Const $sURL = $oAPI[0] & $V_SUMMONER & "by-name/" & $sSummonerName & "?api_key=" & $oAPI[1]
	;Return CleanReturn(BinaryToString(InetRead($sURL)))
	Return StringSplit(CleanReturn(BinaryToString(InetRead($sURL))), ",")
EndFunc   ;==>GetSummonerByName

Func GetSummonerIdBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[1], ":")[3]
EndFunc   ;==>GetSummonerIdBySummoner

Func GetSummonerNameBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[2], ":")[2]
EndFunc   ;==>GetSummonerNameBySummoner

Func GetSummonerIconBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[3], ":")[2]
EndFunc   ;==>GetSummonerIconBySummoner

Func GetSummonerLevelBySummoner($summoner)
	If Not IsArray($summoner) Then Return -1
	Return StringSplit($summoner[4], ":")[2]
EndFunc   ;==>GetSummonerLevelBySummoner

Func GetLeaguesBySummonerId($oAPI, $summonerId)
	Local Const $sURL = $oAPI[0] & $V_LEAGUE & "by-summoner/" & $summonerId & "?api_key=" & $oAPI[1]
	Return StringSplit(CleanReturn(BinaryToString(InetRead($sURL))), ',')
EndFunc   ;==>GetLeaguesBySummonerId

Func GetSummonerRankingInLeague($aLeagues, $summonerId, $sLeague = "RANKED_SOLO_5x5")
	If Not IsArray($aLeagues) Then Return "N/A"
	Local $sRanking = ""
	Local $found = 0

	For $i = 0 To $aLeagues[0]
		$found = StringInStr($aLeagues[$i], $sLeague)
		If $found Then
			$sRanking &= StringSplit($aLeagues[$i - 1], ":")[2] & " "
			ExitLoop
		EndIf
	Next

	If Not $found Then Return "N/A"

	For $i = 0 To $aLeagues[0]
		If StringInStr($aLeagues[$i], $summonerId, 0, 1, $found) Then
			$sRanking &= StringSplit($aLeagues[$i + 2], ":")[2]
			ExitLoop
		EndIf
	Next

	Return $sRanking

EndFunc   ;==>GetSummonerRankingInLeague

$oAPI = CreateAPIObject("euw", "7ca3259a-302a-49c7-95d8-censored")
$mySummoner = GetSummonerByName($oAPI, "Saintwitch")
$mySummonerId = GetSummonerIdBySummoner($mySummoner)
$mySummonerName = GetSummonerNameBySummoner($mySummoner)
$mySummonerLevel = GetSummonerLevelBySummoner($mySummoner)

$myLeagues = GetLeaguesBySummonerId($oAPI, $mySummonerId)
$myRanking = GetSummonerRankingInLeague($myLeagues, $mySummonerId)

ConsoleWrite("Name: " & $mySummonerName & @CRLF)
ConsoleWrite("Level: " & $mySummonerLevel & @CRLF)
ConsoleWrite("Id: " & $mySummonerId & @CRLF)
ConsoleWrite("Elo: " & $myRanking & @CRLF)
Output:
Code:
Name: Saintwitch
Level: 30
Id: 24685246
Elo: DIAMOND V
It's obivously better to use proper json parsing and GET (does inetread do that? i think so).
Whatever - feel free to extend it!

greetz, buFFy
Hey, this doesn't seem to be working anymore...

Do you have an up to date version ?
Sillyre is offline  
Reply




All times are GMT +1. The time now is 17:27.


Powered by vBulletin®
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2023 elitepvpers All Rights Reserved.