From 3b04a4b2d83bbfe765c519ac37c437f478984742 Mon Sep 17 00:00:00 2001 From: JeremySkalla <77216636+JeremySkalla@users.noreply.github.com> Date: Fri, 4 Mar 2022 13:53:13 -0600 Subject: [PATCH] v1.2, CHANGELOG.md for updates --- CHANGELOG.md | 6 ++++++ README.md | 4 ++++ pysmashgg/filters.py | 31 ++++++++++++++++++++++++++----- pysmashgg/smashgg.py | 4 ++++ pysmashgg/t_queries.py | 25 ++++++++++++++++++++++++- pysmashgg/tournaments.py | 6 ++++++ setup.py | 2 +- 7 files changed, 71 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c2e11..b40f8da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# **v1.2** + +- I figured I've been doing so many minor updates we'll call this a new version +- Added `tournament_show_by_owner(owner, page_num)` +- Added `startAt` to `tournament_show_event_by_game_size_dated` + # **v1.1 thru v1.1.6** - Added game results (and then fixed a bug with them) diff --git a/README.md b/README.md index 9244094..1d05f9a 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,10 @@ print(tournaments_by_radius) # Shows players at tournaments from a certain sponsor/prefix players_by_sponsor = smash.tournament_show_players_by_sponsor('genesis-7', 'C9') print(players_by_sponsor) + +# Shows tournaments by owner +tournaments_by_owner = smash.tournament_show_by_owner(161429, 1) +print(tournaments_by_owner) ``` ## **Event Usage** diff --git a/pysmashgg/filters.py b/pysmashgg/filters.py index 5fddf0a..fdeb890 100644 --- a/pysmashgg/filters.py +++ b/pysmashgg/filters.py @@ -455,6 +455,7 @@ def show_event_by_game_size_dated_filter(response, size, videogame_id): cur_event['tournamentSlug'] = node['slug'].split('/')[-1] cur_event['tournamentId'] = node['id'] cur_event['online'] = node['isOnline'] + cur_event['startAt'] = node['startAt'] cur_event['endAt'] = node['endAt'] cur_event['eventName'] = event['name'] cur_event['eventId'] = event['id'] @@ -562,11 +563,6 @@ def show_by_radius_filter(response): cur_tournament['city'] = node['city'] cur_tournament['startTimestamp'] = node['startAt'] cur_tournament['endTimestamp'] = node['endAt'] - # IMPLEMENT THIS ONCE I ACTUALLY UNDERSTAND HOW STATE WORKS - # if node['state'] == 3: - # cur_tournament['completed'] = True - # else: - # cur_tournament['completed'] = False tournaments.append(cur_tournament) @@ -595,6 +591,31 @@ def show_players_by_sponsor_filter(response): return players +def show_by_owner_filter(response): + if response['data']['tournaments'] is None: + return + + if response['data']['tournaments']['nodes'] is None: + return + + tournaments = [] + + for node in response['data']['tournaments']['nodes']: + cur_tournament = {} + cur_tournament['id'] = node['id'] + cur_tournament['name'] = node['name'] + cur_tournament['slug'] = node['slug'].split('/')[-1] + cur_tournament['entrants'] = node['numAttendees'] + cur_tournament['country'] = node['countryCode'] + cur_tournament['state'] = node['addrState'] + cur_tournament['city'] = node['city'] + cur_tournament['startTimestamp'] = node['startAt'] + cur_tournament['endTimestamp'] = node['endAt'] + + tournaments.append(cur_tournament) + + return tournaments + # BRACKETS.PY # Filter for the show_entrants function diff --git a/pysmashgg/smashgg.py b/pysmashgg/smashgg.py index bf8a3d1..cee20e8 100644 --- a/pysmashgg/smashgg.py +++ b/pysmashgg/smashgg.py @@ -91,6 +91,10 @@ def tournament_show_by_radius(self, coordinates, radius, page_num): # Players from a tournament with a certain sponsor def tournament_show_players_by_sponsor(self, tournament_name, sponsor): return tournaments.show_players_by_sponsor(tournament_name, sponsor, self.header, self.auto_retry) + + # Tournaments by owner id + def tournament_show_by_owner(self, owner, page_num): + return tournaments.show_by_owner(owner, page_num, self.header, self.auto_retry) # All entrants in a bracket (phaseGroup) at a tournament def bracket_show_entrants(self, bracket_id, page_num): diff --git a/pysmashgg/t_queries.py b/pysmashgg/t_queries.py index 7fab653..f303a3f 100644 --- a/pysmashgg/t_queries.py +++ b/pysmashgg/t_queries.py @@ -238,6 +238,7 @@ id slug isOnline + startAt endAt events { name @@ -365,4 +366,26 @@ } } } -}""" \ No newline at end of file +}""" + +SHOW_BY_OWNER_QUERY = """query TournamentsByOwner($ownerId: ID!, $page: Int!) { + tournaments(query: { + perPage: 25, + page: $page, + filter: { ownerId: $ownerId } + }) { + nodes { + id + name + slug + numAttendees + countryCode + addrState + city + startAt + endAt + state + } + } +} +""" \ No newline at end of file diff --git a/pysmashgg/tournaments.py b/pysmashgg/tournaments.py index 0613970..e9af051 100644 --- a/pysmashgg/tournaments.py +++ b/pysmashgg/tournaments.py @@ -144,4 +144,10 @@ def show_players_by_sponsor(tournament_name, sponsor, header, auto_retry): variables = {"slug": tournament_name, "sponsor": sponsor} response = run_query(SHOW_PLAYERS_BY_SPONSOR, variables, header, auto_retry) data = filters.show_players_by_sponsor_filter(response) + return data + +def show_by_owner(owner, page_num, header, auto_retry): + variables = {"ownerId": owner, "page": page_num} + response = run_query(SHOW_BY_OWNER_QUERY, variables, header, auto_retry) + data = filters.show_by_owner_filter(response) return data \ No newline at end of file diff --git a/setup.py b/setup.py index dae34eb..6355ba7 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pysmashgg", - version="1.1.6", + version="1.2", author="Jeremy Skalla", author_email="jthroughs@gmail.com", description="Python Wrapper for smash.gg's GraphQL API",