Merge pull request #8 from ZaneTurner/master

Added a python example using the API
This commit is contained in:
Trevor Blades
2019-12-30 06:56:21 -08:00
committed by GitHub
2 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -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))