In [40]:
import json
import numpy as np
from pprint import pprint
from urllib.request import urlopen
target_url = 'https://api.smash.gg/phase_group/343547?expand[]=sets'
#target_url = 'https://api.smash.gg/tournament/beast-7-1?expand[]=phase&expand[]=groups&expand[]=event'
fname = 'beast7_tournament'
munge_text = True
path = 'json_data/'
ftag = '.json'
file = open( path+fname+ftag,'w')
for line in urlopen(target_url):
if munge_text == True:
text = str(line)
print(text[0:2], text[-1])
newtext = text[2:-1]
print(newtext[0:3], newtext[-3:])
else:
newtext = str(line)
file.write( newtext )
pprint(newtext)
b' '
{"e []}
('{"entities":{"groups":{"id":343547,"phaseId":118402,"waveId":15531,"poolRefId":null,"groupTypeId":3,"title":null,"identifier":"7","displayIdentifier":"C61","state":3,"tiebreakOrder":null,"tiebreaks":null,"bestOf":null,"setsOnDeck":3,"rematchSeconds":0,"finalized":true,"winnersTargetPhaseId":118403,"numProgressing":2,"losersTargetPhaseId":null,"startAt":1487426400,"startedAt":null,"seeds":[],"sets":[],"rounds":[],"numRounds":null,"pointsPerMatchWin":null,"pointsPerGameWin":0,"pointsPerBye":null,"matchmakingEnabled":false,"scheduleId":131046,"stationId":35263,"expand":["sets"],"hasSets":true,"hasCustomWinnerByes":false},"sets":[{"id":7509402,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":355398,"entrant2Id":429536,"winnerId":355398,"loserId":429536,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4840968,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4841000,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"A","round":1,"state":3,"entrant1Score":0,"entrant2Score":-1,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427537,"updatedAtMicro":1487427537.0527,"startAt":null,"startedAt":1487427533,"completedAt":1487427537,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":1,"originalRound":1,"fullRoundText":"Round '
'1","midRoundText":"Round '
'1","shortRoundText":"R1","roundDivision":null},{"id":7509403,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":402500,"entrant2Id":388743,"winnerId":402500,"loserId":388743,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4840989,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840980,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"B","round":1,"state":3,"entrant1Score":0,"entrant2Score":-1,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427519,"updatedAtMicro":1487427519.193,"startAt":null,"startedAt":1487427516,"completedAt":1487427519,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":1,"originalRound":1,"fullRoundText":"Round '
'1","midRoundText":"Round '
'1","shortRoundText":"R1","roundDivision":null},{"id":7509404,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":439067,"entrant2Id":429536,"winnerId":439067,"loserId":429536,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4841002,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4841000,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"C","round":2,"state":3,"entrant1Score":0,"entrant2Score":-1,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427530,"updatedAtMicro":1487427530.3011,"startAt":null,"startedAt":1487427528,"completedAt":1487427530,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":2,"originalRound":2,"fullRoundText":"Round '
'2","midRoundText":"Round '
'2","shortRoundText":"R2","roundDivision":null},{"id":7509405,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":355398,"entrant2Id":402500,"winnerId":355398,"loserId":402500,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4840968,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840989,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"D","round":2,"state":3,"entrant1Score":2,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427728,"updatedAtMicro":1487427728.242,"startAt":null,"startedAt":1487427725,"completedAt":1487427728,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":2,"originalRound":2,"fullRoundText":"Round '
'2","midRoundText":"Round '
'2","shortRoundText":"R2","roundDivision":null},{"id":7509406,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":439067,"entrant2Id":388743,"winnerId":439067,"loserId":388743,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4841002,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840980,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"E","round":3,"state":3,"entrant1Score":0,"entrant2Score":-1,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427506,"updatedAtMicro":1487427505.668,"startAt":null,"startedAt":1487427503,"completedAt":1487427505,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":3,"originalRound":3,"fullRoundText":"Round '
'3","midRoundText":"Round '
'3","shortRoundText":"R3","roundDivision":null},{"id":7509407,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":429536,"entrant2Id":402500,"winnerId":402500,"loserId":429536,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4841000,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840989,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"F","round":3,"state":3,"entrant1Score":-1,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427583,"updatedAtMicro":1487427583.3949,"startAt":null,"startedAt":1487427551,"completedAt":1487427583,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":3,"originalRound":3,"fullRoundText":"Round '
'3","midRoundText":"Round '
'3","shortRoundText":"R3","roundDivision":null},{"id":7509408,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":439067,"entrant2Id":402500,"winnerId":439067,"loserId":402500,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4841002,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840989,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"G","round":4,"state":3,"entrant1Score":2,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427718,"updatedAtMicro":1487427717.9574,"startAt":null,"startedAt":1487427715,"completedAt":1487427717,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":4,"originalRound":4,"fullRoundText":"Round '
'4","midRoundText":"Round '
'4","shortRoundText":"R4","roundDivision":null},{"id":7509409,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":388743,"entrant2Id":355398,"winnerId":355398,"loserId":388743,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4840980,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840968,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"H","round":4,"state":3,"entrant1Score":-1,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427513,"updatedAtMicro":1487427513.3162,"startAt":null,"startedAt":1487427509,"completedAt":1487427513,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":4,"originalRound":4,"fullRoundText":"Round '
'4","midRoundText":"Round '
'4","shortRoundText":"R4","roundDivision":null},{"id":7509410,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":439067,"entrant2Id":355398,"winnerId":439067,"loserId":355398,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4841002,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4840968,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"I","round":5,"state":3,"entrant1Score":2,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427488,"updatedAtMicro":1487427488.2766,"startAt":null,"startedAt":1487427474,"completedAt":1487427488,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":5,"originalRound":5,"fullRoundText":"Round '
'5","midRoundText":"Round '
'5","shortRoundText":"R5","roundDivision":null},{"id":7509411,"eventId":20848,"phaseGroupId":343547,"stationId":null,"entrant1Id":388743,"entrant2Id":429536,"winnerId":429536,"loserId":388743,"bracketId":"58a50e52838e8","entrant1PrereqType":"seed","entrant1PrereqId":4840980,"entrant1PrereqCondition":null,"entrant2PrereqType":"seed","entrant2PrereqId":4841000,"entrant2PrereqCondition":null,"wProgressionSeedId":null,"lProgressionSeedId":null,"wPlacement":null,"lPlacement":null,"wOverallPlacement":null,"lOverallPlacement":null,"lEligiblePhaseId":null,"wEligiblePhaseId":null,"unreachable":false,"isTiebreak":false,"type":1,"crewPlayerCount":null,"identifier":"J","round":5,"state":3,"entrant1Score":-1,"entrant2Score":0,"bestOf":3,"totalGames":5,"setGamesType":1,"isLast":false,"isGF":false,"hasPlaceholder":false,"entrant1Present":true,"entrant2Present":true,"adminViewedBy":null,"adminMessagedBy":null,"tasksPruned":null,"subState":[],"modRequestedBy":null,"modRequestedAt":null,"vodUrl":null,"fbUrl":null,"smashggUrl":null,"durationSeconds":null,"updatedAt":1487427524,"updatedAtMicro":1487427524.1136,"startAt":null,"startedAt":1487427522,"completedAt":1487427524,"adminViewedAt":null,"adminMessagedAt":null,"progressionPlacement":null,"progressionCount":null,"games":[],"videogameId":4,"eventType":1,"images":[],"expand":["crew_lineup","station"],"displayRound":5,"originalRound":5,"fullRoundText":"Round '
'5","midRoundText":"Round '
'5","shortRoundText":"R5","roundDivision":null}]},"result":343547,"resultEntity":"groups","actionRecords":[]}')
In [34]:
with open(path+fname+ftag, 'r') as data_file:
data = json.load(data_file)
data.keys()
# data['entities']['groups']
for j in range(len(data['entities']['sets'])):
print(data['entities']['sets'][j]['bestOf'])
print(data['entities']['sets'][j]['entrant1Id'])
print(data['entities']['sets'][j]['entrant2Id'])
print(data['entities']['sets'][j]['loserId'])
print(data['entities']['sets'][j]['winnerId'])
print(data['entities']['sets'][j]['totalGames'])
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-34-0799378f7d28> in <module>()
1 with open(path+fname+ftag, 'r') as data_file:
----> 2 data = json.load(data_file)
3
4 data.keys()
5
/usr/lib/python3.5/json/__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
266 cls=cls, object_hook=object_hook,
267 parse_float=parse_float, parse_int=parse_int,
--> 268 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
269
270
/usr/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
317 parse_int is None and parse_float is None and
318 parse_constant is None and object_pairs_hook is None and not kw):
--> 319 return _default_decoder.decode(s)
320 if cls is None:
321 cls = JSONDecoder
/usr/lib/python3.5/json/decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):
/usr/lib/python3.5/json/decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Content source: NCssb64/major-stats
Similar notebooks: