def importAllData(): data = util.todayStock() threadlist = [] engine = create_engine('mysql+pymysql://root:root@localhost:3306/stock') try: QuerryDupontData(data, 'tb_stock_dupont', engine) except: traceback.print_exc()
def importToday(): try: today = datetime.datetime.now() endDate = today.strftime('%Y%m%d') data=util.todayStock() if(timeUtil.tableNeedUpdate('tb_stock_history')): insertTodayValue(data,'tb_stock_history' ) timeUtil.saveOperationTime('tb_stock_history') except: print('today stock error')
def importTodayStockAndPE(tablename='tb_stock_hisotry_detatil'): try: data = util.todayStock() print(data) except: traceback.print_exc() print('error') try: if (timeUtil.tableNeedUpdate(tablename)): importHistory(data, tablename) timeUtil.saveOperationTime(tablename) except: traceback.print_exc()
def dataimport(table, fun, if_exists='append'): logger = logging.getLogger(__name__) logger.setLevel(level=logging.INFO) handler = logging.FileHandler("log.txt") handler.setLevel(logging.INFO) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) logger.info(table + ' start') configger.init() engine = configger.engine data = todayStock() lg = bs.login() i = 0 symbols = tqdm(data['symbol']) now = datetime.datetime.now() sql = 'select code,max(date) as date,max(updateTime)as updateTime from {} GROUP BY code'.format( table) try: timeData = pd.read_sql(con=engine, sql=sql, index_col='code') except: timeData = pd.DataFrame() for code in symbols: i = i + 1 # code=util.getdotCodeBysymbol(symbol) if (not timeData.empty and code in timeData.index and needUpdate(timeData.loc[code, 'updateTime'], now, isWorkDay=True) == False): continue try: start_date = pd.to_datetime( timeData.loc[code, 'date']) + datetime.timedelta(days=90) start_date = start_date.strftime('%Y-%m-%d') # start_date=start_date.date() except: start_date = '1990-01-01' # print(start_date,end_date) # print(start_date,end_date) result = fun(code, start_date) result['updateTime'] = now # print(result) result.to_sql(table, con=engine, if_exists=if_exists, index=False) symbols.set_description("查询代码为:{},数据条数为{}".format( code, len(result.index))) if (i % 1000 == 0): bs.logout() time.sleep(5) bs.login() bs.logout()
def bySMAMain(): data = util.todayStock() symbols = data['symbol'] list = findSMAbySymbols(symbols, 'deathCross') return list
def byMacdMain(): data = util.todayStock() symbols = data['symbol'] list = findMacdListBySymobls(symbols, 'goldenCross', days=100) return list
def importGrowth(): engine = create_engine('mysql+pymysql://root:root@localhost:3306/stock') stockData = todayStock() importData(stockData, engine)
def mainProcess(): configger.init() engine=configger.engine stockData=todayStock()
def dataimport(table,fun,if_exists='append'): configger.init() engine=configger.engine stockData=todayStock() i,count =0, len(stockData.index) lg = bs.login() toyear = datetime.datetime.now().year toseason=int(datetime.datetime.now().month/4) now=datetime.datetime.now() codes = tqdm(stockData['symbol']) sql='select code,max(updateTime) as updateTime,max(date) as date from {} GROUP BY code '.format(table) try: timeData=pd.read_sql(con=engine,sql=sql,index_col='code') except: timeData=pd.DataFrame() # print(timeData) for code in codes: data=pd.DataFrame() try: if(not timeData.empty and code in timeData.index and (now-timeData.loc[code,'updateTime']).days<1): # print(timeData.loc[code]) continue except: traceback.print_exc() pass # sql='select max(date) from {} where code="{}"'.format(table,code) i=i+1 try: # print('timeData',timeData) date=timeData.loc[code,'date'] # print('date',date) year,season=date.split('-') year,season=int(year),int(season) except: year=1989 season=4 season=season+1 year =year+1 if(season==5) else year season =0 if(season==5) else season # print('update',year,season) # print(year,season) list=[] for i in range(year,toyear+1): for j in range(1,5): #在之前 if(i==year and j<season) or i < year: continue #在以后 elif(i==toyear and j>toseason) or i>toyear: continue #更新 else: list.append(i*10+j) list.reverse() j = 0 for i in list: date=str(int(i/10))+'-'+str(i%10) try: # print(i) result=fun(code,int(i/10),i%10) result['code']=code result['date']=date ##判断无历史数据自动跳出 if(result.empty): j=j+1 if(j>3): break continue if(data is None or data.empty): data=result else: data=data.append(result,ignore_index=True) # print(count) # print(data) except: traceback.print_exc() data['updateTime']=now # print(data) data.to_sql(table,con=engine,if_exists=if_exists,index=False) # print(data) os.system('cls') if(i%100==0): bs.logout() time.sleep(5) bs.login() codes.set_description("导入{}中代码为{},条数为{}".format(table,code,len(data.index))) bs.logout()
def byCRMain(): data = util.todayStock() symbols = data['symbol'] list = findCRBySymbols(symbols) return list
def importProfit(): configger.init() engine = configger.engine stockData = todayStock() importData(stockData, engine)