Last active
May 5, 2019 05:25
-
-
Save clystian/8724c0eae5af1c231c534fb9717e248d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 unirest | |
| def convert_currency(origin, destination, amount = 1): | |
| convert = origin+"_"+destination | |
| urlRequest = "https://free.currconv.com/api/v7/convert?q="+convert+"&compact=ultra&apiKey=47353d3141893576b990" | |
| response = unirest.get(urlRequest) | |
| return amount * response.body[convert] | |
| usdcop = convert_currency("USD","COP") |
This file contains hidden or 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 urllib2 | |
| import json | |
| def convert_currency_urllib2( origin, destination, amount = 1): | |
| convert = origin+"_"+destination | |
| urlRequest = "https://free.currconv.com/api/v7/convert?q="+convert+"&compact=ultra&apiKey=47353d3141893576b990" | |
| response = urllib2.urlopen(urlRequest) | |
| data = json.load(response) | |
| return amount * data[convert] | |
| usdcop = convert_currency_urllib2("USD","COP"); | |
| print "urllib2 results: "sdcop | |
| import json | |
| import urllib | |
| def convert_currency_urllib(origin, destination, amount = 1): | |
| convert = origin+"_"+destination | |
| urlRequest = "https://free.currconv.com/api/v7/convert?q="+convert+"&compact=ultra&apiKey=47353d3141893576b990" | |
| response = urllib.request.urlopen(urlRequest) | |
| data = json.loads(r.read().decode(response.info().get_param('utf-8')) | |
| return amount * data[convert] | |
| usdcop = convert_currency_urllib("USD","COP") | |
| print "urllib results :" + usdcop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks