<s> """<STR_LIT>""" <EOL> import sys <EOL> sys . path . append ( "<STR_LIT>" ) <EOL> import pyalgotrade . logger <EOL> import lxml . html <EOL> import symbolsxml <EOL> logger = pyalgotrade . logger . getLogger ( "<STR_LIT>" ) <EOL> TICKER_SYMBOL_COL = <NUM_LIT:0> <EOL> COMPANY_COL = <NUM_LIT:1> <EOL> GICS_COL = <NUM_LIT:3> <EOL> GICS_SUB_INDUSTRY_COL = <NUM_LIT:4> <EOL> def get_html ( ) : <EOL> logger . info ( "<STR_LIT>" ) <EOL> ret = lxml . html . parse ( "<STR_LIT>" ) <EOL> return ret <EOL> def find_table ( htmlTree ) : <EOL> logger . info ( "<STR_LIT>" ) <EOL> ret = None <EOL> tables = htmlTree . xpath ( "<STR_LIT>" ) <EOL> for table in tables : <EOL> headers = table . xpath ( "<STR_LIT>" ) <EOL> if len ( headers ) > <NUM_LIT:5> : <EOL> if headers [ TICKER_SYMBOL_COL ] . xpath ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . text != "<STR_LIT>" : <EOL> continue <EOL> if headers [ COMPANY_COL ] . text != "<STR_LIT>" : <EOL> continue <EOL> if headers [ GICS_COL ] . xpath ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . text != "<STR_LIT>" : <EOL> continue <EOL> if headers [ GICS_SUB_INDUSTRY_COL ] . text != "<STR_LIT>" : <EOL> continue <EOL> ret = table <EOL> break <EOL> return ret <EOL> def parse_results ( table ) : <EOL> ret = symbolsxml . Writer ( ) <EOL> logger . info ( "<STR_LIT>" ) <EOL> rows = table . xpath ( "<STR_LIT>" ) <EOL> for row in rows [ <NUM_LIT:1> : ] : <EOL> cols = row . xpath ( "<STR_LIT>" ) <EOL> tickerSymbol = cols [ TICKER_SYMBOL_COL ] . xpath ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . text <EOL> company = cols [ COMPANY_COL ] . xpath ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . text <EOL> gics = cols [ GICS_COL ] . text <EOL> gicsSubIndustry = cols [ GICS_SUB_INDUSTRY_COL ] . text <EOL> if gicsSubIndustry is None : <EOL> gicsSubIndustry = "<STR_LIT>" <EOL> ret . addStock ( tickerSymbol , company , gics , gicsSubIndustry ) <EOL> return ret <EOL> def main ( ) : <EOL> try : <EOL> htmlTree = get_html ( ) <EOL> table = find_table ( htmlTree ) <EOL> if table is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> symbolsXML = parse_results ( table ) <EOL> logger . info ( "<STR_LIT>" ) <EOL> symbolsXML . write ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> logger . error ( str ( e ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
