9 from abc
import ABCMeta, abstractmethod
13 from serverportfolio
import GlobalDicts
15 from serverportfolio
import Utils
30 __metaclass__ = ABCMeta
83 self.logger.debug(
"run_parser stock: %s", Utils.to_list( stock ) )
85 if option_post !=
None:
87 self.logger.debug(
'option_post is present: %s' % option_post)
95 self.logger.debug(
"No valid Stock after store_stock_copy")
97 except Exception
as ex:
98 self.logger.debug(
"Caught Exception in store_stock_copy: ex", ex)
101 self.logger.debug(
"\n== create_url")
105 except Exception
as ex:
106 self.logger.debug(
"Caught Exception in create_url: %s", ex)
111 self.logger.debug(
"\n== web_query")
113 s = UtilsParsers.web_query( self.
url )
114 except Exception
as ex:
115 self.logger.error(
"Got a general Exception from web_query %s" % ex )
120 self.logger.debug(
"\n== parse the page")
125 self.logger.error(
"run_parser() catch a ParserError")
128 except PortfolioError
as ex:
129 self.logger.error(
"run_parser() catch a PortfolioError: %s", ex)
133 except Exception
as ex :
135 self.logger.error(
"Catch exception in run_parser from parse(): %s " % ex)
136 raise ParserError(
'ParserError from myparser.parse(): ' + str(ex), stock, self.e_action.name, self.
url )
141 self.logger.debug(
"\n== update the stock(s)")
146 self.logger.debug(
"\n== clean parser for re-use")
164 self.logger.debug(
"Entry store_stock_copy")
165 self.logger.debug(
"list_stock: %s" % list_stock)
170 for elem
in Stock.to_list(list_obj_stocks):
172 if ( isinstance(elem, InvalidStock) ==
False ):
178 self.logger.debug(
"local_stock %s" % self.
local_stock)
184 self.logger.debug(
"Entry update_stock")
189 for elem
in list_dict:
190 symbol = elem[
'symbol']
191 self.
local_stock[ symbol ].add_dict_stock( elem[
'action_templ'], self.source )
193 print "\n== After add_dict_stok"
199 if hasattr(self,
'option_post'):
200 print "option_post present"
203 print "option_post not present"
212 self.logger.debug(
"get_symbol_from_code: %s" % code )
213 assert( ( code_type ==
'code_yahoo') | (code_type ==
'code_bourso') ),\
214 "Error in argument for code_type: %s" % code_type
216 for key, value
in self.local_stock.iteritems():
217 if value.get_action(
'Static',code_type) == code:
218 self.logger.debug(
"return symbol: %s" % key)
221 raise ParserError(
"Cannot retrieve symbol from '%s': %s" %(code_type, code), \
222 self.local_stock.keys(), self.e_action.name, self.
url)
def clean
Reset internal data members after a parsing.
def run_parser
Main function to call for running the parser.
e_action
enumeration (EAction) of the type of query to perform
def store_stock_copy
Make a local copy of the Stock objects (linked of the original in DictionaryStocks in fact) into a lo...
Define 2 abstract methods which need to be overridden by the Parsers and a generic algorithm (run_pa...
Define custom and specific exceptions for the complete package.
Derived class specific to the parsers.
def get_symbol_from_code
Retrieve the symbol (or Stock) from the code_yahoo or code_bourso.
Container of all Stocks objects, it also reads the static stocks configuration file "dictstocks...
Define the classes Stock and InvalidStock.
Global variables for configuration: paths, TCP ports and generic definitions.
def parse
Parse the text file (html, CSV,...)
url
save url, useful for reporting errors and exceptions
def update_stock
Update the local stocks with the new retrieved data.
def create_url
Store links to stocks to update, dictionary 'symbol' : Stock object.
Define singleton class DictionaryStocks, act as the main container of Stocks objects.