def get_day_cinema(day=None): if day == None: try: result = ts.day_cinema().to_json() except Exception as e: result = json.dumps({"error":True,"message":str(e)}) else: try: result = ts.day_cinema(day).to_json() except Exception as e: result = json.dumps({"error":True, "message":"can not get the data, format date as YYYY-M-D,error:{error}".format(error=e.message)}) return result
def job_9(): try: print("I'm working......电影票房") # 实时票房 realtime_boxoffice = ts.realtime_boxoffice() data = pd.DataFrame(realtime_boxoffice) data.to_sql('realtime_boxoffice',engine,index=True,if_exists='replace') print("实时票房......done") # 每日票房 day_boxoffice = ts.day_boxoffice() data = pd.DataFrame(day_boxoffice) data.to_sql('day_boxoffice',engine,index=True,if_exists='replace') print("每日票房......done") # 月度票房 month_boxoffice = ts.month_boxoffice() data = pd.DataFrame(month_boxoffice) data.to_sql('month_boxoffice',engine,index=True,if_exists='replace') print("月度票房......done") # 影院日度票房 day_cinema = ts.day_cinema() data = pd.DataFrame(day_cinema) data.to_sql('day_cinema',engine,index=True,if_exists='replace') print("影院日度票房......done") except Exception as e: print(e)
def get_movie(): # mov = ts.realtime_boxoffice() # print(mov.to_json()) df = ts.day_cinema() # 取上一日全国影院票房排行数据 # df = ts.day_cinema('2015-12-24') #取指定日期的数据 df.head(10) print(df.to_json())
def cinema(): dd = tu.day_cinema() dd_data = nu.array(dd) dd_list = dd_data.tolist() send_dd_list = [] for i in dd_list[:10]: send_dd_list.append('-'.join(i)) send_dd_list.insert(0, u"上座率-场均人次-影院名称-排名-今日观众-今日票房-今日场次-场均票价") str_send_dd_list = '\n'.join(send_dd_list) return str_send_dd_list
def get_day_cinema(day=None): df = ts.day_cinema(day) if df is not None: if day is None: day = get_yesterday() df.insert(0, 'date', day) res = df.to_sql(fun_day_cinema, engine, if_exists='replace') msg = 'ok' if res is None else res print('获取全国影院指定单日:{0}票房排行数据: {1} '.format(day, msg) + '\n') else: print('获取全国影院指定单日:{0}票房排行数据: {1} '.format(day, 'None') + '\n')
def updateDayCinema(con, date: datetime): import share.model.dao.boxoffice.DayCinema as Model dateString = date.strftime("%Y-%m-%d") logging.debug("Updating day cinema of {}".format(dateString)) df = ts.day_cinema(date=dateString,retry_count=16) res = [] for _, row in df.iterrows(): obj = Model.rowToORM(row, date=date) if obj is not None: res.append(obj) Base.metadata.create_all(con.engine) con.save_all(res) return
def cinema_office((start_date,end_date)): startdate = datetime .datetime .strptime(start_date ,'%Y-%m-%d').date() enddate = datetime .datetime .strptime(end_date ,'%Y-%m-%d').date() date_list = date_loop .date_loop_all(start_date= startdate ,end_date= enddate ) DTS = [] for date in date_list: preDTS = ts.day_cinema(date=date) preDTS['date'] = date DTS.append(preDTS) DTS = pd.concat(DTS) return DTS
def get_day_cinema(day=None): print(day) if day == None: try: total = ts.day_cinema().to_csv().split() head = [TRANS.get(i) for i in total[0].split(",")] body = [line.split(",") for line in total[1:]] result = {"head": head, "body": body} except Exception as e: result = {"error": "true", "message": str(e)} else: try: total = ts.day_cinema(day).to_csv().split() head = [TRANS.get(i) for i in total[0].split(",")] body = [line.split(",") for line in total[1:]] result = {"head": head, "body": body} except Exception as e: result = { "error": "true", "message": "can not get the data, format date as YYYY-M-D" } print("result") print(result) return result
import tushare as ts # 实时票房 ts.realtime_boxoffice() # 每日票房 ts.day_boxoffice() #取上一日的数据 ts.day_boxoffice('2010-01-01') #取指定日期的数据 # 月度票房 ts.month_boxoffice() #取上一月票房数据 ts.month_boxoffice('2019-02') #此月数据 # 影院日度票房 ts.day_cinema() #取上一日全国影院票房排行数据 df = ts.day_cinema('2019-02-05') # 指定日期的数据 2019年春节 df.to_excel('movie.xlsx') # pip install openpyxl
import tushare as ts from sqlalchemy import create_engine token = ts.set_token( 'c723069dd4a25402d05ea6afad36da2937111adf012f8258abb5f7e05936e575') #engine = create_engine('mysql+pymysql://root:[email protected]/packageing?charset=utf8') engine = create_engine( 'mysql+pymysql://root:[email protected]/gupiao?charset=utf8') realtime = ts.realtime_boxoffice() #realtime.to_sql('realtime_boxoffice',engine) realtime.to_sql('realtime_boxoffice', engine, if_exists='append') day = ts.day_boxoffice() #day.to_sql('day_boxoffice',engine) day.to_sql('day_boxoffice', engine, if_exists='append') month = ts.month_boxoffice() #month.to_sql('month_boxoffice',engine) month.to_sql('month_boxoffice', engine, if_exists='append') cinema = ts.day_cinema() #cinema.to_sql('day_cinema',engine) cinema.to_sql('day_cinema', engine, if_exists='append')
import tushare as ts # 实时票房 # 获取实时电影票房数据,30分钟更新一次票房数据,可随时调用。 df = ts.realtime_boxoffice() print(df) # 每日票房 # 获取单日电影票房数据,默认为上一日的电影票房,可输入参数获取指定日期的票房。 # 似乎只能显示前一日的 df = ts.day_boxoffice("2015-01-01") print(df) # 月度票房 # 获取单月电影票房数据,默认为上一月,可输入月份参数获取指定月度的数据。 df = ts.month_boxoffice('2016-12') print(df) # 影院日度票房 # 获取全国影院单日票房排行数据,默认为上一日,可输入日期参数获取指定日期的数据。 df = ts.day_cinema('2015-12-24') print(df)
g_p.index=g_p.month;g_p g_p.plot(); #工业品价格指数 g_p1=g_p[['ppiip','ppi','qm','rmi','pi']].dropna() g_p1.plot(); #生活价格指数 g_p2=g_p[['cg','food','clothing','roeu','dcg']].dropna();g_p2 g_p2.plot(grid=True) ###10.4 电影票房数据的实时分析 #实时票房 #获取实时电影票房数据,30分钟更新一次票房数据,可随时调用。 r_b = ts.realtime_boxoffice() r_b.info() r_b plt.barh(r_b.MovieName,r_b.BoxOffice.astype(float)); plt.pie(r_b.boxPer,labels=r_b.MovieName); #每日票房 d_b = ts.day_boxoffice() #取上一日的数据 d_b #影院日度票房 #获取全国影院单日票房排行数据,默认为上一日,可输入日期参数获取指定日期的数据。 d_c=ts.day_cinema() #取上一日全国影院票房排行数据 d_c.info() d_c[:10] plt.barh(d_c.CinemaName[:10],d_c.Attendance.astype(float)[:10]);
def capture_stock_data(): capture_date = datetime.datetime.now().strftime("%Y%m%d") save_dir = "/home/dandelion/stock_data/" + capture_date if not os.path.exists(save_dir): os.mkdir(save_dir) print("The save directory is created successfully!\n", save_dir) print("The save directory is already exist!\n", save_dir) # ======================Daily Command================================================================ # get the boxoffcie data of the last day and save as csvfile named as the capture command ts.day_boxoffice().to_csv( save_dir + "/" + capture_date + "_day_boxoffice.csv", header=True, sep=",", index=False, ) print("day_boxoffice data capture completed!") # get the cinema data of the last day and save as csvfile named as the capture command ts.day_cinema().to_csv( save_dir + "/" + capture_date + "_day_cinema.csv", header=True, sep=",", index=False, ) print("day_cinema data capture completed!") ts.month_boxoffice().to_csv( save_dir + "/" + capture_date + "_month_boxoffice.csv", header=True, sep=",", index=False, ) print("month_boxoffice data capture completed!") ts.realtime_boxoffice().to_csv( save_dir + "/" + capture_date + "_realtime_boxoffice.csv", header=True, sep=",", index=False, ) print("realtime_boxoffice data capture completed!") # get the stock data index of the last day and save as csvfile named as the capture command ts.get_index().to_csv( save_dir + "/" + capture_date + "_get_index.csv", header=True, sep=",", index=False, ) print("get_index data capture completed!") # get the history cpi data and save as csvfile named as the capture command ts.get_cpi().to_csv( save_dir + "/" + capture_date + "_get_cpi.csv", header=True, sep=",", index=False, ) print("get_cpi data capture completed!") # get the history gdp data by month and save as csvfile named as the capture command ts.get_gdp_year().to_csv( save_dir + "/" + capture_date + "_get_gdp_year.csv", header=True, sep=",", index=False, ) print("get_gdp_year data capture completed!") # get today all stock data and save as csvfile named as the capture command # ts.get_today_all().to_csv(save_dir+'/'+capture_date+'_get_today_all.csv',header=True,sep=',',index=False) # get detail information of the top brokers today and save as csvfile named as the capture command ts.broker_tops().to_csv( save_dir + "/" + capture_date + "_broker_tops.csv", header=True, sep=",", index=False, ) print("broker_tops data capture completed!") # get detail information of the top brokers today and save as csvfile named as the capture command ts.cap_tops().to_csv( save_dir + "/" + capture_date + "_cap_tops.csv", header=True, sep=",", index=False, ) print("cap_tops data capture completed!") ts.get_area_classified().to_csv( save_dir + "/" + capture_date + "_get_area_classified.csv", header=True, sep=",", index=False, ) print("get_area_classified data capture completed!") # ts.get_balance_sheet(code='').to_csv(save_dir+'/'+capture_date+'_get_balance_sheet.csv',header=True,sep=',',index=False) # print('get_balance_sheet data capture completed!') # ts.get_cash_flow(code='').to_csv(save_dir+'/'+capture_date+'_get_cash_flow.csv',header=True,sep=',',index=False) # print('get_cash_flow data capture completed!') ts.get_day_all().to_csv( save_dir + "/" + capture_date + "_get_day_all.csv", header=True, sep=",", index=False, ) print("get_day_all data capture completed!") ts.get_cashflow_data(2018, 3).to_csv( save_dir + "/" + capture_date + "_get_cashflow_data.csv", header=True, sep=",", index=False, ) print("get_cashflow_data data capture completed!") ts.get_concept_classified().to_csv( save_dir + "/" + capture_date + "_get_concept_classified.csv", header=True, sep=",", index=False, ) print("get_concept_classified data capture completed!") ts.get_debtpaying_data(2018, 3).to_csv( save_dir + "/" + capture_date + "_get_debtpaying_data.csv", header=True, sep=",", index=False, ) print("get_debtpaying_data data capture completed!") ts.get_deposit_rate().to_csv( save_dir + "/" + capture_date + "_get_deposit_rate.csv", header=True, sep=",", index=False, ) print("get_deposit_rate data capture completed!") ts.get_gdp_contrib().to_csv( save_dir + "/" + capture_date + "_get_gdp_contrib.csv", header=True, sep=",", index=False, ) ts.get_gdp_for().to_csv( save_dir + "/" + capture_date + "_get_gdp_for.csv", header=True, sep=",", index=False, ) ts.get_gdp_pull().to_csv( save_dir + "/" + capture_date + "_get_gdp_pull.csv", header=True, sep=",", index=False, ) ts.get_gdp_quarter().to_csv( save_dir + "/" + capture_date + "_get_gdp_quarter.csv", header=True, sep=",", index=False, ) print("get_gdp_ data capture completed!") # ts.get_gdp_year().to_csv(save_dir+'/'+capture_date+'_get_gdp_year.csv',header=True,sep=',',index=False) ts.get_gem_classified().to_csv( save_dir + "/" + capture_date + "_get_gem_classified.csv", header=True, sep=",", index=False, ) ts.get_gold_and_foreign_reserves().to_csv( save_dir + "/" + capture_date + "_get_gold_and_foreign_reserves.csv", header=True, sep=",", index=False, ) ts.get_growth_data(2018, 3).to_csv( save_dir + "/" + capture_date + "_get_growth_data.csv", header=True, sep=",", index=False, ) ts.get_industry_classified().to_csv( save_dir + "/" + capture_date + "_get_industry_classified.csv", header=True, sep=",", index=False, ) ts.get_hs300s().to_csv( save_dir + "/" + capture_date + "_get_hs300s.csv", header=True, sep=",", index=False, ) ts.get_sz50s().to_csv( save_dir + "/" + capture_date + "_get_sz50s.csv", header=True, sep=",", index=False, ) ts.get_zz500s().to_csv( save_dir + "/" + capture_date + "_get_zz500s.csv", header=True, sep=",", index=False, ) ts.get_operation_data(2018, 3).to_csv( save_dir + "/" + capture_date + "_get_operation_data.csv", header=True, sep=",", index=False, ) ts.get_stock_basics().to_csv( save_dir + "/" + capture_date + "_get_stock_basics.csv", header=True, sep=",", index=False, ) ts.get_report_data(2018, 3).to_csv( save_dir + "/" + capture_date + "_get_report_data.csv", header=True, sep=",", index=False, ) ts.inst_detail().to_csv( save_dir + "/" + capture_date + "_inst_detail.csv", header=True, sep=",", index=False, ) ts.inst_tops().to_csv( save_dir + "/" + capture_date + "_inst_tops.csv", header=True, sep=",", index=False, ) print("inst_tops data capture completed!") ts.new_stocks().to_csv( save_dir + "/" + capture_date + "_new_stocks.csv", header=True, sep=",", index=False, ) print("new_stocks data capture completed!") ts.top_list().to_csv( save_dir + "/" + capture_date + "_top_list.csv", header=True, sep=",", index=False, ) print("top_list data capture completed!")
def GetDayCinema(): df = ts.day_cinema() df = df.head(10) df = df.to_json(force_ascii=False) print(df) return df
for i in range(aaa.shape[0]): print(aaa.iloc[i,1]) print("aaa result={result}".format(result=aaa[i,1])) df=pd.DataFrame(columns=['month','cpi']) for i in range(aaa.shape[0]): gap=pd.DataFrame({"month":aaa.iloc[i,0],"cpi":(aaa.iloc[i,1].astype(float)-bbb.astype(float))}) df=df.append(gap) #票房数据 piaofang=ts.day_cinema('2017-10-02') pd.set_option pd.set_option('display.max_columns', 200) pd.set_option('display.width', 1000) piaofang[piaofang['price'].max()] rl_piaofang=ts.realtime_boxoffice() last_m_pf=ts.month_boxoffice('2017-07') piaofang_df=pd.DataFrame()
ticker = '000547' # 获取历史行情数据 # finace=ts.get_hist_data(ticker) # print("获取历史行情数据") # print(finace) # # # 获取实时行情数据 # datato = ts.get_today_all(ticker) # print("获取实时行情数据") # print(datato) # # 获取实时分笔数据 # data=ts.get_realtime_quotes(ticker) # print("获取实时分笔数据") # print(data) # 获取当日历史分笔数据 data_today = ts.get_today_ticks(ticker) print("获取当日历史分笔数据") print(data_today) data_today.to_csv('000547.csv') # data_today.to_excel('000547.xlsx') df = ts.realtime_boxoffice() print(df) dd = ts.day_cinema() print(dd)