Skip to content

Commit 843849a

Browse files
committed
Convert from symbol to code.
1 parent 26368e1 commit 843849a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

forex_python/converter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ def _get_data(self, currency_code):
119119
currency_dict = next((item for item in currency_data if item["cc"] == currency_code), None)
120120
return currency_dict
121121

122+
def _get_data_from_symbol(self, symbol):
123+
file_path = os.path.dirname(os.path.abspath(__file__))
124+
with open(file_path + '/raw_data/currencies.json') as f:
125+
currency_data = json.loads(f.read())
126+
currency_dict = next((item for item in currency_data if item["symbol"] == symbol), None)
127+
return currency_dict
128+
122129
def get_symbol(self, currency_code):
123130
currency_dict = self._get_data(currency_code)
124131
if currency_dict:
@@ -131,6 +138,13 @@ def get_currency_name(self, currency_code):
131138
return currency_dict.get('name')
132139
return None
133140

141+
def get_currency_code_from_symbol(self, symbol):
142+
currency_dict = self._get_data_from_symbol(symbol)
143+
if currency_dict:
144+
return currency_dict.get('cc')
145+
return None
146+
147+
134148
_CURRENCY_CODES = CurrencyCodes()
135149

136150

0 commit comments

Comments
 (0)