|
|
|
|
from hashlib import md5
|
|
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
from datetime import datetime as dt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 从BI的日常影片数据接口中获取信息
|
|
|
|
|
class MovieData:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.salt = '53b22eda5938706a34fd9d44f097bec2'
|
|
|
|
|
self.ts = str(int(dt.timestamp(dt.now())))
|
|
|
|
|
self.url = 'https://nation.bi.piao51.cn/nationDataApi/restful/boxoffice/nation/movieSupportData'
|
|
|
|
|
|
|
|
|
|
def get_data(self, movie_code):
|
|
|
|
|
params = {
|
|
|
|
|
'movieCode': movie_code,
|
|
|
|
|
'timeStamp': self.ts,
|
|
|
|
|
'sign': self.sign(movie_code)
|
|
|
|
|
}
|
|
|
|
|
req = requests.get(self.url, params=params)
|
|
|
|
|
# print(json.dumps(req.json(), indent=4))
|
|
|
|
|
r = ''
|
|
|
|
|
req = req.json()
|
|
|
|
|
if (req['success'] is True) and req['data']['movieInfo'] != '':
|
|
|
|
|
info = req['data']['movieInfo']
|
|
|
|
|
hot = f"《{info['movie_name']}》 - 想看:{info['wish_num']},热度:小红书{info['xiaohongshu']}、视频号{info['shipinhao']}、抖音{info['douyin']}、微博{info['weibo']};"
|
|
|
|
|
# print(hot)
|
|
|
|
|
daily = req['data']['movieDailyBox']
|
|
|
|
|
sales = [f"{daily[n]['businessDate']} {daily[n]['boxRate']}%" for n in range(0, 6)]
|
|
|
|
|
# print(sales)
|
|
|
|
|
pre_sales = [f"{daily[n]['businessDate']} {daily[n]['boxRate']}%" for n in range(7, len(daily))]
|
|
|
|
|
# print(pre_sales)
|
|
|
|
|
r = f"\t{hot}过去六天的票房占比:{'、'.join(sales)};今天到当前时间的票房占比:{daily[6]['boxRate']}%;未来7天的预售票房占比:{'、'.join(pre_sales)};"
|
|
|
|
|
print('MovieData.get_data', movie_code, r)
|
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
def sign(self, code):
|
|
|
|
|
_pre = md5((self.salt + f"movieCode={code}&timeStamp={self.ts}").encode()).hexdigest()
|
|
|
|
|
_sign = md5((_pre + self.salt).encode()).hexdigest()
|
|
|
|
|
return _sign
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
md = MovieData()
|
|
|
|
|
md.get_data('082000852026')
|