31 import logging, argparse
160 main_logger.debug(
"send_to_server server_running %s" % server_running)
164 print "server running call it directly"
165 print 'method ', method
173 str +=
' '.join(stock
for stock
in list_stock)
180 print "str in CallGET ", str
181 received = SocketServer_Client.SendData( str )
187 print "server not running call parsers"
188 main_logger.debug(
"server not running call parsers")
195 received += update_stock.get_string_data( list_stock, opt_header = header)
211 print "Entry CallYahooCSV"
212 print "action ", action
213 print "stock ", stock
224 received = SocketServer_Client.SendData( str )
228 parserstocks = ParserStocks( stock, source )
232 if action ==
'LAST_CSV_UPDATE' :
233 time_t = parserstocks.LastCSV()
238 elif action ==
'UPDATE_CSV' :
239 received = parserstocks.UpdateCSV()
242 elif action ==
'INTRO' :
244 time_t = parserstocks.GetDateYIntro()
245 print "time_t", time_t
255 arg_parser = argparse.ArgumentParser(description=
"Main executable for parsing data from web page")
258 arg_parser.add_argument(
"-stock", dest=
"list_stock", required=
False, nargs=
'+', help=
"The list of stock symbol to update")
261 arg_parser.add_argument(
"-method", dest=
"method",required=
True, \
262 help=
'method GET / FORCE / UPDATE_CSV / TEST_SERVER')
265 arg_parser.add_argument(
"-a",
"--action", \
266 help=
"Action to perform, available: EAction")
269 arg_parser.add_argument(
'-v',
'--verbose', dest=
'verbose', action=
'store_true', default=
"False",\
270 help=
'Set logging to debug mode, otherwise error/critical mode activated by default')
273 arg_parser.set_defaults(verbose=
False)
276 option = arg_parser.parse_args()
281 print "option.verbose", option.verbose
285 logging.basicConfig(level=logging.DEBUG)
287 logging.basicConfig(level=logging.ERROR)
293 logger = logging.getLogger(
'SP')
294 main_logger = logging.getLogger(
"SP.run_parser")
296 main_logger.debug(
"Main Run_Parsers")
297 main_logger.debug(
"OK, list_stock: %s" % option.list_stock)
298 main_logger.debug(
"method : %s" % option.method)
299 main_logger.debug(
"action : %s" % option.action)
300 main_logger.debug(
"option.verbose : %s" % option.verbose)
303 server_running = SocketServer_Client.Connect()
304 main_logger.debug(
"server_running: %s", server_running)
309 if option.method ==
'TEST_SERVER' :
310 if server_running ==
False :
317 elif option.method ==
'RELOAD' :
318 print "RELOAD to implement"
329 except PortfolioError
as ex:
330 print "Caught PortfolioError in RunParser"
331 print "ex: ", ex.get_format_string()
336 main_logger.debug(
"final output")
Define class UpdateStocks and ParserFactory.
def CallYahooCSV
Make calls to YahooAPI module.
To communicate with the server.
Define custom and specific exceptions for the complete package.
Update data of a list of Stock's (only one action by call is possible).
def send_to_server
Get the last instantaneous data of the list of stocks.