Skip to content

Commit 0dccea7

Browse files
committed
feat: add further queries
1 parent 4e79df4 commit 0dccea7

11 files changed

Lines changed: 626 additions & 153 deletions
Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
from playerdatapy.gqlauth import GraphqlAuth
22
from playerdatapy.gqlclient import Client
33
from playerdatapy.gqlauth import AuthenticationType
4-
import asyncio
54
from playerdatapy.constants import API_BASE_URL
5+
66
import os
7+
import asyncio
78
from datetime import datetime, timedelta
89

910
CLIENT_ID = os.environ.get("CLIENT_ID")
1011
CLIENT_SECRET = os.environ.get("CLIENT_SECRET")
1112
CLUB_ID = os.environ.get("CLUB_ID")
1213

14+
# Example usage of the GraphqlClient class.
15+
auth = GraphqlAuth(
16+
client_id=CLIENT_ID,
17+
client_secret=CLIENT_SECRET,
18+
type=AuthenticationType.CLIENT_CREDENTIALS_FLOW,
19+
)
20+
21+
# Create a Client instance.
22+
client = Client(
23+
url=f"{API_BASE_URL}/api/graphql",
24+
headers={"Authorization": f"Bearer {auth._get_authentication_token()}"},
25+
)
1326

1427
# Build out the query string to get session details.
1528
# Our GraphiQL Playground at https://app.playerdata.co.uk/api/graphiql/ is useful for building out and testing the query.
29+
# This example query gets all sessions for a club in the last 30 days.
1630
example_query = """
1731
query($clubIdEq:ID!,$startTimeGteq:ISO8601DateTime,$endTimeLteq:ISO8601DateTime){
1832
sessions(filter: {clubIdEq:$clubIdEq, startTimeGteq:$startTimeGteq, endTimeLteq:$endTimeLteq}){
@@ -22,30 +36,18 @@
2236
}
2337
}
2438
"""
25-
39+
startTimeGteq = (datetime.now() - timedelta(days=30)).isoformat()
40+
endTimeLteq = datetime.now().isoformat()
41+
variables = {
42+
"clubIdEq": CLUB_ID,
43+
"startTimeGteq": startTimeGteq,
44+
"endTimeLteq": endTimeLteq,
45+
}
2646

2747
async def main():
28-
auth = GraphqlAuth(
29-
client_id=CLIENT_ID,
30-
client_secret=CLIENT_SECRET,
31-
type=AuthenticationType.CLIENT_CREDENTIALS_FLOW,
32-
)
33-
client = Client(
34-
url=f"{API_BASE_URL}/api/graphql",
35-
headers={"Authorization": f"Bearer {auth._get_authentication_token()}"},
36-
)
37-
startTimeGteq = (datetime.now() - timedelta(days=30)).isoformat()
38-
endTimeLteq = datetime.now().isoformat()
39-
variables = {
40-
"clubIdEq": CLUB_ID,
41-
"startTimeGteq": startTimeGteq,
42-
"endTimeLteq": endTimeLteq,
43-
}
44-
response = await client.execute(query=example_query, variables=variables)
45-
result = client.get_data(response)
46-
return result["sessions"]
48+
response = client.execute(query=example_query, variables=variables)
49+
result = await client.get_data(response)
50+
print(result["sessions"])
4751

52+
asyncio.run(main())
4853

49-
if __name__ == "__main__":
50-
result = asyncio.run(main())
51-
print(result)

examples/direct/raw_data_query.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)