Skip to content

Instantly share code, notes, and snippets.

@kaijchang
Last active August 1, 2024 03:07
Show Gist options
  • Save kaijchang/000ba7ee4bc55e1d0747c2b9400343ee to your computer and use it in GitHub Desktop.
Save kaijchang/000ba7ee4bc55e1d0747c2b9400343ee to your computer and use it in GitHub Desktop.
# pip install "gql[all]"
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
transport = AIOHTTPTransport(url="https://graphql-prod-4626.prod.aws.worldathletics.org/graphql", headers={
"x-api-key": "da2-f5bnlno2fvhzldaq5bvyj7ccry"
})
client = Client(transport=transport, fetch_schema_from_transport=True)
competitor_results_query = gql(
"""
query($id: Int!, $resultsByYear: Int!) {
getSingleCompetitorResultsDate(id: $id, resultsByYearOrderBy: "date", resultsByYear: $resultsByYear) {
resultsByDate {
competition
competitionId
date
discipline
place
mark
}
}
}
"""
)
competitor_query = gql(
"""
query($id: Int!) {
getSingleCompetitor(id: $id) {
personalBests {
results {
discipline
mark
}
}
}
}
"""
)
competition_query = gql(
"""
query($id: Int!) {
getCalendarCompetitionResults(competitionId: $id) {
eventTitles {
events {
event
gender
races {
race
results {
competitor {
id
name
}
mark
place
}
}
}
}
}
}
"""
)
for year in range(2022, 2024):
result = client.execute(competitor_results_query, variable_values={
"id": 14536762, # Noah Lyles
"resultsByYear": year
})
print(result)
result = client.execute(competitor_query, variable_values={
"id": 14536762, # Noah Lyles
})
print(result)
result = client.execute(competition_query, variable_values={
"id": 7154229, # Millrose 2022
})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment