Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zgovani committed Oct 13, 2017
1 parent eda026f commit 644cbc9
Show file tree
Hide file tree
Showing 5 changed files with 337 additions and 0 deletions.
59 changes: 59 additions & 0 deletions accountIdCrawler.py
@@ -0,0 +1,59 @@
import requests
from requests.auth import HTTPDigestAuth
import json
import time
# API Script 1
accountIdsFile = open("accountIdsFile.txt", "w")
api_key = "?api_key=RGAPI-d6b5fbf4-fd1b-48fc-a7b4-3d33a8727f20"
crawl_start_basic = "MLGB Blade"
crawl_ids = set()
already_crawled = set()
currentId = ""
gameIdList = []
count = 1


url = 'https://na1.api.riotgames.com/lol/summoner/v3/summoners/by-name/' + crawl_start_basic + api_key
myResponse = requests.get(url)
if(myResponse.ok):
jData = myResponse.json()
crawl_ids.add(str(jData["accountId"]))
currentId = str(jData["accountId"])
print("Id found", currentId)
else:
print("response not found")

already_crawled.add(currentId)
while len(crawl_ids):
try:
if count % 100 == 0:
time.sleep(122)
url = 'https://na1.api.riotgames.com/lol/match/v3/matchlists/by-account/' + str(currentId) + api_key
count += 1
myResponse = requests.get(url)
if(myResponse.ok):
jData = myResponse.json()
for match in jData["matches"]:
gameIdList += [str(match["gameId"])]
else:
print("matches not found")
for gameId in gameIdList:
url = 'https://na1.api.riotgames.com/lol/match/v3/matches/' + str(gameId) + api_key
count += 1
if count % 100 == 0:
time.sleep(122)
myResponse = requests.get(url)
if(myResponse.ok):
jData = myResponse.json()
for participantIdentityDto in jData["participantIdentities"]:
crawl_ids.add(str(participantIdentityDto["player"]["accountId"]))
print(len(crawl_ids))
else:
print("match data not found")
currentId = crawl_ids.difference(already_crawled).pop()
already_crawled.add(currentId)
crawl_ids = crawl_ids.union(already_crawled)
gameIdList = []
except KeyboardInterrupt:
break
accountIdsFile.write(str(crawl_ids))
2 changes: 2 additions & 0 deletions basicPython.py
@@ -0,0 +1,2 @@
for i in range(0, 100):
print(i)
123 changes: 123 additions & 0 deletions dataAggregate.py
@@ -0,0 +1,123 @@
import requests
from requests.auth import HTTPDigestAuth
import json
import time

baseData = ["MLGB Blade", "Liquid Mickey", "Danskvand", "Licorice", "Pobelter", "eLLi nOISE", "Imaqtpie", "Gaston", "Linsanity", "MLGB Clown", "Jòéy", "dawolfsfang", "19950307", "She Limp", "Jurassiq", "SpaghettiBud9", "C9 Gun", "Pants are Dragon", "hi its viper", "Rikara", "Somin", "Wiggily", "iWeixin VinLeous", "Kingslayer Sheep", "Ablazeolive", "Humble Diligent", "Acoldblazeolive", "Fanatiik", "Bobjenkins", "Hungry Like", "GangstahSwerve", "W0WFIXZ", "FallenBandit", "Apdo dogjj", "C9 Sneaky", "Arceent Censer", "big brain gamer", "Oddiee", "Morïarty", "Falcon God", "SoloQ Antihero", "Little Baiano", "Vulcan1", "RyuShoryu", "Eitori", "enaek", "Kazahana", "Jayms", "salt on bench", "Oneself", "Daarr", "Revenge", "LittleFrosty", "TLB Tarzaned", "Scrandor", "Win or Learn", "NintendudeX", "Midnight Train", "i need some suga", "Ash", "Sophist Sage", "C9 Smoothie", "Piggy Kitten", "feedlancer", "Jue Viole Grace", "Tuesdayy", "Value", "Iron Pyrite", "CLA Tuesday", "Ild i piben", "ybooks", "Kitty Ears", "Akaadian4", "Julien", "Ssita", "Winter", "NoahMost", "League", "Rohammers", "Chapanya", "MRTONERBONER", "Phaxen", "Implicit", "NaGeNanHai", "Berta Lovejoy", "fragas1", "5word", "Autolycus1", "SleepyzLOL", "Ivan Pavlov", "WildTurtle", "Rodov", "Lebron James", "CHIEF KEITH", "717J", "Chubakaaa", "LHHS", "WorthyOfLohpally", "Myloo", "Flaresz"]

baseData2 = ["WildTurtle", "Chimonaa1", "Maxtrobo", "I Love Cindy Fu", "Pennie", "kWeixin Vinleous", "Jako5000", "never loses", "Rich Homie Jayms", "19981015", "Erry", "Johnson", "Descraton", "Allorim", "XueGao", "PunOko", "bugslife", "yeedam", "Slash", "1onz", "dun is washed up", "GL IM ZWAG", "5fire", "Brother Dyrus", "FlyQ Hai", "828", "Pransie", "DopaSenKer", "MLGB Blade", "be small", "Easley", "Yassuo", "Dubehavior", "Dhokla", "goldenglue", "Tawnington", "MrPresidentObama", "cackdeus", "t d", "Hakuho", "KitKatxz", "Teamfighting", "joong ki song", "Strompest LFT", "Huhi", "baia baia", "Paid By Steve", "Peridot", "And July", "mvsh", "fwii", "TLB Adrian Riven", "717 J", "4994", "Qissaruj", "Ew Michelle", "Anivia Kid", "Grow Gaiy", "Doubtfull", "FateFalls", "Baekk", "Faith in Myself", "Fas the Magi", "Grigne", "rhubarbs", "Prismal", "shabudaba", "Kostyantyn", "Manifest", "CaillouX", "mnesty247", "1 baron", "Ahigholive", "Weeknd", "Osama", "Yur1 Boyka", "Liquid Lourlo", "BukZacH", "rovex2", "watercold", "Legend Never Die", "MLGB Grae", "Jia", "always plan ahea", "Achilles Heal", "FOX Brandini", "SandPaperX", "N For New York", "ChaoZxl", "insanity", "Pocket Rhino", "we gg na", "245 979", "highimpactplayer", "1T 1T 1T 1T 1T", "MLGB Blade"]

accountIds = ""
api_key = "?api_key=RGAPI-210f1e27-46d3-41b9-a5e9-907d79fdeb85"

# # API Script 1
# count = 0
# text_file = open("accountIds.txt", "w")
# for summoner in baseData2:
# count += 1
# print(count)
# if count % 100 == 0:
# time.sleep(122)
# url = 'https://na1.api.riotgames.com/lol/summoner/v3/summoners/by-name/' + summoner + api_key
# myResponse = requests.get(url)
# if(myResponse.ok):
# jData = myResponse.json()
# accountIds += str(jData["accountId"]) + " "
# else:
# print(summoner, "response not found")
# text_file.write(accountIds)
# text_file.close()


# # API Script 2
# with open('accountIds.txt', 'r') as myfile:
# data = myfile.read()
# myfile.close()
# game_file = open("gamesByUser.txt", "w")
#
# userGames = ""
# count = 0
# for accountId in data.split():
# count += 1
# print(count)
# if count % 100 == 0:
# time.sleep(122)
# url = 'https://na1.api.riotgames.com/lol/match/v3/matchlists/by-account/' + str(accountId) + api_key
# myResponse = requests.get(url)
# if(myResponse.ok):
# jData = myResponse.json()
# for match in jData["matches"]:
# userGames += str(match["gameId"]) + " "
# else:
# print(accountId, "matches not found")
# game_file.write(userGames)
# game_file.close()

# API Script 3
with open('heroStaticData.txt', 'r') as myfile:
data2 = myfile.read()
myfile.close()
j = json.loads(data2)

heroFrequency = {}
idToHero = {}
preHeroes = {}
for hero in j["data"]:
heroName = str(j["data"][hero]["name"])
heroId = str(j["data"][hero]["id"])
heroFrequency[heroId] = 0
idToHero[heroId] = heroName
preHeroes[heroName] = heroId

sortedHeroes = [value for (key, value) in sorted(preHeroes.items())]

heroes = {}
arrayIndex = 0
for heroID in sortedHeroes:
heroes[heroID] = arrayIndex
arrayIndex += 1

# API Script 4
with open('gamesByUser.txt', 'r') as myfile:
data2 = myfile.read()
myfile.close()
game_file = open("formattedDataset2.txt", "w")

enter = 0
count = 0
for gameid in data2.split():
url = 'https://na1.api.riotgames.com/lol/match/v3/matches/' + str(gameid) + api_key
count += 1
print(count)
if count % 100 == 0:
time.sleep(122)
myResponse = requests.get(url)
if(myResponse.ok):
didTeamWin = {}
output = [0] * 277
jData = myResponse.json()
team2 = ""
for team in jData["teams"]:
team2 = team["teamId"]
if 'win' in team:
didTeamWin[str(team["teamId"])] = team["win"]
for participantDto in jData["participants"]:
if participantDto["teamId"] != team2:
heroId = str(participantDto["championId"])
heroFrequency[heroId] += 1
heroIndex = heroes[heroId]
output[heroIndex] = 1
else:
heroId = str(participantDto["championId"])
heroFrequency[heroId] += 1
heroIndex = heroes[heroId] + 134
output[heroIndex] = 1
if output.count(1) == 10:
if didTeamWin["100"] == "Win":
output[len(output) - 1] = 1
game_file.write(str(output) + "\n")
else:
print(gameid, "matches not found")
game_file.close()
for heroId in idToHero:
print(idToHero[heroId] + " with count: " + str(heroFrequency[heroId]))
117 changes: 117 additions & 0 deletions datasetAggregateFinal.py
@@ -0,0 +1,117 @@
import requests
from requests.auth import HTTPDigestAuth
import json
import time
import re

rawData = ""
with open('gameIdsFile.txt', 'r') as myfile:
rawData = myfile.read()
myfile.close()
rawData = ''.join('' if c is " " or c is "\'" or c is "{" or c is "}" or c is "\n" else c for c in rawData)
gameIds = re.split(",", rawData)
api_key = "?api_key=RGAPI-882663d5-50f5-4ecc-9c88-8fe7f1754efb"
crawl_ids = set()
currentId = ""
count = 1
lanes = {"TOP" : 0, "BOTTOM" : 1, "MIDDLE" : 2, "JUNGLE" : 3}
spells = {"1" : 0, "3" : 1, "4" : 2 ,"6" : 3,"7" : 4,"11" : 5,"12" : 6,"13" : 7,"14" : 8,"21" : 9}


with open('heroStaticData.txt', 'r') as myfile:
data2 = myfile.read()
myfile.close()
j = json.loads(data2)

heroFrequency = {}
idToHero = {}
preHeroes = {}
for hero in j["data"]:
heroName = str(j["data"][hero]["name"])
heroId = str(j["data"][hero]["id"])
heroFrequency[heroId] = 0
idToHero[heroId] = heroName
preHeroes[heroName] = heroId

sortedHeroes = [value for (key, value) in sorted(preHeroes.items())]

heroes = {}
arrayIndex = 0
for heroID in sortedHeroes:
heroes[heroID] = arrayIndex
arrayIndex += 1

count = 0
tensors = []
dataset = open("dataset.txt", "w")
print(heroes)

for gameid in gameIds:
try:
url = 'https://na1.api.riotgames.com/lol/match/v3/matches/' + str(gameid) + api_key
count += 1
print(count)
if count % 100 == 0:
time.sleep(122)
myResponse = requests.get(url)
if(myResponse.ok):
jData = myResponse.json()
t1 = []
t2 = []
tensor = []
for team in jData["teams"]:
team2 = team["teamId"]
for participantDto in jData["participants"]:
if participantDto["teamId"] != team2:
t1.append(participantDto)
else:
t2.append(participantDto)
for participantDto in t1:
tensor.append(lanes[participantDto["timeline"]["lane"]])
tensor.append(heroes[str(participantDto["championId"])])
tensor.append(spells[str(participantDto["spell1Id"])])
tensor.append(spells[str(participantDto["spell2Id"])])
for participantDto in t2:
tensor.append(lanes[participantDto["timeline"]["lane"]])
tensor.append(heroes[str(participantDto["championId"])])
tensor.append(spells[str(participantDto["spell1Id"])])
tensor.append(spells[str(participantDto["spell2Id"])])
team1 = jData["teams"][0]
team2 = jData["teams"][1]
if team1["firstDragon"]:
tensor.append(0)
else:
tensor.append(1)
if team1["firstInhibitor"]:
tensor.append(0)
else:
tensor.append(1)
if team1["firstRiftHerald"]:
tensor.append(0)
else:
tensor.append(1)
if team1["firstBaron"]:
tensor.append(0)
else:
tensor.append(1)
if team1["firstBlood"]:
tensor.append(0)
else:
tensor.append(1)
if team1["firstTower"]:
tensor.append(0)
else:
tensor.append(1)
tensor.append(team1["baronKills"] - team2["baronKills"])
tensor.append(team1["riftHeraldKills"] - team2["riftHeraldKills"])
tensor.append(team1["vilemawKills"] - team2["vilemawKills"])
tensor.append(team1["inhibitorKills"] - team2["inhibitorKills"])
tensor.append(team1["towerKills"] - team2["towerKills"])
tensors.append(tensor)
else:
print(gameid, "matches not found")
except KeyboardInterrupt:
break
except KeyError:
print("keyerror")
dataset.write(str(tensors))
36 changes: 36 additions & 0 deletions gameIdCrawler.py
@@ -0,0 +1,36 @@
import requests
from requests.auth import HTTPDigestAuth
import json
import time
import re


rawData = ""
with open('accountIdsFile.txt', 'r') as myfile:
rawData = myfile.read()
myfile.close()
rawData = ''.join('' if c is " " or c is "\'" or c is "{" or c is "}" or c is "\n" else c for c in rawData)
accountIds = re.split(",", rawData)
api_key = "?api_key=RGAPI-d6b5fbf4-fd1b-48fc-a7b4-3d33a8727f20"
crawl_ids = set()
currentId = ""
count = 1

gameIdsFile = open("gameIdsFile.txt", "w")
for accountId in accountIds:
try:
if count % 100 == 0:
time.sleep(122)
url = 'https://na1.api.riotgames.com/lol/match/v3/matchlists/by-account/' + str(accountId) + api_key
count += 1
myResponse = requests.get(url)
if(myResponse.ok):
jData = myResponse.json()
for match in jData["matches"]:
crawl_ids.add(str(match["gameId"]))
print(len(crawl_ids))
else:
print("matches not found")
except KeyboardInterrupt:
break
gameIdsFile.write(str(crawl_ids))

0 comments on commit 644cbc9

Please sign in to comment.