From 4e4b0997a2172e00c8a46acb6889fe2c8c939a09 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 27 Sep 2021 22:02:49 -0500 Subject: Add packaging tooling --- wikijscmd/custom_requests.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 wikijscmd/custom_requests.py (limited to 'wikijscmd/custom_requests.py') diff --git a/wikijscmd/custom_requests.py b/wikijscmd/custom_requests.py new file mode 100644 index 0000000..bc9b16e --- /dev/null +++ b/wikijscmd/custom_requests.py @@ -0,0 +1,30 @@ +import requests +import sys +import json +from wikijscmd.config import config + +def handle_errors(r): + error = False + if r.status_code != 200: + error = True + print("Error status code: %s" % r.status_code) + json = r.json() + if "errors" in json: + error = True + for e in json["errors"]: + print(e["message"]) + print(e) + if error: + sys.exit(1) + + +def get_headers(): + return { "Authorization": "Bearer %s" % config["wiki"]["key"] } + +def send_query(query, query_vars): + '''Returns status code, json''' + payload = { "query": query, "variables": query_vars} + r = requests.post(config["wiki"]["url"], json=payload, headers = get_headers()) + handle_errors(r) + return r.json() + -- cgit v1.2.3