def __init__(self, stock_no, data_num = 75, debug=0):
    """ stock_no: Stock no.
        data_num: Default fetch numbers. (Default is 75)
        debug: For debug to print some info about data solution. (Default is 0)

        stock_no: 股票代碼。
        data_num: 預設抓取的筆數（交易日數，預設為 75 筆）
        debug: 除錯用，列印出相關除錯資訊。0:關閉（預設） 1:開啟

        property:
          self.raw_data = [list]    收盤資訊，[舊→新]
          self.stock_name = str()   該股票名稱
          self.stock_no = str()     該股票代號
          self.data_date = [list]   日期資訊，[舊→新]
          self.stock_range = [list] 漲跌幅
          self.stock_vol = [list]   成交量
          self.stock_open = [list]  開盤價
          self.stock_h = [list]     最高價
          self.stock_l = [list]     最低價
    """
    self.raw_data = []
    self.stock_name = ''
    self.stock_no = stock_no
    self.data_date = []
    self.stock_range = []
    self.stock_vol = []
    self.stock_open = []
    self.stock_h = []
    self.stock_l = []
    starttime = 0
    self.debug = debug

    try:
      while len(self.raw_data) < data_num:
        # start fetch data.
        self.csv_read = self.fetch_data(stock_no, datetime.today() - timedelta(days = 30 * starttime), starttime)
        try:
          result = self.list_data(self.csv_read)
        except:
          # In first day of months will fetch no data.
          if starttime == 0:
            starttime += 1
            self.csv_read = self.fetch_data(stock_no, datetime.today() - timedelta(days = 30 * starttime), starttime)
            result = self.list_data(self.csv_read)
          logging.info('In first day of months %s' % stock_no)

        self.raw_data = result['stock_price'] + self.raw_data
        self.data_date = result['data_date'] + self.data_date
        self.stock_name = result['stock_name']
        self.stock_range = result['stock_range'] + self.stock_range
        self.stock_vol = result['stock_vol'] + self.stock_vol
        self.stock_open = result['stock_open'] + self.stock_open
        self.stock_h = result['stock_h'] + self.stock_h
        self.stock_l = result['stock_l'] + self.stock_l
        starttime += 1
    except:
      logging.info('Data not enough! %s' % stock_no)

    logging.info('Fetch %s' % stock_no)
def __init__ ( self , stock_no , data_num = 75 , debug = 0 ) : self . raw_data = [ ] self . stock_name = '' self . stock_no = stock_no self . data_date = [ ] self . stock_range = [ ] self . stock_vol = [ ] self . stock_open = [ ] self . stock_h = [ ] self . stock_l = [ ] starttime = 0 self . debug = debug try : while len ( self . raw_data ) < data_num : self . csv_read = self . fetch_data ( stock_no , datetime . today ( ) - timedelta ( days = 30 * starttime ) , starttime ) try : result = self . list_data ( self . csv_read ) except : if starttime == 0 : starttime += 1 self . csv_read = self . fetch_data ( stock_no , datetime . today ( ) - timedelta ( days = 30 * starttime ) , starttime ) result = self . list_data ( self . csv_read ) logging . info ( 'In first day of months %s' % stock_no ) self . raw_data = result [ 'stock_price' ] + self . raw_data self . data_date = result [ 'data_date' ] + self . data_date self . stock_name = result [ 'stock_name' ] self . stock_range = result [ 'stock_range' ] + self . stock_range self . stock_vol = result [ 'stock_vol' ] + self . stock_vol self . stock_open = result [ 'stock_open' ] + self . stock_open self . stock_h = result [ 'stock_h' ] + self . stock_h self . stock_l = result [ 'stock_l' ] + self . stock_l starttime += 1 except : logging . info ( 'Data not enough! %s' % stock_no ) logging . info ( 'Fetch %s' % stock_no )
stock_no: Stock no.
        data_num: Default fetch numbers. (Default is 75)
        debug: For debug to print some info about data solution. (Default is 0)

        stock_no: 股票代碼。
        data_num: 預設抓取的筆數（交易日數，預設為 75 筆）
        debug: 除錯用，列印出相關除錯資訊。0:關閉（預設） 1:開啟

        property:
          self.raw_data = [list]    收盤資訊，[舊→新]
          self.stock_name = str()   該股票名稱
          self.stock_no = str()     該股票代號
          self.data_date = [list]   日期資訊，[舊→新]
          self.stock_range = [list] 漲跌幅
          self.stock_vol = [list]   成交量
          self.stock_open = [list]  開盤價
          self.stock_h = [list]     最高價
          self.stock_l = [list]     最低價