(url: str, params: Mapping[str, str], headers: dict, debug_requests=False)
| 44 | |
| 45 | |
| 46 | def query_api(url: str, params: Mapping[str, str], headers: dict, debug_requests=False) -> dict: |
| 47 | if debug_requests: |
| 48 | print(f'REQUEST URL: {url}') |
| 49 | if len(params) > 0: |
| 50 | print(f'QUERY: {params}') |
| 51 | |
| 52 | response = requests.get(url, params=params, headers=headers, timeout=60) |
| 53 | response.raise_for_status() |
| 54 | |
| 55 | if debug_requests: |
| 56 | json_response = response.json() |
| 57 | print('========== RESPONSE ==========') |
| 58 | if json_response is not None: |
| 59 | print(json.dumps(json_response, indent=4)) |
| 60 | else: |
| 61 | print(response.content) |
| 62 | print('==============================') |
| 63 | |
| 64 | return response.json() |
| 65 | |
| 66 | |
| 67 | def download_file(url: str, target_path: Path, headers: dict, overwrite=False): |
no test coverage detected