vagrant provision does not work so i need to commit unsolved files
This commit is contained in:
parent
50b16ec842
commit
47ed36e3af
|
@ -25,11 +25,12 @@ def get_exchange_rate():
|
||||||
# urlsocket = urllib.request.urlopen(SNB_URL)
|
# urlsocket = urllib.request.urlopen(SNB_URL)
|
||||||
# root = ET.parse(urlsocket)
|
# root = ET.parse(urlsocket)
|
||||||
# root = ET.ElementTree(root)
|
# root = ET.ElementTree(root)
|
||||||
|
# today = datetime.now().strftime("%Y-%m-%d")
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~
|
||||||
# development block:
|
# development block:
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~
|
||||||
root = ET.ElementTree(file='rss')
|
root = ET.ElementTree(file='rss')
|
||||||
|
today = "2018-01-01"
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
# Namespaces
|
# Namespaces
|
||||||
|
@ -42,8 +43,7 @@ def get_exchange_rate():
|
||||||
# Pathvariables to XML Namespaces
|
# Pathvariables to XML Namespaces
|
||||||
rate_path = 'cb:statistics/cb:exchangeRate/'
|
rate_path = 'cb:statistics/cb:exchangeRate/'
|
||||||
observation_path = 'cb:statistics/cb:exchangeRate/cb:observation/'
|
observation_path = 'cb:statistics/cb:exchangeRate/cb:observation/'
|
||||||
# today = datetime.now().strftime("%Y-%m-%d")
|
|
||||||
today = "2018-01-02"
|
|
||||||
exchange_rates = {}
|
exchange_rates = {}
|
||||||
|
|
||||||
for item in root.findall('none:item', ns):
|
for item in root.findall('none:item', ns):
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class ExchangeRate_name(models.Model):
|
||||||
|
name = models.CharField(max_length=200, unique=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class ExchangeRate_date(models.Model):
|
||||||
|
date = models.DateField('%Y-%m-%d', unique_for_date=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.date)
|
||||||
|
|
||||||
|
|
||||||
class ExchangeRate(models.Model):
|
class ExchangeRate(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.ForeignKey(ExchangeRate_name)
|
||||||
date = models.DateField('%Y-%m-%d', null=True)
|
date = models.ForeignKey(ExchangeRate_date)
|
||||||
exchange_rate_to_chf = models.FloatField(max_length=5)
|
exchange_rate_to_chf = models.FloatField(max_length=5)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -23,15 +23,19 @@
|
||||||
{% endifchanged %}
|
{% endifchanged %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table> -->
|
</table> -->
|
||||||
|
{% else %}
|
||||||
|
<p class="alert">
|
||||||
|
currency_list missing.
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
<br>
|
<br>
|
||||||
<p> {{ message }} </p>
|
<p> {{ message }} </p>
|
||||||
<br>
|
<br>
|
||||||
<ul>
|
<ul>
|
||||||
{% for currency in currency_list %}
|
{% for currency in currency_list %}
|
||||||
<li>
|
<li>
|
||||||
{{ currency.date }} :
|
{{ currency.date.date }} :
|
||||||
{{ currency.name }} :
|
{{ currency.name.name }} :
|
||||||
{{ currency.exchange_rate_to_chf }}
|
{{ currency.exchange_rate_to_chf }}
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -47,11 +51,6 @@
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
|
||||||
<p class="alert">
|
|
||||||
Something whent totaly wrong.
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
<br>
|
<br>
|
||||||
today
|
today
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -78,11 +77,9 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
count_date
|
count_raw_data
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>{{ count_raw_data }}</li>
|
||||||
{{ count_date }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
count_currencies
|
count_currencies
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from currencies.models import ExchangeRate
|
from currencies.models import ExchangeRate, ExchangeRate_date, ExchangeRate_name
|
||||||
from currencies import exchange_rates
|
from currencies import exchange_rates
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,17 +11,53 @@ def currencies(request):
|
||||||
raw_data, today = exchange_rates.get_exchange_rate()
|
raw_data, today = exchange_rates.get_exchange_rate()
|
||||||
message_no = "Already querried today: "
|
message_no = "Already querried today: "
|
||||||
message_yes = " Updated successfully: "
|
message_yes = " Updated successfully: "
|
||||||
|
count_raw_data = 0
|
||||||
for currency, rate in raw_data.items():
|
for currency, rate in raw_data.items():
|
||||||
if ExchangeRate.objects.filter(date=today, name=currency)[:1]:
|
count_raw_data += 1
|
||||||
|
if ExchangeRate_date.objects.filter(date__date=today) \
|
||||||
|
and ExchangeRate_name.objects.get(name=currency):
|
||||||
message_no += currency + ", "
|
message_no += currency + ", "
|
||||||
|
# A: https://stackoverflow.com/a/27802801/4061870
|
||||||
else:
|
else:
|
||||||
e = ExchangeRate.objects.create(
|
if ExchangeRate_date.objects.filter(date=today)[:1]:
|
||||||
name=currency,
|
try:
|
||||||
exchange_rate_to_chf=rate,
|
date_dict = ExchangeRate_date.objects.filter(date=today).values()
|
||||||
date=today
|
date = date_dict[0]['date']
|
||||||
)
|
date_id = date_dict[0]['id']
|
||||||
e.save()
|
except Exception as e:
|
||||||
message_yes += currency + ", "
|
print('date_dict %s (%s)' % (e, type(e)))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
exdate = ExchangeRate_date.objects.create(date=today)
|
||||||
|
exdate.save()
|
||||||
|
except Exception as e:
|
||||||
|
print('exdate %s (%s)' % (e, type(e)))
|
||||||
|
if ExchangeRate_name.objects.filter(name=currency)[:1]:
|
||||||
|
try:
|
||||||
|
name_dict = ExchangeRate_name.objects.get(name=currency)
|
||||||
|
name = name_dict[0]['name']
|
||||||
|
name_id = name_dict[0]['id']
|
||||||
|
except Exception as e:
|
||||||
|
print('exdate %s (%s)' % (e, type(e)))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
exname = ExchangeRate_name.objects.create(name=currency)
|
||||||
|
exname.save()
|
||||||
|
except Exception as e:
|
||||||
|
print('exname %s (%s)' % (e, type(e)))
|
||||||
|
try:
|
||||||
|
exrate = ExchangeRate.objects.create(
|
||||||
|
# name_id=name_id,
|
||||||
|
name_id=ExchangeRate_name.objects.only('id').get(name=currency).id,
|
||||||
|
# date_id=date_id,
|
||||||
|
date_id=ExchangeRate_date.objects.only('id').get(date=today).id,
|
||||||
|
exchange_rate_to_chf=rate,
|
||||||
|
)
|
||||||
|
exrate.save()
|
||||||
|
message_yes += currency + ", "
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print('exrate %s (%s)' % (e, type(e)))
|
||||||
|
|
||||||
# prepare messages:
|
# prepare messages:
|
||||||
message_no = message_no[::-1] # invert the string
|
message_no = message_no[::-1] # invert the string
|
||||||
|
@ -39,41 +75,42 @@ def currencies(request):
|
||||||
message = message_yes
|
message = message_yes
|
||||||
else:
|
else:
|
||||||
message = "something whent wrong"
|
message = "something whent wrong"
|
||||||
|
currency_list = ExchangeRate.objects.all()
|
||||||
# prepare data to be displayed in a html table:
|
# prepare data to be displayed in a html table:
|
||||||
# https://stackoverflow.com/questions/8749158/removing-duplicates-from-dictionary#8749473
|
# https://stackoverflow.com/questions/8749158/removing-duplicates-from-dictionary#8749473
|
||||||
# atomar_dates
|
# atomar_dates
|
||||||
# A: https://stackoverflow.com/questions/37205793/django-values-list-vs-values#37205928
|
# A: https://stackoverflow.com/questions/37205793/django-values-list-vs-values#37205928
|
||||||
# B: https://stackoverflow.com/questions/6521892/how-to-access-a-dictionary-key-value-present-inside-a-list
|
# B: https://stackoverflow.com/questions/6521892/how-to-access-a-dictionary-key-value-present-inside-a-list
|
||||||
unique_dates_list = ExchangeRate.objects.values_list('date', flat=True).distinct()
|
# dates_list = ExchangeRate_date.objects.values_list('date', flat=True)
|
||||||
# atomar_currenies
|
# # atomar_currenies
|
||||||
unique_currencies_list = ExchangeRate.objects.values_list('name', flat=True).distinct()
|
# currencies_list = ExchangeRate_name.objects.values_list('name', flat=True)
|
||||||
# search for currencies in a date and apend them to the list
|
# # search for currencies in a date and apend them to the list
|
||||||
currency_list = []
|
# currency_list = []
|
||||||
count_date = 0
|
# count_date = 0
|
||||||
count_currencies = 0
|
# count_currencies = 0
|
||||||
for unique_date in unique_dates_list:
|
# for date in dates_list:
|
||||||
count_date += 1
|
# count_date += 1
|
||||||
currency_dict = {}
|
# currency_dict = {}
|
||||||
currency_dict['date'] = unique_date
|
# currency_dict['date'] = date
|
||||||
for unique_currency in unique_currencies_list:
|
# for currency in currencies_list:
|
||||||
count_currencies += 1
|
# count_currencies += 1
|
||||||
try:
|
# try:
|
||||||
temp = ExchangeRate.objects.filter(date=unique_date, name=unique_currency).values() #A
|
# temp = ExchangeRate.objects.objects.only('exchange_rate_to_chf').get(name=currency).id
|
||||||
exchange_rate_to_chf = temp[0]['exchange_rate_to_chf']
|
# #temp = ExchangeRate.objects.filter(date=unique_date, name=currency).values() # A
|
||||||
currency_dict = currency_dict.update({unique_currency: exchange_rate_to_chf}) #B
|
# exchange_rate_to_chf = temp[0]['exchange_rate_to_chf']
|
||||||
except Exception as e:
|
# currency_dict = currency_dict.update({currency: exchange_rate_to_chf}) # B
|
||||||
print('%s (%s)' % (e, type(e)))
|
# except Exception as e:
|
||||||
currency_list.append(currency_dict)
|
# print('%s (%s)' % (e, type(e)))
|
||||||
assert False
|
# currency_list.append(currency_dict)
|
||||||
|
# assert False
|
||||||
return render(request,
|
return render(request,
|
||||||
'currencies/index.html',
|
'currencies/index.html',
|
||||||
{'currency_list': currency_list,
|
{'currency_list': currency_list,
|
||||||
'raw_data': raw_data,
|
'raw_data': raw_data,
|
||||||
'today': today,
|
'today': today,
|
||||||
'unique_dates_list': unique_dates_list,
|
# 'unique_dates_list': unique_dates_list,
|
||||||
'unique_currencies_list': unique_currencies_list,
|
# 'unique_currencies_list': unique_currencies_list,
|
||||||
'count_date': count_date,
|
'count_raw_data': count_raw_data,
|
||||||
'count_currencies': count_currencies,
|
# 'count_currencies': count_currencies,
|
||||||
'currency_dict': currency_dict,
|
# 'currency_dict': currency_dict,
|
||||||
'message': message})
|
'message': message})
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<title>CH: 1.3081 CHF = 1 GBP 2017-11-27 Tägliche Kurse (11:00)</title>
|
<title>CH: 1.3081 CHF = 1 GBP 2017-11-27 Tägliche Kurse (11:00)</title>
|
||||||
<link>https://www.snb.ch</link>
|
<link>https://www.snb.ch</link>
|
||||||
<description>1 GBP = 1.3081 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.767+01:00)</description>
|
<description>1 GBP = 1.3081 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.767+01:00)</description>
|
||||||
<dc:date>2018-01-02T12:16:53.767+01:00</dc:date>
|
<dc:date>2018-01-01T12:16:53.767+01:00</dc:date>
|
||||||
<dc:language>de</dc:language>
|
<dc:language>de</dc:language>
|
||||||
<cb:statistics rdf:parseType="Resource">
|
<cb:statistics rdf:parseType="Resource">
|
||||||
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
<title>CH: 0.8813 CHF = 100 JPY 2017-11-27 Tägliche Kurse (11:00)</title>
|
<title>CH: 0.8813 CHF = 100 JPY 2017-11-27 Tägliche Kurse (11:00)</title>
|
||||||
<link>https://www.snb.ch</link>
|
<link>https://www.snb.ch</link>
|
||||||
<description>100 JPY = 0.8813 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.760+01:00)</description>
|
<description>100 JPY = 0.8813 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.760+01:00)</description>
|
||||||
<dc:date>2018-01-02T12:16:53.760+01:00</dc:date>
|
<dc:date>2018-01-01T12:16:53.760+01:00</dc:date>
|
||||||
<dc:language>de</dc:language>
|
<dc:language>de</dc:language>
|
||||||
<cb:statistics rdf:parseType="Resource">
|
<cb:statistics rdf:parseType="Resource">
|
||||||
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
<title>CH: 1.1697 CHF = 1 EUR 2017-11-27 Tägliche Kurse (11:00)</title>
|
<title>CH: 1.1697 CHF = 1 EUR 2017-11-27 Tägliche Kurse (11:00)</title>
|
||||||
<link>https://www.snb.ch</link>
|
<link>https://www.snb.ch</link>
|
||||||
<description>1 EUR = 1.1697 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.750+01:00)</description>
|
<description>1 EUR = 1.1697 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.750+01:00)</description>
|
||||||
<dc:date>2018-01-02T12:16:53.750+01:00</dc:date>
|
<dc:date>2018-01-01T12:16:53.750+01:00</dc:date>
|
||||||
<dc:language>de</dc:language>
|
<dc:language>de</dc:language>
|
||||||
<cb:statistics rdf:parseType="Resource">
|
<cb:statistics rdf:parseType="Resource">
|
||||||
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
||||||
|
@ -125,7 +125,7 @@
|
||||||
<title>CH: 0.9803 CHF = 1 USD 2017-11-27 Tägliche Kurse (11:00)</title>
|
<title>CH: 0.9803 CHF = 1 USD 2017-11-27 Tägliche Kurse (11:00)</title>
|
||||||
<link>https://www.snb.ch</link>
|
<link>https://www.snb.ch</link>
|
||||||
<description>1 USD = 0.9803 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.737+01:00)</description>
|
<description>1 USD = 0.9803 CHF (Tägliche Kurse (11:00); 2017-11-27T12:16:53.737+01:00)</description>
|
||||||
<dc:date>2018-01-02T12:16:53.737+01:00</dc:date>
|
<dc:date>2018-01-01T12:16:53.737+01:00</dc:date>
|
||||||
<dc:language>de</dc:language>
|
<dc:language>de</dc:language>
|
||||||
<cb:statistics rdf:parseType="Resource">
|
<cb:statistics rdf:parseType="Resource">
|
||||||
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
<rdf:type rdf:resource="http://www.cbwiki.net/wiki/index.php/RSS-CB_1.2_RDF_Schema#Statistics"/>
|
||||||
|
|
Loading…
Reference in New Issue