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
Post a Comment