This commit is contained in:
2021-05-04 21:30:14 +05:30
parent 293fa8b69d
commit 8c3f918a86
8 changed files with 430 additions and 1 deletions

46
CurrencyConverter.py Normal file
View File

@@ -0,0 +1,46 @@
"""
----------------------------------------
Currency Converter
----------------------------------------
This is a straightforward project with a simple GUI.
The name quite evidently describes the role of the
project is to convert currencies from one unit into another.
For example, converting Indian rupee to USD or euro. Tkinter,
the standard Python interface can be used to design and develop
this application.
----------------------------------------
"""
import urllib.request
import json
def currency_converter(currency_from, currency_to, currency_input):
yql_base_url = "https://query.yahooapis.com/v1/public/yql"
yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair' \
'%20in%20("'+currency_from+currency_to+'")'
yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
try:
yql_response = urllib.request.urlopen(yql_query_url)
try:
json_string = str(yql_response.read())
json_string = json_string[2:]
json_string = json_string[:-1]
print(json_string)
yql_json = json.loads(json_string)
last_rate = yql_json['query']['results']['rate']['Rate']
currency_output = currency_input * float(last_rate)
return currency_output
except (ValueError, KeyError, TypeError):
print(yql_query_url)
return "JSON format error"
except IOError as e:
print(str(e))
currency_input = 1
# currency codes : http://en.wikipedia.org/wiki/ISO_4217
currency_from = "USD"
currency_to = "TRY"
rate = currency_converter(currency_from, currency_to, currency_input)
print(rate)