Refactor, extract pulls and get example pull
authorJacob Casper <dev@jacobcasper.com>
Fri, 6 Aug 2021 21:13:56 +0000 (16:13 -0500)
committerJacob Casper <dev@jacobcasper.com>
Fri, 6 Aug 2021 21:13:56 +0000 (16:13 -0500)
main.py

diff --git a/main.py b/main.py
index 9a695b1..f2c7f90 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -4,6 +4,14 @@ from gql.transport.aiohttp import AIOHTTPTransport
 import requests
 from secrets import *
 
+encounter_aliases = [
+        'cloudRanks',
+        'dogRanks',
+        'thanRanks',
+        'boobaRanks',
+        'gaiaRanks',
+]
+
 res = requests.post(
         "https://www.fflogs.com/oauth/token", 
         data={"grant_type": "client_credentials"},
@@ -44,8 +52,28 @@ params = {
         "serverRegion": "na",
         }
 result = client.execute(query, variable_values=params)
-print(result['characterData']['character']['cloudRanks']['ranks'][0]['report'])
-print(result['characterData']['character']['dogRanks']['ranks'][0]['report'])
-print(result['characterData']['character']['thanRanks']['ranks'][0]['report'])
-print(result['characterData']['character']['boobaRanks']['ranks'][0]['report'])
-print(result['characterData']['character']['gaiaRanks']['ranks'][0]['report'])
+encounter_ranks = [result['characterData']['character'][encounter_alias] for encounter_alias in encounter_aliases]
+ranks = [rank for encounter in encounter_ranks for rank in encounter['ranks']]
+pulls = [(rank['report']['code'], rank['report']['fightID']) for rank in ranks]
+query = gql(
+        '''
+        query ($code: String!, $fightIds: [Int]!) {
+          reportData {
+            report (
+              code: $code
+            )
+            {
+              code
+              fights (
+                fightIDs: $fightIds
+              )
+              {
+                hasEcho
+                kill
+              }
+            }
+          }
+        }
+        '''
+        )
+result = client.execute(query, variable_values={"code": pulls[0][0], "fightIds": pulls[0][1]})