Skip to content

Instantly share code, notes, and snippets.

@szczyt
Created December 28, 2018 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szczyt/59a9c36426dea47598ee413ace76221f to your computer and use it in GitHub Desktop.
Save szczyt/59a9c36426dea47598ee413ace76221f to your computer and use it in GitHub Desktop.
REST countriesへの呼び出し関数
import requests
REST_EU_ROOT_URL = "http://restcountries.eu/rest/v2"
def REST_country_request(field='all', name='', params=None):
headers = {'User-Agent' : 'Mozilla/5.0'}
if params is None:
params = {}
if field == 'all':
return requests.get(REST_EU_ROOT_URL + '/all')
url = '%s/%s/%s'%(REST_EU_ROOT_URL, field, name)
print('Requesting URL: '+url)
response = requests.get(url, params=params, headers=headers)
if not response.status_code == 200:
raise Exception('Request failed with status code' + str(response.status_code))
return response
response = REST_country_request('currency', 'usd')
print(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment