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