def generate_sample_data():

    dates = pd.date_range(start="2008-01-01", end="2008-01-30")

    for index, date in enumerate(dates):
        stock = Stock()
        stock.code = "T9999"
        stock.date = date
        stock.open = index
        stock.high = index + 1
        stock.low = index - 0.5
        stock.close = index + 1
        stock.volume = 100
        stock.save_if_need()

    for index, date in enumerate(dates[::-1]):
        stock = Stock()
        stock.code = "T9998"
        stock.date = date
        stock.open = index
        stock.high = index + 1
        stock.low = index - 0.5
        stock.close = index + 1
        stock.volume = 100
        stock.save_if_need()
Ejemplo n.º 2
0
 def crawl(self):
     stock_frame = ts.get_k_data(code=self.code,
                                 start=self.start,
                                 end=self.end,
                                 retry_count=30)
     for index in stock_frame.index:
         stock_series = stock_frame.loc[index]
         stock_dict = stock_series.to_dict()
         stock = Stock(**stock_dict)
         stock.save_if_need()
     logging.warning("Finish crawling code: {}, items count: {}".format(
         self.code, stock_frame.shape[0]))
Ejemplo n.º 3
0
 def crawl(self):
     stock_frame = ts.get_k_data(code=self.code,
                                 start=self.start,
                                 end=self.end,
                                 retry_count=30)
     for index in stock_frame.index:  # stock_index是从0到length(stock_frame)的整数
         stock_series = stock_frame.loc[index]  # 某一行的数据
         stock_dict = stock_series.to_dict(
         )  # pandas提供的字典化方法, 返回{"date":"2018-08-01","open":5234,"close":5272,"high":5298,"volume":7665600,"code":"sh"}
         stock = Stock(**stock_dict)  # 将字典的键和Stock类中各个字段对应起来进行组装
         stock.save_if_need()  # 储存进数据库
     logging.warning("Finish crawling code: {}, items count: {}".format(
         self.code, stock_frame.shape[0]))