|
4 | 4 | import requests |
5 | 5 | import pandas as pd |
6 | 6 |
|
7 | | -def apiQuery(tier, query, variables): |
| 7 | +def apiQuery(tier, query, variables, verbose=0): |
8 | 8 | if tier == 'prod': |
9 | 9 | url = 'https://hub.datacommons.cancer.gov/api/graphql' |
10 | 10 | token = os.environ['PRODAPI'] |
| 11 | + if verbose >= 2: |
| 12 | + print(f"Running query on prod:\n{query}\n") |
11 | 13 | elif tier == 'stage': |
12 | 14 | #Note that use of Stage is for example purposes only, actual submissions should use the production URL. If you wish to run tests on Stage, please contact the helpdesk. |
13 | 15 | url = 'https://hub-stage.datacommons.cancer.gov/api/graphql' |
14 | 16 | token = os.environ['STAGEAPI'] |
| 17 | + if verbose >= 2: |
| 18 | + print(f"Running query on stage:\n{query}\n") |
15 | 19 | else: |
16 | 20 | return('Please provide either "stage" or "prod" as tier values') |
17 | 21 | headers = {"Authorization": f"Bearer {token}"} |
| 22 | + if verbose >= 3: |
| 23 | + print(f"Headers:\n{headers}") |
18 | 24 | try: |
19 | 25 | if variables is None: |
20 | 26 | result = requests.post(url = url, headers = headers, json={"query": query}) |
21 | 27 | else: |
22 | 28 | result = requests.post(url = url, headers = headers, json = {"query":query, "variables":variables}) |
23 | 29 | if result.status_code == 200: |
| 30 | + if verbose >= 3: |
| 31 | + print(result.json()) |
24 | 32 | return result.json() |
25 | 33 | else: |
26 | 34 | print(f"Error: {result.status_code}") |
| 35 | + if verbose >= 3: |
| 36 | + print(result.content) |
27 | 37 | return result.content |
28 | 38 | except requests.exceptions.HTTPError as e: |
29 | 39 | return(f"HTTP Error: {e}") |
@@ -90,7 +100,9 @@ def main(args): |
90 | 100 | reslist = [] |
91 | 101 | for submissionid in sublist: |
92 | 102 | checkvars = {"id": submissionid} |
93 | | - res = apiQuery(args.tier.lower(), getSubmissionQuery, checkvars) |
| 103 | + if args.verbose >= 2: |
| 104 | + print(f"Updating submission:\t {checkvars}") |
| 105 | + res = apiQuery(args.tier.lower(), getSubmissionQuery, checkvars, args.verbose) |
94 | 106 | if args.verbose >= 2: |
95 | 107 | reslist.append(res['data']['getSubmission']) |
96 | 108 | if args.verbose >= 2: |
|
0 commit comments