import pandas as pd import requests import os from requests_toolbelt.multipart.encoder import MultipartEncoder from datetime import datetime, timedelta
url = "https://jike.v.cntv.cn/interface/deal_post"
def login(): res = requests.post(url, data={ "action": "ulogin", "username": "xxx", "password": "xxx"}, verify=False) return "JSESSIONID=" + res.json().get("sessionid")
def upload_video(cookie, mainname, keyword, content, filepath): headers = { "User-Agent": "Mozilla/5.0", "cookie": cookie }
data = { "action": "uupload", "username": "hehuihui", "upload_strategy": "VR4K发CMS", "catlog_columnname": "JOVE内部测试", "catlog_mainname": mainname, "catlog_uploadkeyword": keyword, "catlog_content": content, "catlog_precisioncutena": "精切", "catlog_channelname": "央视网原创", "catlog_firstcategory": "原创 ", "catlog_secondcategory": "资讯", "catlog_check": "不审核", }
encoder = MultipartEncoder( fields={ **data, 'upload_file': ('video_mono.mov', open(filepath, 'rb'), 'application/octet-stream') } )
headers['Content-Type'] = encoder.content_type
try: response = requests.post(url, headers=headers, data=encoder, verify=False, timeout=3600) print(mainname, response.status_code, response.text) except Exception as e: print(f"Error uploading file: {e}")
if __name__ == '__main__': c = login() file_path = '/data/oss/VR视频迁移记录表.xlsx' df = pd.read_excel(file_path)
for index, row in df.iterrows(): mainname = row.values[0] id = row.values[1] keyword = row.values[2] content = row.values[3] print(mainname, id, keyword, content) filepath = "/data/oss/" + id + "/video_mono.mov" upload_video(c, mainname, keyword, content, filepath)
|