Skip to main content


Python Currency Converter Latest 2022(Accurate Data)

Currency Converter with Free API



Source Code:- Currency_converter_Version_1.py
# Required:- pip install CurrencyConverter
# Documentation :- https://pypi.org/project/CurrencyConverter/

from currency_converter import CurrencyConverter
c = CurrencyConverter()
conv = c.convert(100, 'USD', 'INR')
print(conv)


Source Code:- Currency_converter_Version_2.py
#Source Code:- FREE Currency Converter [LATEST Conversion]
##Dev:- Joel Dcosta
# pip install xmltodict
## You can also view some currency converter APIs
#
#API:- https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
#
###################################################

from requests import get
import xmltodict
import json
import time

# I am using XML as my API
xml_url = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
response = get(xml_url)
data = xmltodict.parse(response.content)

# Converting XML to JSON and saving it as data.json
with open('data.json', 'w') as f:
    json.dump(data, f)
    f.close()

# Read json file
read = open('data.json','r')
data = json.load(read)
count = 0

print(':::Currency List:::\n')
for i in data['gesmes:Envelope']['Cube']['Cube']['Cube']:
    currency = data['gesmes:Envelope']['Cube']['Cube']['Cube'][count]['@currency']
    rate = data['gesmes:Envelope']['Cube']['Cube']['Cube'][count]['@rate']
    directory = (currency+'='+rate)
    print(directory)
    # Creating a quick python script from the data
    with open('currency_list.py', 'a') as c:
        c.writelines(directory+'\n')
        c.close()
    count += 1
print('\n\n')

# Importing the create script as currency_list
from currency_list import *

def conv(rate, _to, _from):
    #print(1000*USD / INR)
    return (rate *  _from / _to)
###################################################
print('RUN And TYPE THE FOLLOWING')
print('EXAMPLE:-')
print('conv(<AMOUNT>,<Convert from>,<Convert to>)')

Comments



🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Top 11 Essential Python Tips and Tricks

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram