corrected offline error to be catched.
This commit is contained in:
parent
6cf9d77cae
commit
b02e8c1343
|
@ -24,14 +24,18 @@ def get_exchange_rate():
|
|||
# ~~~~~~~~~~~~~~~~~~~~~
|
||||
today = datetime.now().strftime("%Y-%m-%d")
|
||||
SNB_URL = 'https://www.snb.ch/selector/de/mmr/exfeed/rss'
|
||||
urlsocket = ''
|
||||
try:
|
||||
urlsocket = urllib.request.urlopen(SNB_URL)
|
||||
except urllib.error.URLError as e:
|
||||
print('err: urllib.request.urlopen: ', e.reason)
|
||||
if urlsocket:
|
||||
root = ET.parse(urlsocket)
|
||||
root = ET.ElementTree(root)
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~
|
||||
# development block:
|
||||
# ~~~~~~~~~~~~~~~~~~~~~
|
||||
# today = "2018-01-03"
|
||||
# today = "2018-01-08"
|
||||
# try:
|
||||
# root = ET.ElementTree(file='rss')
|
||||
# except Exception as e:
|
||||
|
@ -79,7 +83,7 @@ def get_exchange_rate():
|
|||
print('%s (%s)' % (e, type(e)))
|
||||
continue
|
||||
# Print dates for development:
|
||||
# print("date:", date, "today:", today)
|
||||
# print("date:", date, "today:", today)
|
||||
# only the values of today are used so check for date in XML:
|
||||
if date == today:
|
||||
# now search for the currency exchange rate:
|
||||
|
@ -136,5 +140,5 @@ def get_exchange_rate():
|
|||
# Print the Dictionary:
|
||||
# print(exchange_rates)
|
||||
else:
|
||||
break
|
||||
continue
|
||||
return(exchange_rates, today)
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
<tr>
|
||||
<th scope="col">DATE</th>
|
||||
<th scope="col">RATE</th>
|
||||
<tr>
|
||||
</tr>
|
||||
{% for currency in currency_USD_list %}
|
||||
<tr>
|
||||
<td scope="col">{{ currency.date.date }}</td>
|
||||
<td scope="col">{{ currency.exchange_rate_to_chf }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="alert">
|
||||
|
@ -34,13 +34,13 @@
|
|||
<tr>
|
||||
<th scope="col">DATE</th>
|
||||
<th scope="col">RATE</th>
|
||||
<tr>
|
||||
</tr>
|
||||
{% for currency in currency_EUR_list %}
|
||||
<tr>
|
||||
<td scope="col">{{ currency.date.date }}</td>
|
||||
<td scope="col">{{ currency.exchange_rate_to_chf }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="alert">
|
||||
|
@ -54,11 +54,12 @@
|
|||
<tr>
|
||||
<th scope="col">DATE</th>
|
||||
<th scope="col">RATE</th>
|
||||
<tr>
|
||||
</tr>
|
||||
{% for currency in currency_JPY_list %}
|
||||
<tr>
|
||||
<td scope="col">{{ currency.date.date }}</td>
|
||||
<td scope="col">{{ currency.exchange_rate_to_chf }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
</table>
|
||||
|
@ -74,11 +75,12 @@
|
|||
<tr>
|
||||
<th scope="col">DATE</th>
|
||||
<th scope="col">RATE</th>
|
||||
<tr>
|
||||
</tr>
|
||||
{% for currency in currency_GBP_list %}
|
||||
<tr>
|
||||
<td scope="col">{{ currency.date.date }}</td>
|
||||
<td scope="col">{{ currency.exchange_rate_to_chf }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
</table>
|
||||
|
|
|
@ -12,11 +12,15 @@ def currencies(request):
|
|||
# prepares the view all dynamicaly.
|
||||
# It can grow in terms of more Currencies over time automaticaly.
|
||||
today = ''
|
||||
raw_data = ''
|
||||
raw_data = []
|
||||
try:
|
||||
raw_data, today = exchange_rates.get_exchange_rate()
|
||||
print('views raw_data: ', raw_data) # assert False
|
||||
except Exception as e:
|
||||
print('views raw_data: ', raw_data, 'error:', e) # assert False
|
||||
message_no = "Already querried today: "
|
||||
message_yes = " Updated successfully: "
|
||||
if raw_data:
|
||||
print(raw_data)
|
||||
for currency, rate in raw_data.items():
|
||||
if ExchangeRate.objects.filter(
|
||||
date__date=today,
|
||||
|
|
Loading…
Reference in New Issue