def fetch_realtime_quotes(cs=['sh', 'sz', '600300', '601633']): ps = Postgresql() df = ts.get_realtime_quotes(cs) for r in df.values: for i in range(10, 30): if r[i] == '': r[i] = 0 ps.update_insert(table='data_realtime', where="date='%s' and time='%s' and code='%s'" % (r[30], r[31], r[32]), \ date=str(r[30]), time=str(r[31]), code=str(r[32]), open=r[1], pre_close=r[2], price=r[3], \ high=r[4], low=r[5], bid=r[6], ask=r[7], volume=r[8], amount=r[9], \ b1_v=r[10], b1_p=r[11], b2_v=r[12], b2_p=r[13], b3_v=r[14], b3_p=r[15], b4_v=r[16], b4_p=r[17], b5_v=r[18], b5_p=r[19], \ a1_v=r[20], a1_p=r[21], a2_v=r[22], a2_p=r[23], a3_v=r[24], a3_p=r[25], a4_v=r[26], a4_p=r[27], a5_v=r[28], a5_p=r[29]) ps.close()
def reflesh_profit_stock_info(): fb.write('start refleshing stock info on table [profit] .') ps = Postgresql() sql = "SELECT code, name, industry, area, bvps, esp, outstanding, totals, \"timeToMarket\" FROM stock_basics ORDER BY code" rs = ps.fetchall(sql) i = 0 for r in rs: ps.update_insert(table='profit', where="code='%s'" % r[0], code=r[0], name=r[1], industry=r[2], area=r[3], bvps=r[4], esp=r[5], outs=r[6], tots=r[7], market=str(r[8])) i += 1 if i % 100 == 0: fb.write('.') ps.close() fb.write(' is done!\n')