From aca18c1cfc86f393fc3919afd6d59b10b6531074 Mon Sep 17 00:00:00 2001 From: Zane Date: Sat, 28 Dec 2019 17:23:20 -0600 Subject: [PATCH 1/2] Added a python example using the API --- examples/python/PythonExampleUsage.py | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/python/PythonExampleUsage.py diff --git a/examples/python/PythonExampleUsage.py b/examples/python/PythonExampleUsage.py new file mode 100644 index 0000000..b8fef41 --- /dev/null +++ b/examples/python/PythonExampleUsage.py @@ -0,0 +1,33 @@ +import requests, json + +FETCH_COUNT = 50 +URL = "https://countries.trevorblades.com" + +query = """ +{ + country(code: "BR") { + name + native + emoji + currency + languages { + code + name + } + } +} +""" + + +def get_country_data(arguments='{}'): + arguments = dict(query=arguments) # wrap query in dictionary + + graph_ql_request = requests.post(URL, + data=json.dumps(arguments), + headers={"Content-type": "application/json"}) + + country_data = graph_ql_request.json() + return country_data + + +print(get_country_data(arguments=query)) From b6cfaf6873d1c836b6a70dd4c5ec04c992ff651f Mon Sep 17 00:00:00 2001 From: Zane Date: Sun, 29 Dec 2019 19:44:35 -0600 Subject: [PATCH 2/2] Added a python example using the API --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ca2668d..4398d8a 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Check out [the playground](https://countries.trevorblades.com) to explore the sc - [React Native](https://github.com/muhzi4u/country-directory-app) - [ReasonML](https://medium.com/@idkjs/reasonml-and-graphql-without-graphql-part-1-192c2e9e349c) - [Country quiz app](https://github.com/byrichardpowell/Country-Quiz) (React, TypeScript) +- [Python](./examples/python) ## License