aboutsummaryrefslogtreecommitdiff
path: root/custom_requests.py
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-09-25 20:28:58 -0500
committerMark Powers <markppowers0@gmail.com>2020-09-25 20:28:58 -0500
commitb1d66f527869236b877207fb617c2660ef68e95e (patch)
tree34cb6060e0da49f51fbc95449c54d37d948c94f7 /custom_requests.py
parent9275df710e578aa0ce67de12a952d76e3f036757 (diff)
Add edit page command
Diffstat (limited to 'custom_requests.py')
-rw-r--r--custom_requests.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/custom_requests.py b/custom_requests.py
new file mode 100644
index 0000000..65673cf
--- /dev/null
+++ b/custom_requests.py
@@ -0,0 +1,30 @@
+import requests
+import sys
+import json
+from 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()
+