ServerPortfolio
2.0
Python parsers and server
|
Update data of a list of Stock's (only one action by call is possible). More...
Public Member Functions | |
def | __init__ |
Constructor. More... | |
def | set_option_post |
To set/unset the options b_save and b_interactive. More... | |
def | get_option_post |
Return a new dictionary with the option for post-processing. More... | |
def | update_xml |
def | get_string_data |
Update the stock(s) and return the data as multi lines string. More... | |
def | check_open |
Parse instantaneous value and check the stock is in state 'OPEN'. More... | |
Wrapper to DictionaryStocks functionalities | |
def | get_stocks |
Return a Stock (or a list of Stock) object(s) from a symbol (or a list of symbols). More... | |
def | print_dict_stocks |
Print one line strings of the data. More... | |
Public Attributes | |
e_action | |
b_save | |
Indicates if the new data must be saved into the file system, post-processing stage. More... | |
b_interactive | |
Set interactive mode, the user is required to accept / reject the update of data. More... | |
Static Public Attributes | |
tuple | t = threading.Thread(target=run_thread_pool_parser, args=(list_stock, self.e_action, option_post)) |
Private Member Functions | |
def | _set_parser |
Set or reset an action, a correct parser depending on the action. More... | |
def | _update_data |
Update stock(s) data according to the specified action. More... | |
Private Attributes | |
_logger | |
_myparser | |
_dictstocks | |
Link to the DictionaryStocks singleton. More... | |
_multithread | |
Allow multi-threading for executing _update_data. More... | |
Update data of a list of Stock's (only one action by call is possible).
This module allows to choose:
Create and store a appropriate parser object to query a web page and make the post-processing: validation/interactive mode, save_to_file/save_to_xml.
Re-use of the internal parser object needed only for Server, to improve.
Used mainly by the RunParser tool.
Used by C++, with simple arguments.
If optional argument easy to implement in C++, can be provided in constructor.
Definition at line 45 of file UpdateStocks.py.
def serverportfolio.UpdateStocks.UpdateStocks.__init__ | ( | self, | |
action, | |||
option_parser = None , |
|||
opt_multithread = False |
|||
) |
Constructor.
action | EAction or string of the action to perform, 'NoAction' will not initialise the internal parser. |
option_parser | (not implemented) |
option_multithread | if possible for the action, parsers are run in independent threads |
Definition at line 51 of file UpdateStocks.py.
|
private |
Set or reset an action, a correct parser depending on the action.
Try to re-use the same parser object if the same action is required.
If not possible, create a new one
Called from _update_data
action_name | string or EAction to execute |
Definition at line 116 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks._myparser, serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, and serverportfolio.Parsers.YahooCSV.YahooCSV.e_action.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().
|
private |
Update stock(s) data according to the specified action.
If a specific stock or list of stocks symbol is provided, the Stock object may be created on the fly
If the default None is used, only the Stock objects already loaded in the dictionary are used(option update_all may be added)
The function provides access to any action. if option save is set (by default) data are saved in their respective file. If multithread is required with action InstValue or HistPrice, a thread is created for each thread in this function.
Other post-processes (print, send data to gui_server) must be done by the caller
stock | symbol (or list of symbols) of the stock, default None update all stocks from the loaded Stocks (not all from config) |
action | string of the action, must be valid as defined in GlobalDicts.EAction. If None use the default specified in constructor. All cases check the parser is compatible with the action. |
opt_parser | option to use a specific parser(not implemented, use only the default one) |
Definition at line 157 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks._multithread, serverportfolio.UpdateStocks.UpdateStocks._myparser, serverportfolio.UpdateStocks.UpdateStocks._set_parser(), serverportfolio.UpdateStocks.UpdateStocks.b_interactive, serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, serverportfolio.Parsers.YahooCSV.YahooCSV.e_action, and serverportfolio.UpdateStocks.UpdateStocks.get_option_post().
Referenced by serverportfolio.UpdateStocks.UpdateStocks.check_open(), and serverportfolio.UpdateStocks.UpdateStocks.get_string_data().
def serverportfolio.UpdateStocks.UpdateStocks.check_open | ( | self, | |
stock | |||
) |
Parse instantaneous value and check the stock is in state 'OPEN'.
Called only at the start of AutoParser.
or may call _update_data from AutoParser, and then check with Stock get_state
stock | one unique stock symbol |
Definition at line 426 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks._update_data(), serverportfolio.UpdateStocks.UpdateStocks.get_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().
def serverportfolio.UpdateStocks.UpdateStocks.get_option_post | ( | self | ) |
Return a new dictionary with the option for post-processing.
An entry 'tk_manager' will be added only if needed (interactive/multithread) and supported by action
Definition at line 103 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks.b_interactive, and serverportfolio.UpdateStocks.UpdateStocks.b_save.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().
def serverportfolio.UpdateStocks.UpdateStocks.get_stocks | ( | self, | |
stock | |||
) |
Return a Stock (or a list of Stock) object(s) from a symbol (or a list of symbols).
May return InvalidStocks, wrapper to DictionaryStocks.get_stocks()
Definition at line 132 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks.check_open(), and serverportfolio.UpdateStocks.UpdateStocks.update_xml().
def serverportfolio.UpdateStocks.UpdateStocks.get_string_data | ( | self, | |
list_stock, | |||
action = None , |
|||
opt_header = False , |
|||
opt_parse = True |
|||
) |
Update the stock(s) and return the data as multi lines string.
Should work for all actions, print one line by stock.
Easy to call and parse from C++ or other scripts. Called by default by RunParsers.
list_stock | of the stock symbols |
action | |
opt_header | optional boolean, print a header before the data |
opt_parse | if True call an update of the data, if False only print values in memory |
Definition at line 407 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks._update_data(), serverportfolio.Parsers.Abstract.AbstractParser.e_action, serverportfolio.UpdateStocks.UpdateStocks.e_action, serverportfolio.Parsers.YahooYQL.YahooYQL.e_action, serverportfolio.Parsers.YahooCSV.YahooCSV.e_action, serverportfolio.UpdateStocks.UpdateStocks.print_dict_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.print_dict_stocks().
def serverportfolio.UpdateStocks.UpdateStocks.print_dict_stocks | ( | self, | |
action, | |||
input_stocks = None , |
|||
opt_all_stocks = False , |
|||
opt_header = False |
|||
) |
Print one line strings of the data.
Definition at line 137 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks.get_string_data().
def serverportfolio.UpdateStocks.UpdateStocks.set_option_post | ( | self, | |
bool_save = True , |
|||
bool_interactive = False |
|||
) |
To set/unset the options b_save and b_interactive.
bool_save | boolean to set/unset the option to save to file. |
bool_interactive | to set/unset the interative mode |
Definition at line 96 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks.b_interactive, and serverportfolio.UpdateStocks.UpdateStocks.b_save.
def serverportfolio.UpdateStocks.UpdateStocks.update_xml | ( | self, | |
stock | |||
) |
Definition at line 362 of file UpdateStocks.py.
References serverportfolio.UpdateStocks.UpdateStocks.b_interactive, serverportfolio.UpdateStocks.UpdateStocks.get_stocks(), and serverportfolio.DictionaryStocks.DictionaryStocks.get_stocks().
|
private |
Link to the DictionaryStocks singleton.
Could pass the option load_all_stocks if created from here...
Definition at line 82 of file UpdateStocks.py.
|
private |
Definition at line 63 of file UpdateStocks.py.
|
private |
Allow multi-threading for executing _update_data.
Definition at line 85 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data().
|
private |
Definition at line 73 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._set_parser(), and serverportfolio.UpdateStocks.UpdateStocks._update_data().
serverportfolio.UpdateStocks.UpdateStocks.b_interactive |
Set interactive mode, the user is required to accept / reject the update of data.
Definition at line 91 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._update_data(), serverportfolio.UpdateStocks.UpdateStocks.get_option_post(), serverportfolio.UpdateStocks.UpdateStocks.set_option_post(), and serverportfolio.UpdateStocks.UpdateStocks.update_xml().
serverportfolio.UpdateStocks.UpdateStocks.b_save |
Indicates if the new data must be saved into the file system, post-processing stage.
Apply to all types : 'csv' and 'xml'
Default is True, for debugging/testing may need to set to False
Definition at line 89 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks.get_option_post(), and serverportfolio.UpdateStocks.UpdateStocks.set_option_post().
serverportfolio.UpdateStocks.UpdateStocks.e_action |
Definition at line 68 of file UpdateStocks.py.
Referenced by serverportfolio.UpdateStocks.UpdateStocks._set_parser(), serverportfolio.UpdateStocks.UpdateStocks._update_data(), and serverportfolio.UpdateStocks.UpdateStocks.get_string_data().
|
static |
Definition at line 213 of file UpdateStocks.py.