Skip to content

Commit b5e91b0

Browse files
committed
Catch all exceptions when fetching and parsing currency data in qmodule
1 parent 071d6de commit b5e91b0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

queries/currency.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,31 @@ def QCurAmountConversion(node: Node, params: QueryStateDict, result: Result) ->
205205

206206
@cachetools.cached(cachetools.TTLCache(1, _CURR_CACHE_TTL))
207207
def _fetch_exchange_rates() -> Optional[Dict[str, float]]:
208+
<<<<<<< Updated upstream
208209
"""Fetch exchange rate data from apis.is and cache it."""
209210
res = query_json_api(_CURR_API_URL)
210211
if not isinstance(res, dict) or "results" not in res:
211212
logging.warning(f"Unable to fetch exchange rate data from {_CURR_API_URL}")
213+
=======
214+
"""Fetch exchange rate data from Arion banki and cache it."""
215+
try:
216+
resp = requests.get(_ARION_EXCHR_XML_API_URL, timeout=5)
217+
# Parse the XML response
218+
root = ET.fromstring(resp.content)
219+
exchange_rates = {}
220+
items_element = root.find('items')
221+
if items_element is None:
222+
return None
223+
# Build dict mapping currency ID to sale rate
224+
for currency_element in items_element.findall('Currency'):
225+
currency_id = currency_element.find('mynt').text
226+
sale_rate_str = currency_element.find('Solugengi').text
227+
sale_rate_float = float(sale_rate_str)
228+
exchange_rates[currency_id] = sale_rate_float
229+
return exchange_rates
230+
except Exception as e:
231+
logging.warning(f"Error fetching exchange rate data from {_ARION_EXCHR_XML_API_URL}: {e}")
232+
>>>>>>> Stashed changes
212233
return None
213234
return {
214235
c["shortName"]: c["value"]

templates/about.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,7 @@
226226
</script>
227227

228228
{% endblock %}
229+
<<<<<<< Updated upstream
230+
=======
231+
232+
>>>>>>> Stashed changes

0 commit comments

Comments
 (0)