def ParseMarket(self):
     BaseParser.ParseMarket(self)
     try:
         f = requests.get(self.download_url)
         workbook = xlrd.open_workbook(file_contents=f.content)
         worksheet = workbook.sheet_by_index(0)
         for row_idx in range(3, worksheet.nrows):
             row = worksheet.row(row_idx)
             market_symbol = {}
             market_symbol['code'] = row[0].value.strip() + '.HK'
             if market_symbol['code'][0] == '0':
                 market_symbol['code'] = market_symbol['code'][1:]
             market_symbol['name'] = row[1].value.strip()
             self.market_symbols.append(market_symbol)
     except Exception as e:
         print(e)
예제 #2
0
    def ParseMarket(self):
        BaseParser.ParseMarket(self)
        try:
            f = urllib.request.urlopen(self.download_url)
            csvfile = csv.reader(codecs.iterdecode(f, 'utf-8'))
            is_header = True
            for line in csvfile:
                if not line or len(line) < 2:
                    continue

                if is_header:
                    is_header = False
                    continue

                market_symbol = {}
                market_symbol['code'] = line[0].strip()
                market_symbol['name'] = line[1].strip()
                self.market_symbols.append(market_symbol)

        except Exception as e:
            print(e)