From 6ed26f0a126e9ca427ebc2727b128f9e37b95a90 Mon Sep 17 00:00:00 2001 From: l3n Date: Thu, 23 Sep 2021 22:34:13 +0200 Subject: [PATCH] Add python commands history. --- README.org | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/README.org b/README.org index fd500f6..ec88bf0 100644 --- a/README.org +++ b/README.org @@ -33,3 +33,139 @@ events via mobilizon GraphQL api from yaml or json or whatever. Probably yaml. - https://graphql-core-3.readthedocs.io/en/latest/usage/queries.html *** developing in guix + + + +** Python requests + + #+BEGIN_EXAMPLE python + import requests + import json + endpoint='https://dogodki.kompot.si/api' + body=''' + query { + events { + elements { + id, + url, + title, + description, + beginsOn, + endsOn, + status, + picture { + url + }, + physicalAddress { + id, + description, + locality + } + } + total + } + } + ''' + r = requests.post(endpoint, json={'query':body}, '') + r = requests.post(endpoint, json={"query":body}, headers='') + r.status_code + print(json.dumps(r.json(), indent=2)) + body + body2=''' + query { + events { + elements { + id, + url, + title, + description, + beginsOn, + endsOn, + status, + picture { + url + }, + physicalAddress { + id, + description, + locality + } + } + } + } + ''' + body2=''' + query { + groups { + elements { + id, + name, + domain, + page + } + } + } + ''' + r2 = requests.post(endpoint, json={"query":body2}, headers='') + print(json.dumps(r2.json(), indent=2)) + body2="query{grups{elements{id,name}}}" + r2 = requests.post(endpoint, json={"query":body2}, headers='') + r2.status_code + print(json.dumps(r2.json(), indent=2)) + b2 + body2 + body2="query{\ngrups{\nelements{\nid,\nname\n}\n}\n}" + r2 = requests.post(endpoint, json={"query":body2}, headers='') + r2.status_code + r2 = requests.post(endpoint, json={"query":body2}, headers='') + print(json.dumps(r2.json(), indent=2)) + bl=''' + mutation Login($email: String!, $password: String!) { + login(email: $email, password: $password) { + accessToken + refreshToken + user { + id + email + role + } + } + } + ''' + varsl= {'email': 'lio@kompot.si', 'password': ''} + r3=requests.post(endpoint, json={"query": bl, 'variables': varsl}, headers='') + r3.status_code + print(json.dumps(r3json(), indent=2)) + print(json.dumps(r3.json(), indent=2)) + r3.json() + r3.json().data + r3.json().get('data') + r3.json().get('data').get.('login') + r3.json().get('data').get('login') + r3.json().get('data').get('login').get('login') + r3.json().get('data').get('login').get('accessToken') + r3.json().get('data.login') + j=r3.json() + data=json.loads(j) + j + data=json.loads(j) + print j['data']['login']['accessToken'] + j + j['data'] + j['data']['login'] + j['data']['login']['accessToken'] + at=j['data']['login']['accessToken'] + head={"Authorization": f"Bearer {at}"} + r2 = requests.post(endpoint, json={"query":body2}, headers='') + print(json.dumps(r2.json(), indent=2)) + bg="query{groups{elements{id,name}\ntotal}}" + r2 = requests.post(endpoint, json={"query":body2}, headers='') + print(json.dumps(r2.json(), indent=2)) + bg="query {\ngroups {\nelements {\nid,\nname}\ntotal\n}\n}" + bg + r2 = requests.post(endpoint, json={"query":bg}, headers=head) + r2.status_code + print(json.dumps(r2.json(), indent=2)) + + #+END_EXAMPLE +