diff --git a/caotek_mesavoirs/models/actifs.py b/caotek_mesavoirs/models/actifs.py index c38cc92..f4953ad 100644 --- a/caotek_mesavoirs/models/actifs.py +++ b/caotek_mesavoirs/models/actifs.py @@ -10,6 +10,8 @@ from zope.sqlalchemy import ZopeTransactionExtension, mark_changed from datetime import * import transaction +from bs4 import BeautifulSoup +import urllib2 from .default import ( execute_query, @@ -139,3 +141,34 @@ def delete_histo(request, no_id): query = "DELETE FROM histo WHERE no_id = :no_id ;" execute_query(request, query, {'no_id': no_id}) +def getCurrencyRate(currency): + # specify the url + quote_page = 'http://www.finances.net/devises/courseuro' + + # query & parse the html using beautiful soap and store in variable `soup` + soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser') + # get the history table + rows = soup.find('table', attrs={'class': 'news_table'}).tbody.findAll('tr') + divs = rows[1].findAll('td') + rate = divs[1].span.text + return float(rate.replace(',','.')) + +def getYahooQuote(ticker): + # specify the url + quote_page = 'https://finance.yahoo.com/quote/%s/history/' % ticker + + # query & parse the html using beautiful soap and store in variable `soup` + soup = BeautifulSoup(urllib2.urlopen(quote_page), 'html.parser') + data = [] + # get the quote price + rows = soup.findAll('table')[0].tbody.findAll('tr') + for each_row in rows: + divs = each_row.findAll('td') + if divs[1].span.text != 'Dividend': #Ignore this row in the table + #I'm only interested in 'Close' price; + data.append({'Date': divs[0].span.text, 'Close': float(divs[5].span.text.replace(',',''))}) + break + + # retourne la prière ligne + return data[0] + diff --git a/caotek_mesavoirs/routes.py b/caotek_mesavoirs/routes.py index 48f402b..a605d28 100644 --- a/caotek_mesavoirs/routes.py +++ b/caotek_mesavoirs/routes.py @@ -5,7 +5,6 @@ def includeme(config): config.add_route('doc_list', '/doc_list') config.add_route('doc_view', '/doc_view/{doc_id}') # actifs - config.add_route('actifs_list', '/actifs_list') config.add_route('actif_edit', '/actif_edit/{no_id}') config.add_route('actif2_edit', '/actif2_edit/{no_id}') config.add_route('allocation_list', '/allocation_list') diff --git a/caotek_mesavoirs/templates/actifs/actif2_edit.pt b/caotek_mesavoirs/templates/actifs/actif2_edit.pt index 0e4f2e5..023992b 100644 --- a/caotek_mesavoirs/templates/actifs/actif2_edit.pt +++ b/caotek_mesavoirs/templates/actifs/actif2_edit.pt @@ -80,7 +80,7 @@
| Classe | -Symbole | -Libellé | -Nombre | -PRU | -Cours | -Valeur | -+/- Valeur | -% de +/- | -% PF | -- | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ${ligne.classe} | -${ligne.symbole} | -${ligne.libelle} | -${ligne.libelle} | -${ligne.nombre} | -${layout.to_euro(ligne.pru)} | -${ligne.cours} | -${layout.to_euro(ligne.valeur)} | -${layout.to_euro(ligne.plus_value)} | -${layout.to_euro(ligne.plus_value)} | -${layout.to_percent(ligne.pc_plusvalue, 1)} | -${layout.to_percent(ligne.pc_plusvalue, 1)} | -${ligne.pc_allocation} % | -- | - |
| Total | -${layout.to_euro(total_valeur)} | -${layout.to_euro(total_pv)} | -${layout.to_percent(total_pc_value, 1)} | -100.0 % | -||||||||||
"Diversification is not determined by the number of securities held." Larry Swedroe
+ + +| % Rdt | % PF | TER | +|||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ${ligne.classe} | -${ligne.libelle} | +${ligne.libelle} | +${ligne.libelle} | ${layout.to_euro(ligne.valeur)} | ${layout.to_euro(ligne.plus_value)} | ${layout.to_euro(ligne.plus_value)} | @@ -100,6 +114,8 @@${layout.to_percent(ligne.pc_rdt,1)} | ${ligne.pc_allocation} % | ${layout.to_percent(ligne.ter,2)} | ++ | |
| Total | @@ -122,7 +138,38 @@|||||||||||