asset/onlinesource: add fixed url,
pre defned online sources: add FAZ.net
This commit is contained in:
parent
edfa0424e5
commit
82f9d3a792
8 changed files with 120 additions and 13 deletions
26
asset.py
26
asset.py
|
@ -8,6 +8,7 @@ from trytond.transaction import Transaction
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.pyson import Eval, Bool, If, Date
|
from trytond.pyson import Eval, Bool, If, Date
|
||||||
from trytond.report import Report
|
from trytond.report import Report
|
||||||
|
from trytond.exceptions import UserError
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from datetime import time
|
from datetime import time
|
||||||
|
@ -84,8 +85,19 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
help='Select sources for the course update. The course sources are tried until a valid value has been read.',
|
help='Select sources for the course update. The course sources are tried until a valid value has been read.',
|
||||||
relation_name='investment.asset_source_rel',
|
relation_name='investment.asset_source_rel',
|
||||||
origin='asset', target='source')
|
origin='asset', target='source')
|
||||||
updtdays = fields.Selection(string='Select days', required=True,
|
updturl = fields.Char(
|
||||||
selection=sel_updtdays)
|
string='URL',
|
||||||
|
help='URL for data retrieval.',
|
||||||
|
states={
|
||||||
|
'invisible': Eval('updturl_enable', False) == False,
|
||||||
|
'required': Eval('updturl_enable', False) == True,
|
||||||
|
}, depends=['updturl_enable'])
|
||||||
|
updturl_enable = fields.Function(fields.Boolean(
|
||||||
|
string='URL required', readonly=True,
|
||||||
|
states={'invisible': True}),
|
||||||
|
'on_change_with_updturl_enable')
|
||||||
|
updtdays = fields.Selection(
|
||||||
|
string='Select days', required=True, selection=sel_updtdays)
|
||||||
updttime = fields.Time(string='Time',
|
updttime = fields.Time(string='Time',
|
||||||
states={
|
states={
|
||||||
'readonly': ~Bool(Eval('updtsources')),
|
'readonly': ~Bool(Eval('updtsources')),
|
||||||
|
@ -206,6 +218,16 @@ class Asset(SymbolMixin, ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
return 'work'
|
return 'work'
|
||||||
|
|
||||||
|
@fields.depends('updtsources')
|
||||||
|
def on_change_with_updturl_enable(self, name=None):
|
||||||
|
""" return True if a source has fixed-url
|
||||||
|
"""
|
||||||
|
if self.updtsources:
|
||||||
|
for usource in self.updtsources:
|
||||||
|
if usource.fixed_url == True:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@fields.depends('updtsources', 'updttime')
|
@fields.depends('updtsources', 'updttime')
|
||||||
def on_change_updtsources(self):
|
def on_change_updtsources(self):
|
||||||
""" clear time-fields
|
""" clear time-fields
|
||||||
|
|
24
locale/de.po
24
locale/de.po
|
@ -46,6 +46,10 @@ msgctxt "model:ir.message,text:msg_querytype_web"
|
||||||
msgid "Extract from web page"
|
msgid "Extract from web page"
|
||||||
msgstr "aus Webseite auslesen"
|
msgstr "aus Webseite auslesen"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_missing_url"
|
||||||
|
msgid "URL for the online source '%(oname)s' is missing."
|
||||||
|
msgstr "URL für die Onlinequelle '%(oname)s' fehlt."
|
||||||
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# ir.ui.menu #
|
# ir.ui.menu #
|
||||||
|
@ -330,6 +334,18 @@ msgctxt "selection:investment.asset,updtdays:"
|
||||||
msgid "Mon - Sun"
|
msgid "Mon - Sun"
|
||||||
msgstr "Mo - So"
|
msgstr "Mo - So"
|
||||||
|
|
||||||
|
msgctxt "field:investment.asset,updturl:"
|
||||||
|
msgid "URL"
|
||||||
|
msgstr "URL"
|
||||||
|
|
||||||
|
msgctxt "help:investment.asset,updturl:"
|
||||||
|
msgid "URL for data retrieval."
|
||||||
|
msgstr "URL für Datenabruf."
|
||||||
|
|
||||||
|
msgctxt "field:investment.asset,updturl_enable:"
|
||||||
|
msgid "URL required"
|
||||||
|
msgstr "URL required"
|
||||||
|
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
# investment.asset-source-rel #
|
# investment.asset-source-rel #
|
||||||
|
@ -530,6 +546,14 @@ msgctxt "help:investment.source,query_method:"
|
||||||
msgid "Select the method to retrieve the data."
|
msgid "Select the method to retrieve the data."
|
||||||
msgstr "Wählen Sie die Methode zum Abruf der Daten."
|
msgstr "Wählen Sie die Methode zum Abruf der Daten."
|
||||||
|
|
||||||
|
msgctxt "field:investment.source,fixed_url:"
|
||||||
|
msgid "Fixed URL"
|
||||||
|
msgstr "feste URL"
|
||||||
|
|
||||||
|
msgctxt "help:investment.source,fixed_url:"
|
||||||
|
msgid "URL must be defined at investment record."
|
||||||
|
msgstr "Die URL muss im Investitionsdatensatz definiert werden."
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# investment.rate #
|
# investment.rate #
|
||||||
|
|
12
locale/en.po
12
locale/en.po
|
@ -34,6 +34,10 @@ msgctxt "model:ir.message,text:msg_querytype_web"
|
||||||
msgid "Extract from web page"
|
msgid "Extract from web page"
|
||||||
msgstr "Extract from web page"
|
msgstr "Extract from web page"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_missing_url"
|
||||||
|
msgid "URL for the online source '%(oname)s' is missing."
|
||||||
|
msgstr "URL for the online source '%(oname)s' is missing."
|
||||||
|
|
||||||
msgctxt "model:ir.ui.menu,name:menu_investment"
|
msgctxt "model:ir.ui.menu,name:menu_investment"
|
||||||
msgid "Investment"
|
msgid "Investment"
|
||||||
msgstr "Investment"
|
msgstr "Investment"
|
||||||
|
@ -482,6 +486,14 @@ msgctxt "help:investment.source,query_method:"
|
||||||
msgid "Select the method to retrieve the data."
|
msgid "Select the method to retrieve the data."
|
||||||
msgstr "Select the method to retrieve the data."
|
msgstr "Select the method to retrieve the data."
|
||||||
|
|
||||||
|
msgctxt "field:investment.source,fixed_url:"
|
||||||
|
msgid "Fixed URL"
|
||||||
|
msgstr "Fixed URL"
|
||||||
|
|
||||||
|
msgctxt "help:investment.source,fixed_url:"
|
||||||
|
msgid "URL must be defined at investment record."
|
||||||
|
msgstr "URL must be defined at investment record."
|
||||||
|
|
||||||
msgctxt "model:investment.rate,name:"
|
msgctxt "model:investment.rate,name:"
|
||||||
msgid "Rate"
|
msgid "Rate"
|
||||||
msgstr "Rate"
|
msgstr "Rate"
|
||||||
|
|
|
@ -20,6 +20,9 @@ full copyright notices and license terms. -->
|
||||||
<record model="ir.message" id="msg_querytype_web">
|
<record model="ir.message" id="msg_querytype_web">
|
||||||
<field name="text">Extract from web page</field>
|
<field name="text">Extract from web page</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="ir.message" id="msg_missing_url">
|
||||||
|
<field name="text">URL for the online source '%(oname)s' is missing.</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -14,6 +14,7 @@ from trytond.model import ModelView, ModelSQL, fields
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.pyson import Eval, Bool
|
from trytond.pyson import Eval, Bool
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
|
from trytond.exceptions import UserError
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,6 +61,12 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
help='Select the method to retrieve the data.',
|
help='Select the method to retrieve the data.',
|
||||||
selection='get_query_methods')
|
selection='get_query_methods')
|
||||||
url = fields.Char(string='URL', states=STATES_WEB, depends=DEPENDS_WEB)
|
url = fields.Char(string='URL', states=STATES_WEB, depends=DEPENDS_WEB)
|
||||||
|
fixed_url = fields.Boolean(
|
||||||
|
string='Fixed URL',
|
||||||
|
states={
|
||||||
|
'invisible': Eval('query_method', '') != 'web',
|
||||||
|
}, depends=DEPENDS_WEB,
|
||||||
|
help='URL must be defined at investment record.')
|
||||||
nohtml = fields.Boolean(
|
nohtml = fields.Boolean(
|
||||||
string='Remove HTML',
|
string='Remove HTML',
|
||||||
help='Removes HTML tags before the text is interpreted.',
|
help='Removes HTML tags before the text is interpreted.',
|
||||||
|
@ -178,6 +185,12 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def default_fixed_url(cls):
|
||||||
|
""" default: False
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
@fields.depends(*fields_check)
|
@fields.depends(*fields_check)
|
||||||
def on_change_nsin(self):
|
def on_change_nsin(self):
|
||||||
""" run request
|
""" run request
|
||||||
|
@ -220,7 +233,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
def on_change_with_symbol(self, name=None):
|
def on_change_with_symbol(self, name=None):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@fields.depends('url', 'isin', 'nsin', 'symbol')
|
@fields.depends('url', 'isin', 'nsin', 'symbol', 'fixed_url')
|
||||||
def on_change_with_used_url(self, name=None):
|
def on_change_with_used_url(self, name=None):
|
||||||
""" get url for testing
|
""" get url for testing
|
||||||
"""
|
"""
|
||||||
|
@ -229,6 +242,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
isin=self.isin,
|
isin=self.isin,
|
||||||
nsin=self.nsin,
|
nsin=self.nsin,
|
||||||
symbol=self.symbol,
|
symbol=self.symbol,
|
||||||
|
url=self.url,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -246,7 +260,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_query_method(cls, osource, isin, nsin, symbol, debug=False):
|
def run_query_method(cls, osource, isin, nsin, symbol, url, debug=False):
|
||||||
""" run selected query to retrive data
|
""" run selected query to retrive data
|
||||||
result: {
|
result: {
|
||||||
'text': raw-text from query - for debug,
|
'text': raw-text from query - for debug,
|
||||||
|
@ -265,6 +279,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
nsin=nsin,
|
nsin=nsin,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
debug=debug,
|
debug=debug,
|
||||||
|
url=url,
|
||||||
)
|
)
|
||||||
|
|
||||||
def call_online_source(self):
|
def call_online_source(self):
|
||||||
|
@ -274,7 +289,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
OSourc = Pool().get('investment.source')
|
OSourc = Pool().get('investment.source')
|
||||||
|
|
||||||
result = OSourc.run_query_method(
|
result = OSourc.run_query_method(
|
||||||
self, self.isin, self.nsin,
|
self, self.isin, self.nsin, self.url,
|
||||||
self.symbol, debug=True)
|
self.symbol, debug=True)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
self.text = result.get('text', None)
|
self.text = result.get('text', None)
|
||||||
|
@ -283,15 +298,24 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
self.fndrate = result.get('rate', None)
|
self.fndrate = result.get('rate', None)
|
||||||
self.fndident = result.get('code', None)
|
self.fndident = result.get('code', None)
|
||||||
|
|
||||||
def get_url_with_parameter(self, isin=None, nsin=None, symbol=None):
|
def get_url_with_parameter(
|
||||||
|
self, isin=None, nsin=None, symbol=None, url=None):
|
||||||
""" generate url
|
""" generate url
|
||||||
"""
|
"""
|
||||||
if self.url:
|
if self.fixed_url is True:
|
||||||
return Template(self.url).substitute({
|
if url is None:
|
||||||
'isin': isin if isin is not None else '',
|
raise UserError(gettext(
|
||||||
'nsin': nsin if nsin is not None else '',
|
'investment.msg_missing_url',
|
||||||
'symbol': symbol if symbol is not None else '',
|
oname=self.rec_name,
|
||||||
})
|
))
|
||||||
|
return url
|
||||||
|
else :
|
||||||
|
if self.url:
|
||||||
|
return Template(self.url).substitute({
|
||||||
|
'isin': isin if isin is not None else '',
|
||||||
|
'nsin': nsin if nsin is not None else '',
|
||||||
|
'symbol': symbol if symbol is not None else '',
|
||||||
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_rate(cls, asset):
|
def update_rate(cls, asset):
|
||||||
|
@ -310,6 +334,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
isin=asset.isin,
|
isin=asset.isin,
|
||||||
nsin=asset.wkn,
|
nsin=asset.wkn,
|
||||||
symbol=asset.secsymb,
|
symbol=asset.secsymb,
|
||||||
|
url=asset.updturl,
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(updtsource.rgxident or '') > 0:
|
if len(updtsource.rgxident or '') > 0:
|
||||||
|
@ -387,7 +412,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
@classmethod
|
@classmethod
|
||||||
def read_from_website(
|
def read_from_website(
|
||||||
cls, updtsource, isin=None, nsin=None,
|
cls, updtsource, isin=None, nsin=None,
|
||||||
symbol=None, debug=False):
|
symbol=None, url=None, debug=False):
|
||||||
""" read from url, extract values
|
""" read from url, extract values
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -401,6 +426,7 @@ class OnlineSource(ModelSQL, ModelView):
|
||||||
isin=isin,
|
isin=isin,
|
||||||
nsin=nsin,
|
nsin=nsin,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
|
url=url,
|
||||||
),
|
),
|
||||||
allow_redirects=True,
|
allow_redirects=True,
|
||||||
timeout=5.0)
|
timeout=5.0)
|
||||||
|
|
|
@ -78,6 +78,18 @@ full copyright notices and license terms. -->
|
||||||
<field name="rgxident">\nWKN / ISIN: [A-Z,0-9]+ / ([A-Z,0-9]+)\s+\n</field>
|
<field name="rgxident">\nWKN / ISIN: [A-Z,0-9]+ / ([A-Z,0-9]+)\s+\n</field>
|
||||||
<field name="rgxidtype">isin</field>
|
<field name="rgxidtype">isin</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="investment.source" id="web_faz">
|
||||||
|
<field name="name">FAZ</field>
|
||||||
|
<field name="url">https://www.faz.net/aktuell/finanzen/kurs/etf/</field>
|
||||||
|
<field name="nohtml" eval="True"/>
|
||||||
|
<field name="fixed_url" eval="True"/>
|
||||||
|
<field name="rgxdate">(\d{2}\.\d{2}\.\d{4})</field>
|
||||||
|
<field name="rgxdatefmt">%d.%m.%y</field>
|
||||||
|
<field name="rgxrate">\nKurs(\d+.\d+)\s+€\s+\n</field>
|
||||||
|
<field name="rgxdecimal">,</field>
|
||||||
|
<field name="rgxident">\nWKN:.*\sISIN: ([A-Z,0-9]+).*\n</field>
|
||||||
|
<field name="rgxidtype">isin</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -60,6 +60,11 @@ full copyright notices and license terms. -->
|
||||||
<label name="updtdays"/>
|
<label name="updtdays"/>
|
||||||
<field name="updtdays"/>
|
<field name="updtdays"/>
|
||||||
|
|
||||||
|
<label name="updturl"/>
|
||||||
|
<field name="updturl" colspan="3"/>
|
||||||
|
<field name="updturl_enable"/>
|
||||||
|
<newline/>
|
||||||
|
|
||||||
<field name="updtsources" colspan="4"/>
|
<field name="updtsources" colspan="4"/>
|
||||||
</page>
|
</page>
|
||||||
</notebook>
|
</notebook>
|
||||||
|
|
|
@ -14,9 +14,12 @@ full copyright notices and license terms. -->
|
||||||
<field name="url" colspan="3"/>
|
<field name="url" colspan="3"/>
|
||||||
<label name="nohtml"/>
|
<label name="nohtml"/>
|
||||||
<field name="nohtml"/>
|
<field name="nohtml"/>
|
||||||
|
|
||||||
<label id="labtp1" string=" "/>
|
<label id="labtp1" string=" "/>
|
||||||
<label xalign="0.0" colspan="3" name="nohtml"
|
<label xalign="0.0" colspan="3" name="nohtml"
|
||||||
string="URL parameter placeholders: ${isin}, ${nsin}, ${symbol}"/>
|
string="URL parameter placeholders: ${isin}, ${nsin}, ${symbol}"/>
|
||||||
|
<label name="fixed_url"/>
|
||||||
|
<field name="fixed_url"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
|
|
||||||
<separator colspan="6" name="url" string="Regular expressions to find data"/>
|
<separator colspan="6" name="url" string="Regular expressions to find data"/>
|
||||||
|
|
Loading…
Reference in a new issue