def movie(): df = ts.realtime_boxoffice() return df[[ 'Irank', # 排名 'MovieName', # 片名 'BoxOffice' ]] # 今日票房
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_realtime_boxoffice(): df = ts.realtime_boxoffice() if df is not None: res = df.to_sql(fun_realtime_box_office, engine, if_exists='replace') msg = 'ok' if res is None else res print('获取获取实时电影票房数据: ' + msg + '\n') else: print('获取获取实时电影票房数据: ' + 'None' + '\n')
def sync_movie_data(): ''' movie boxoffice data ''' df = ts.realtime_boxoffice() # df.to_excel('movie.xlsx',encoding='utf-8') # records = json.loads(df.T.to_json()).values() DataFrameToMongo(df, MongoClient(mongourl)['stoinfo']['movie'], ['MovieName'])
def test(): ts.get_sz50s() ts.get_hs300s() ts.get_zz500s() ts.realtime_boxoffice() ts.get_latest_news() ts.get_notices(tk) ts.guba_sina() ts.get_cpi() ts.get_ppi() ts.get_stock_basics() ts.get_concept_classified() ts.get_money_supply() ts.get_gold_and_foreign_reserves() ts.top_list() #每日龙虎榜列表 ts.cap_tops() #个股上榜统计 ts.broker_tops() #营业部上榜统计 ts.inst_tops() # 获取机构席位追踪统计数据 ts.inst_detail()
def movie(): df = tu.realtime_boxoffice() df_data = nu.array(df) df_list = df_data.tolist() send_df_list = [] for i in df_list: send_df_list.append('-'.join(i[:-1])) send_df_list.insert(0, u"实时票房(万)-票房排名-影片名称-票房占比-上映天数-累计票房(万)") str_send_df_list = '\n'.join(send_df_list) return str_send_df_list
def main(): #ts.get_latest_news() #默认获取最近80条新闻数据,只提供新闻类型、链接和标题 # contents = ts.get_latest_news(top=5,show_content=True) #显示最新5条新闻,并打印出新闻内容 # print contents['title'][0],contents['time'][0] # print contents['content'][0] df = ts.realtime_boxoffice() df.columns = [ '实时票房(万)', '排名', '影片名', '票房占比 (%)', '上映天数', '累计票房(万)', '数据获取时间' ] print(df)
def prepare_data(): real_time_box_office = tushare.realtime_boxoffice() if real_time_box_office is None or real_time_box_office.empty: return record_json = real_time_box_office.to_json(orient='records') print(record_json) collection = mongoConfig.get_collection_default("realtime_boxoffice") current_date = time.strftime("%Y-%m-%d") mongoConfig.clear_collection(collection) # mongoConfig.remove(collection, {"time": {'$regex': current_date}}) mongoConfig.insert_json(collection, json.loads(record_json))
def movie(): df = ts.realtime_boxoffice() content = '排名 电影名字 票房占比 上映时间 累计票房\n' for i in range(0, 11): content = content + str( df['Irank'][i]) + ' ' + df['MovieName'][i] + ' ' + str( df['boxPer'][i]) + '% ' + str(df['movieDay'][i]) + '天 ' + str( df['sumBoxOffice'][i]) + '万\n' #print(content) itchat.send('实时票房:\n' + content, toUserName='******')
def updateRealtimeBoxoffice(con): import share.model.dao.boxoffice.RealtimeBoxoffice as Model logging.debug("Updating realtime boxoffice") df = ts.realtime_boxoffice(retry_count=16) res = [] for _, row in df.iterrows(): obj = Model.rowToORM(row) if obj is not None: res.append(obj) Base.metadata.create_all(con.engine) con.save_all(res) return
def real_time_box_office(): df = ts.realtime_boxoffice() f.write('### 实时票房\n\n') table_head = '|影片名|排名|实时票房(万)|累计票房(万)|上映天数|\n|-|-|-|-|-|\n' f.write(table_head) for i in range(len(df)): txt = '|' + df['MovieName'][i] + '|' + df['Irank'][i] + '|' + df['BoxOffice'][i] + '|' + \ df['sumBoxOffice'][i] + '|' + df['movieDay'][i] + '|\n' f.write(txt) pass f.write('\n\n') pass
def today_top_movies(self): #获得当日电影实时票房数据DF movie_df = ts.realtime_boxoffice() #将票房数据转化为int和float以便调用 movie_df[['Irank','movieDay']] = movie_df[['Irank','movieDay']].astype(int) movie_df[['BoxOffice','boxPer','sumBoxOffice']] = movie_df[['BoxOffice','boxPer','sumBoxOffice']].astype(float) #计算前十名日均票房 movie_df['dayboxoffice'] = movie_df.sumBoxOffice/movie_df.movieDay #返回所需数据,上映两周之内日均票房一千万以上,当日票房占比百分之十以上 result = movie_df.ix[(movie_df.movieDay<15) & (movie_df.dayboxoffice>1000) & (movie_df.boxPer>10)] self.today_goods = [i.encode('utf8') for i in list(result.MovieName)] return self.today_goods
def get_realtime_boxoffice(day=None): try: total = ts.realtime_boxoffice().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" } return result
def handle(text, mic, profile, wxbot=None): """ Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) wxbot -- wechat bot instance """ sys.path.append(mic.dingdangpath.LIB_PATH) from app_utils import wechatUser df = ts.realtime_boxoffice() rs = [] # rs.append("实时票房(万)") # rs.append("排名") # rs.append("影片名") # rs.append("票房占比 (%)") # rs.append("上映天数") # rs.append("累计票房(万)") # rs.append("数据获取时间") # rs.append("\n") for index, row in df.iterrows(): for col_name in df.columns: if col_name == "BoxOffice": rs.append("实时票房:" + row[col_name] + "万") elif col_name == "Irank": rs.append("排名:" + row[col_name]) elif col_name == "MovieName": rs.append("片名:" + row[col_name]) elif col_name == "boxPer": rs.append("票房占比:" + row[col_name]) elif col_name == "movieDay": rs.append("上映天数:" + row[col_name]) elif col_name == "sumBoxOffice": rs.append("累计票房:" + row[col_name]) elif col_name == "time": rs.append("获取时间:" + row[col_name]) rs.append('\n') msg = ' '.join(rs) tit = "电影票房实时排行榜" t = mic.asyncSay("已获取" + tit + "," + ('将发送到您的微信' if wxbot != None else "篇幅较长,请登录微信收取")) if wxbot != None: wechatUser(profile, wxbot, tit, msg) t.join()
def today_top_movies(self): #获得当日电影实时票房数据DF movie_df = ts.realtime_boxoffice() #将票房数据转化为int和float以便调用 movie_df[['Irank', 'movieDay']] = movie_df[['Irank', 'movieDay']].astype(int) movie_df[['BoxOffice', 'boxPer', 'sumBoxOffice' ]] = movie_df[['BoxOffice', 'boxPer', 'sumBoxOffice']].astype(float) #计算前十名日均票房 movie_df['dayboxoffice'] = movie_df.sumBoxOffice / movie_df.movieDay #返回所需数据,上映两周之内日均票房一千万以上,当日票房占比百分之十以上 result = movie_df.ix[(movie_df.movieDay < 15) & (movie_df.dayboxoffice > 1000) & (movie_df.boxPer > 10)] self.today_goods = [i.encode('utf8') for i in list(result.MovieName)] return self.today_goods
def show_stats_home(): """大盘指数""" df = ts.get_index() market_index = df2DictList(df, True) """自选股数据""" df = ts.get_realtime_quotes( ['000002', '300122', '002230', '300166', '603189', '000005']) self_stock = df2DictList(df) """新闻数据""" df = ts.get_latest_news() news = df2DictList(df) """电影票房""" df = ts.realtime_boxoffice() boxoffice = df2DictList(df) return dict(market_index=market_index, self_stock=self_stock, news=news, boxoffice=boxoffice)
# -=-=-=-=-=-=-=-=-=-=-= # coding=UTF-8 # __author__='Guo Jun' # Version 1..0.0 # -=-=-=-=-=-=-=-=-=-=-= import tushare as ts df = ts.realtime_boxoffice() print(df) # ds = ts.get_notices() # print(ds) # da = ts.get_latest_news() #默认获取最近80条新闻数据,只提供新闻类型、链接和标题 # dc = ts.get_latest_news(top=5,show_content=True) #显示最新5条新闻,并打印出新闻内容 # # print(da) # print(dc)
#!/usr/bin/python # -*- coding: UTF-8 -*- import tushare as ts df_film = ts.realtime_boxoffice() print(df_film) df_film_date = ts.day_boxoffice('2017-05-17') print(df_film_date)
import tushare # ts = tushare.get_hist_data('601668') # print(ts) # rate = tushare.get_deposit_rate() # print(rate) movie = tushare.realtime_boxoffice() print(movie)
# 股票列表 ts.get_stock_basics() # 业绩报告(主表) ts.get_report_data(2014,3) # 盈利能力 ts.get_profit_data(2014,3) # 营运能力 ts.get_operation_data(2014,3) # 成长能力 ts.get_growth_data(2014,3) # 偿债能力 ts.get_debtpaying_data(2014,3) # 现金流量 ts.get_cashflow_data(2014,3) # 宏观经济数据 # 存款利率 ts.get_deposit_rate() # 贷款利率 ts.get_loan_rate() # 存款准备金率 ts.get_rrr() # 货币供应量 ts.get_money_supply() # 货币供应量(年底余额) ts.get_money_supply_bal() # 国内生产总值(年度) ts.get_gdp_year() # 国内生产总值(季度) ts.get_gdp_quarter() # 三大需求对GDP贡献 ts.get_gdp_for() # 三大产业对GDP拉动 ts.get_gdp_pull() # 三大产业贡献率 ts.get_gdp_contrib() # 居民消费价格指数 ts.get_cpi() # 工业品出厂价格指数 ts.get_ppi() # 新闻事件数据 # 信息地雷 ts.get_notices() code:股票代码 date:信息公布日期 # 新浪股吧 ts.guba_sina() fts.realtime_boxoffice()
def get_realtime_boxoffice(): return ts.realtime_boxoffice().to_json()
def get_all_price(code_list): '''''process all stock''' df = ts.realtime_boxoffice() print df
#!usr/bin/env python3 import tushare as ts df_dayly = ts.realtime_boxoffice() # df_mon = ts.month_boxoffice() df_dayly.to_csv("D:/file.csv", encoding="utf_8_sig")
# -*- coding: utf-8 -*- import tushare as ts ''' 获取实时电影票房数据,30分钟更新一次票房数据,可随时调用。 返回值说明: BoxOffice 实时票房(万) Irank 排名 MovieName 影片名 boxPer 票房占比 (%) movieDay 上映天数 sumBoxOffice 累计票房(万) time 数据获取时间 ''' data = ts.realtime_boxoffice(); print (data[['Irank','MovieName', 'BoxOffice','movieDay', 'sumBoxOffice','boxPer','time']])
def BoxOffice(): return ts.realtime_boxoffice()
def GetRealtime_boxoffice(): df = ts.realtime_boxoffice() df = df.to_json(force_ascii=False) print(df) return df
import time # to analyse movie data plt.axis([0, 48, 0, 6000]) plt.ion() plt.grid(True) index = 1 pre_movie_box1 = 0 pre_movie_box2 = 0 pre_movie_box3 = 0 pre_movie_box4 = 0 pre_movie_box5 = 0 while True: movie_df = ts.realtime_boxoffice() print(movie_df) # t = datetime.datetime.now() t = time.localtime() shituxingzhe_df = movie_df[movie_df['MovieName'] == u'使徒行者'] weiweiyixiao_df = movie_df[movie_df['MovieName'] == u'微微一笑很倾城'] daomubiji_df = movie_df[movie_df['MovieName'] == u'盗墓笔记'] weicheng_df = movie_df[movie_df['MovieName'] == u'危城'] aichongdajimi_df = movie_df[movie_df['MovieName'] == u'爱宠大机密'] print index print(str(float(shituxingzhe_df.iloc[0, 0]))+','+str(float(weiweiyixiao_df.iloc[0, 0]))+',' + str(float(daomubiji_df.iloc[0, 0]))+','+str(float(weicheng_df.iloc[0, 0]))+',' + str(float(aichongdajimi_df.iloc[0, 0]))) plt.plot([index-1, index], [pre_movie_box1, float(shituxingzhe_df.iloc[0, 0])], c='b') plt.plot([index-1, index], [pre_movie_box2, float(weiweiyixiao_df.iloc[0, 0])], c='r') plt.plot([index-1, index], [pre_movie_box3, float(daomubiji_df.iloc[0, 0])], c='g')
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!")
#coding:utf-8 import tushare as ts from sqlalchemy import create_engine, insert df = ts.realtime_boxoffice() #获取实时电影票房数据,30分钟更新一次票房数据 engine = create_engine('mysql://*****:*****@127.0.0.1/tushare?charset=utf8') df.to_sql('movie_data', engine) print df
def get_realtime_boxoffice(): return ts.realtime_boxoffice()
def test_boxoffice_1(self): bf: pd.DataFrame = ts.realtime_boxoffice() print(bf) bf: pd.DataFrame = ts.day_boxoffice() print(bf)
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()