Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Currency Conversion

Is there any facility in Django for doing currency conversions? Obviously, rates change day by day but I'm somewhat hopeful that the locale module has some sort of web-service based converter.

There's a snippet here that handles the formatting: http://www.djangosnippets.org/snippets/552/ But I need to localize the values first.

like image 835
Koobz Avatar asked Mar 21 '26 22:03

Koobz


2 Answers

Probably more elegant ways to do this, but it works.

currency_in = 'USD'
currency_out = 'NOK'
import urllib2
req = urllib2.urlopen('http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='+currency_in+currency_out+'=X')
result = req.read()
# result = "USDNOK=X",5.9423,"5/3/2010","12:39pm"

Then you can split() the result for the modifier.

like image 65
twined Avatar answered Mar 23 '26 12:03

twined


# Install google-currency package

# pip install google-currency

>>> from google_currency import convert  

>>> convert('usd', 'bdt', 1) 

Output:

{"from": "USD", "to": "BDT", "amount": "85.30", "converted": true}
like image 33
MdNazmulHossain Avatar answered Mar 23 '26 11:03

MdNazmulHossain