def update(end_date): indexes = bd.getStocks(True) for each in indexes: stock_code = each[0] stock_code_163 = each[3] start_date = each[5] if start_date is None: start_date = du.convertStringToDate("1990-01-01", "%Y-%m-%d") elif start_date == end_date: continue else: start_date = start_date + timedelta(1) data = bd.getStockData(stock_code_163, start_date, end_date) last_updated_date = data[0].split(",")[0] bd.insertBasicData(stock_code, data) bd.insertTechData(stock_code, data) bd.insertAnalysisData(stock_code, data) bd.updateMasterDate("LAST_UPDATED_DATE", last_updated_date, stock_code_163) stocks = bd.getStocks(False) for each in stocks: stock_code = each[0] stock_code_163 = each[3] stock_code_sina = each[4] start_date = each[5] if start_date is None: start_date = du.convertStringToDate("1990-01-01", "%Y-%m-%d") elif start_date == end_date: continue else: start_date = start_date + timedelta(1) data = bd.getStockData(stock_code_163, start_date, end_date) last_updated_date = data[0].split(",")[0] bd.insertBasicData(stock_code, data) bd.insertTechData(stock_code, data) bd.insertAnalysisData(stock_code, data) bd.updateMasterDate("LAST_UPDATED_DATE", last_updated_date, stock_code_163) rf = bd.getRecoveryFactor(stock_code_163, stock_code_sina, start_date) bd.insertRecoveryFactor(stock_code, rf)
def smartUpdate(end_date=date.today()): sql = "SELECT * FROM stockmaster where LAST_UPDATED_DATE < '" + du.convertDateToString(end_date, "%Y-%m-%d") + "'" result_set = dbu.query(sql) while len(result_set) > 0: for each in result_set: stock_code = each[0] index_indicator = each[2] stock_code_163 = each[3] stock_code_sina = each[4] start_date = each[5] logger.info("UPDATING STOCK, STOCK CODE IS " + stock_code) if start_date is None: start_date = du.convertStringToDate("1990-01-01", "%Y-%m-%d") elif start_date == end_date: continue else: start_date = start_date + timedelta(1) data = bd.getStockData(stock_code_163, start_date, end_date) if len(data) > 0: last_updated_date = data[0].split(",")[0] bd.insertBasicData(stock_code, data) logger.info("INSERT BASIC DATA COMPLETED") bd.insertTechData(stock_code, data) logger.info("INSERT TECH DATA COMPLETED") bd.insertAnalysisData(stock_code, data) logger.info("INSERT ANALYSIS DATA COMPLETED") bd.updateMasterDate("LAST_UPDATED_DATE", last_updated_date, stock_code_163) logger.info("LAST DATE UPDATED") if str(index_indicator) == "1": rf = bd.getRecoveryFactor(stock_code_163, stock_code_sina, start_date) bd.insertRecoveryFactor(stock_code, rf) logger.info("INSERT RF DATA COMPLETED") else: logger.error("NO DATA IS RECEIVED FROM 163") result_set = dbu.query(sql) if len(result_set) > 0: logger.info("NOT ALL STOCKS ARE UPDATED, WAIT 10 MINUTES FOR NEXT UPDATE") tm.sleep(10*60) return "COMPLETED"
def updateWithoutRF(end_date): stocks = bd.getStockCodes() for each in stocks: stock_code = each[0] stock_code_163 = each[3] start_date = each[5] if start_date is None: start_date = du.convertStringToDate("1990-01-01", "%Y-%m-%d") elif start_date == end_date: continue else: start_date = start_date + timedelta(1) data = bd.getStockData(stock_code_163, start_date, end_date) last_updated_date = data[0].split(",")[0] bd.insertBasicData(stock_code, data) bd.insertTechData(stock_code, data) bd.insertAnalysisData(stock_code, data) bd.updateMasterDate("LAST_UPDATED_DATE", last_updated_date, stock_code_163)