Created
December 28, 2018 15:40
-
-
Save szczyt/59a9c36426dea47598ee413ace76221f to your computer and use it in GitHub Desktop.
REST countriesへの呼び出し関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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