def request(self): txt = [] for line in open(root.get_root_path() + "/output/pos_info.txt", "r"): # 设置文件对象并读取每一行文件 txt.append(line) # 将每一行文件加入到list中 pos_uuid = txt[0][:36] f = open(root.get_root_path() + "/output/playlist_uuid.txt", "r") datalist = f.readlines() playlist_uuid = datalist[0][:36] data = { "pos_update_map": { pos_uuid: { "placeholder_type": None, "playlist_id": playlist_uuid, "show_attributes": {}, "state": "assigned" } } } resp = requests.post(self._url + '/core/pos/save_mappings', json=data, cookies=sw_db.database['cookies']) return resp print(resp.json())
def pack_ncm2(): ConfigReader.read_config() advis_url = ConfigReader.get_string('advis', 'advis_url') headers = {'Content-Type': 'application/json'} pack_uuid = str(uuid.uuid4()) screen = random.randint(1, 24) pack_name = 'a'.join(random.sample(string.ascii_letters + string.digits, 5)) f = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist = f.readlines()[1:2] screen = datalist[0][:36] screen1 = screen.replace('\n', '') f1 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist2 = f1.readlines()[2:3] start = datalist2[0][:36] start1 = start.replace('\n', '') payload = { "pack": { "UUID": pack_uuid, "PackName": pack_name, "Issuer": "AAM", "PlaceholderName": "3D Advertisement", "PerformanceDateTime": start1, "Screen": screen1, "Elements": [{ "ContentTitleText": "2211_XiBanYaHangKong_15S_jpg239", "UUID": "1f48272e-3b98-4a35-9c48-0ca03754be5f", "Duration": 312, "EditRate": "24 1" }, { "ContentTitleText": "702_AoDi_A6L_30S_jpg239", "UUID": "34a287f6-8597-40df-9764-0ad9e4554b2e", "Duration": 312, "EditRate": "24 1" }, { "ContentTitleText": "PULP-FIC-FTRETTE_SHR_F_EN-XX_INT_20_2K_PRKC_20121227_AAM_OV", "UUID": "45e695fe-30fd-4410-a211-f18a56bf87ac", "Duration": 312, "EditRate": "24 1" }] } } resp = requests.post(advis_url + '/v1/pack', headers=headers, json=payload) json_obj = json.loads(resp.content) pack_uuid = json_obj['UUID'] with open(root.get_root_path() + '/output/pack_uuid.txt', 'w') as f: f.write(pack_uuid + '\n')
def pack_screenvision(): ConfigReader.read_config() advis_url = ConfigReader.get_string('advis', 'advis_url') headers = {'Content-Type': 'application/json'} pack_uuid = str(uuid.uuid4()) screen = random.randint(1, 24) pack_name = 'a'.join(random.sample(string.ascii_letters + string.digits, 5)) f = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist = f.readlines()[3:4] feature_id = datalist[0][:36] payload = { "pack": { "UUID": pack_uuid, "PackName": pack_name, "Issuer": "DTDC Screenvision", "PlaceholderName": "3D Advertisement", "Title": feature_id, "NotValidBeforeDate": "2020-01-01", "NotValidAfterDate": "2020-12-31", # "Screen": str(screen), "Elements": [{ "ContentTitleText": "2211_XiBanYaHangKong_15S_jpg239", "UUID": "1f48272e-3b98-4a35-9c48-0ca03754be5f", "Duration": 312, "EditRate": "24 1" }, { "ContentTitleText": "PULP-FIC-FTRETTE_SHR_F_EN-XX_INT_20_2K_PRKC_20121227_AAM_OV", "UUID": "45e695fe-30fd-4410-a211-f18a56bf87ac", "Duration": 312, "EditRate": "24 1" }] } } resp = requests.post(advis_url + '/v1/pack', headers=headers, json=payload) json_obj = json.loads(resp.content) pack_uuid = json_obj['UUID'] with open(root.get_root_path() + '/output/pack_uuid.txt', 'w') as f: f.write(pack_uuid + '\n')
def delete_pack2(): ConfigReader.read_config() advis_url = ConfigReader.get_string('advis', 'advis_url') f = open(root.get_root_path() + "/output/pack_uuid.txt", "r") datalist = f.readlines() pack_uuid = datalist[0][:36] resp = requests.request("DELETE", advis_url + '/v1/pack/' + pack_uuid)
def deal_resp(self, resp): if resp.status_code != 200: return json_obj = json.loads(resp.content) with open(root.get_root_path() + '/output/lms_uuid.txt', 'w') as f: for k, v in json_obj['data']['devices'].items(): if v["category"].lower() == 'lms': f.write(k + '\n')
def deal_resp(self, resp): if resp.status_code != 200: return json_obj = json.loads(resp.content) with open(root.get_root_path() + '/output/playlist_uuid.txt', 'w') as f: for data in json_obj['messages']: uuid = data['playlist_uuid'] f.write(uuid + '\n')
def read_config(): root_dir = root.get_root_path() cf = ConfigReader() # cf = configparser.ConfigParser() cf.read(root_dir + "/config.ini", encoding="utf-8-sig") # secs = cf.sections() # 获取文件中所有的section(一个配置文件中可以有多个配置,如数据库相关的配置,邮箱相关的配置,每个section由[]包裹,即[section]),并以列表的形式返回 # print(secs) ConfigReader.CONFIG = cf return cf
def schedule_validate(): f = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist = f.readlines()[5:6] device_uuid = datalist[0][:36] device_uuid1 = device_uuid.replace('\n', '') f1 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist2 = f1.readlines()[2:3] start = datalist2[0][:36] start1 = start.replace('\n', '') start2 = start1.replace('T', ' ') source_start = datetime.datetime.strptime(start2, "%Y-%m-%d %H:%M:%S") start_datetime = source_start - datetime.timedelta(minutes=3) start_datetime1 = datetime.datetime.strftime(start_datetime, "%Y-%m-%d %H:%M:%S") end_datetime = source_start + datetime.timedelta(minutes=3) end_datetime1 = datetime.datetime.strftime(end_datetime, "%Y-%m-%d %H:%M:%S") payload = { "start_time": start_datetime1, "end_time": end_datetime1, "device_uuids": [device_uuid1] } resp = requests.post(api + '/core/scheduling/schedule', json=payload, cookies=dict(tms2_9000=get_tooken())) json_obj = json.loads(resp.content) a = None templating_issues = [] for k, v in json_obj['data'].items(): templating_issues = v.get('templating_issues') if not templating_issues: a = False continue else: a = True break if a: if templating_issues[0].get('pack_uuid'): return True else: return False
def deal_resp(self, resp): if resp.status_code != 200: return # print(global_val.value) # print(resp.content) json_obj = json.loads(resp.content) with open(root.get_root_path() + '/output/device_uuid.txt', 'w') as f: for k in json_obj['data']['status'].keys(): # print('key: {}'.format(k)) f.write(k + '\n')
def request(self): txt = [] for line in open(root.get_root_path() + "/output/lms_uuid.txt", "r"): # 设置文件对象并读取每一行文件 txt.append(line) # 将每一行文件加入到list中 device_uuid = txt[0][:36] f = open(root.get_root_path() + "/output/placeholder_uuid.txt","r") datalist = f.readlines() placeholder_uuid = datalist[0][:36] data = { "device_id": device_uuid, "playlist": { "duration_in_seconds": 2, "title": "3d-2", "events": [{ "type": "composition", "cpl_id": "ce194f67-92be-4774-b05b-f54ccf62a5f0", "duration_in_seconds": 2, "duration_in_frames": 48, "cpl_start_time_in_seconds": 0, "cpl_start_time_in_frames": 0, "edit_rate": [24, 1], "text": "Content_for_Andy_2s_feature_2k_51", "playback_mode": "2D", "content_kind": "feature", "automation": [] }, { "type": "placeholder", "uuid": placeholder_uuid, "text": "3D Advertisement", "automation": [] }], "is_3d": False, "is_hfr": False, "is_4k": False, "automation": [] } } resp = requests.post(self._url + '/core/playlist/save', json = data,cookies=sw_db.database['cookies']) return resp print(resp.json())
def deal_resp(self, resp): if resp.status_code != 200: return json_obj = json.loads(resp.content) with open(root.get_root_path() + '/output/placeholder_uuid.txt', 'w') as f: for data in json_obj['data']: if (data['name'] == '3D Advertisement'): uuid = data['uuid'] f.write(uuid + '\n')
def performance(): ConfigReader.read_config() advis_url = ConfigReader.get_string('advis', 'advis_url') f = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist = f.readlines()[1:2] screen = datalist[0][:36] screen1 = screen.replace('\n', '') f1 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist2 = f1.readlines()[2:3] start = datalist2[0][:36] start1 = start.replace('\n', '') start2 = start1.replace('T', ' ') source_start = datetime.datetime.strptime(start2, "%Y-%m-%d %H:%M:%S") now_time = datetime.datetime.now() f2 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist3 = f2.readlines()[4:5] feature_title = datalist3[0][:36] feature_title1 = feature_title.replace('\n', '') url = advis_url + "/v1/performance-status?screen=%s&performance_datetime=%s" % ( screen1, start1) not_find_str = screen1 + "号厅" + feature_title1 + '影片在' + start1 + '场次未找到对应占位符匹配的内容包' find_str = screen1 + "号厅" + feature_title1 + '影片在' + start1 + '场次已添加对应占位符匹配的内容包CPL' resp = requests.request("GET", url) resp2 = resp.json() if (resp2.get('Packs')): return find_str else: if (source_start - now_time) < datetime.timedelta(hours=2): if schedule_validate(): return find_str + '(保护场次)' else: return not_find_str else: return not_find_str
def delete_pack(): headers = {'Content-Type': 'application/json'} f = open(root.get_root_path() + "/output/pack_uuid.txt", "r") a = list(f) a1 = [x.strip() for x in a if x.strip() != ""] payload = {"pack_uuids": a1} resp = requests.post(api + '/core/pack/delete', json=payload, cookies=dict(tms2_9000=get_tooken()))
def query_pos(): time1 = str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) source_start = datetime.datetime.strptime(time1, "%Y-%m-%d %H:%M:%S") source_start2 = source_start + datetime.timedelta(days=14) time2 = datetime.datetime.strftime(source_start2, "%Y-%m-%d %H:%M:%S") cursor.execute( "SELECT pos.uuid,pos.screen_identifier,pos.source_start,pos.feature_id,pos.feature_title,external_device_map.device_uuid FROM pos JOIN external_device_map ON pos.screen_identifier=external_device_map.external_id WHERE source_start > '%s' AND source_start < '%s' " % (time1, time2)) result = cursor.fetchone() if result: pos_uuid = result[0] screen = result[1] for k, i in enumerate(screen): if i != '0': _screen = screen[k:] break source_start = result[2] start = str(source_start) start = start.replace(' ', 'T') feature_id = result[3] feature_title = result[4] device_uuid = result[5] with open(root.get_root_path() + '/output/pos_info.txt', 'w') as f: f.write(pos_uuid + '\n') f.write(_screen + '\n') f.write(start + '\n') f.write(feature_id + '\n') f.write(feature_title + '\n') f.write(device_uuid + '\n') else: print('数据库查询POS数据为空或POS数据已过期,请添加POS后再运行') input('输入任意键退出...') sys.exit(0) connent.commit() connent.close()
def request(self): #feature_id = '00110492201701' #feature_title = "老兽" # state = assigned' # if DBQuery.is_exist( # self._url, # 'Pos', "state = '{}'".format(state), cookies=sw_db.database['cookies']): # #print ('正片:' + feature_id + '已匹配播放列表') # return # screen_list = DBQuery.query_list(self._url, 'Screen', None, limit=250) if screen_list is None or len(screen_list) == 0: print('找不到screen_list') data = [] for screen in screen_list: screen_uuid = screen['uuid'] txt = [] for line in open( root.get_root_path() + "/output/playlist_uuid.txt", "r"): # 设置文件对象并读取每一行文件 txt.append(line) # 将每一行文件加入到list中 playlist_uuid = txt[0][:36] print(playlist_uuid) data.append({ "feature_id": self.feature['feature_id'], "playlist_uuid": playlist_uuid, "screen_uuid": screen_uuid, "feature_title": self.feature['feature_title'] }) _JSON = {'schedule_update_map': data} resp = requests.post(self._url + '/core/playlist/save_spl_mappings', json=_JSON, cookies=sw_db.database['cookies']) return resp
def query_pack(): payload = { "sEcho": 1, "iColumns": 12, "sColumns": "", "iDisplayStart": 0, "iDisplayLength": 100, "mDataProp_0": "uuid", "mDataProp_1": "function", "mDataProp_2": "function", "mDataProp_3": "function", "mDataProp_4": "function", "mDataProp_5": "function", "mDataProp_6": "function", "mDataProp_7": "function", "mDataProp_8": "function", "mDataProp_9": "function", "mDataProp_10": "function", "mDataProp_11": "function", "sSearch": "", "bRegex": False, "sSearch_0": "", "bRegex_0": False, "bSearchable_0": True, "sSearch_1": "", "bRegex_1": False, "bSearchable_1": False, "sSearch_2": "", "bRegex_2": False, "bSearchable_2": True, "sSearch_3": "", "bRegex_3": False, "bSearchable_3": True, "sSearch_4": "", "bRegex_4": False, "bSearchable_4": True, "sSearch_5": "", "bRegex_5": False, "bSearchable_5": False, "sSearch_6": "", "bRegex_6": False, "bSearchable_6": False, "sSearch_7": "", "bRegex_7": False, "bSearchable_7": False, "sSearch_8": "", "bRegex_8": False, "bSearchable_8": False, "sSearch_9": "", "bRegex_9": False, "bSearchable_9": True, "sSearch_10": "", "bRegex_10": False, "bSearchable_10": True, "sSearch_11": "", "bRegex_11": False, "bSearchable_11": True, "iSortCol_0": 3, "sSortDir_0": "asc", "iSortCol_1": 2, "sSortDir_1": "asc", "iSortingCols": 2, "bSortable_0": False, "bSortable_1": False, "bSortable_2": True, "bSortable_3": True, "bSortable_4": True, "bSortable_5": False, "bSortable_6": True, "bSortable_7": True, "bSortable_8": False, "bSortable_9": True, "bSortable_10": True, "bSortable_11": False, "placeholder_filter": None, "screen_number_filter": None, "rating_filter": None } resp = requests.post(api + '/core/paginated/get_datatables_packs', json=payload, cookies=dict(tms2_9000=get_tooken())) json_obj = json.loads(resp.content) filename = 'write_data.txt' with open(root.get_root_path() + '/output/pack_uuid.txt', 'w') as f: for data in json_obj['aaData']: uuid = data['uuid'] f.write(uuid + '\n')
def single_run(self): ConfigReader.read_config() server_url = ConfigReader.get_string('server', 'url') username = ConfigReader.get_string('account', 'username') password = ConfigReader.get_string('account', 'password') # 模拟登陆 Login(server_url, username, password).execute() #生成LMS的uuid到一个txt文件上 GetLmsUuid(server_url).execute() #配置->通用->Advanced->pos_spl_mapping_enabled 开关 InitAdvancedSpl(server_url).execute() #配置->通用->POS设置 InitPOSSetting(server_url).execute() #配置->影院设备 InitPOSSystem(server_url).execute() #查询POS信息 query_pos() #下发pack(screevision样本、ncm样本) #pack_screenvision() pack_ncm() #创建、查询占位符 Create_Placeholder(server_url).execute() GetPlaceholderUuid(server_url).execute() #创建playlist CreatePlaylist(server_url).execute() #playlist匹配POS场次 PosMapping(server_url).execute() #获取POS f = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist = f.readlines()[1:2] screen = datalist[0][:36] screen1 = screen.replace('\n', '') f1 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist2 = f1.readlines()[2:3] start = datalist2[0][:36] start1 = start.replace('\n', '') f2 = open(root.get_root_path() + "/output/pos_info.txt", "r") datalist3 = f2.readlines()[4:5] feature_title = datalist3[0][:36] feature_title1 = feature_title.replace('\n', '') #统计测试结果变量 send_pack = True delete_pack = True alter_pack = True alter_delete = True #排期同步 ScheduleSync(server_url).execute() print("下发Pack且排期同步后,期望结果:\n" + screen1 + "号厅" + feature_title1 + '影片在' + start1 + "场次应添加对应占位符匹配的内容包CPL") logging.info("下发Pack且排期同步后,期望结果:\n %s号厅 %s影片在 %s场次应添加对应占位符匹配的内容包CPL" % (screen1, feature_title1, start1)) time.sleep(30) print("排期同步完成校验排期,实际结果:") logging.info("排期同步完成校验排期,实际结果:") res = performance() print(res) logging.info(res) if '已添加' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') else: print('测试结果:不通过!!!\n') send_pack = False logging.info('测试结果:不通过!!!\n') time.sleep(20) #查询pack、删除pack #query_pack() #delete_pack() delete_pack2() # 排期同步 ScheduleSync(server_url).execute() print("删除Pack且排期同步后,期望结果:\n" + screen1 + "号厅" + feature_title1 + '影片在' + start1 + "场次找不到对应占位符匹配的内容包(保护场次不受Pack删除影响)") logging.info( "删除Pack且排期同步后,期望结果:\n %s号厅 %s影片在 %s场次找不到对应占位符匹配的内容包(保护场次不受Pack删除影响)" % (screen1, feature_title1, start1)) #time.sleep(30) print("排期同步完成校验排期,实际结果:") logging.info("排期同步完成校验排期,实际结果:") res = performance() print(res) logging.info(res) if '未找到' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') elif '保护场次' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') else: print('测试结果:不通过!!!\n') delete_pack = False logging.info('测试结果:不通过!!!\n') time.sleep(20) #下发pack(screevision样本、ncm样本) #pack_screenvision() pack_ncm2() # 排期同步 ScheduleSync(server_url).execute() print("修改Pack且排期同步后,期望结果:\n" + screen1 + "号厅" + feature_title1 + '影片在' + start1 + "场次应添加对应占位符匹配的内容包CPL(保护场次不受Pack修改影响)") logging.info( "修改Pack且排期同步后,期望结果:\n %s号厅 %s影片在 %s场次应添加对应占位符匹配的内容包CPL(保护场次不受Pack修改影响)" % (screen1, feature_title1, start1)) time.sleep(30) print("排期同步完成校验排期,实际结果:") logging.info("排期同步完成校验排期,实际结果:") res = performance() print(res) logging.info(res) if '已添加' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') else: print('测试结果:不通过!!!\n') alter_pack = False logging.info('测试结果:不通过!!!\n') time.sleep(20) # 查询pack、删除pack # query_pack() # delete_pack() delete_pack2() # 排期同步 ScheduleSync(server_url).execute() print("删除Pack且排期同步后,期望结果:\n" + screen1 + "号厅" + feature_title1 + '影片在' + start1 + "场次找不到对应占位符匹配的内容包(保护场次不受Pack删除影响)") logging.info("删除Pack且排期同步后,期望结果:\n" + screen1 + "号厅" + feature_title1 + '影片在' + start1 + "场次找不到对应占位符匹配的内容包(保护场次不受Pack删除影响)") time.sleep(30) print("排期同步完成校验排期,实际结果:") logging.info("排期同步完成校验排期,实际结果:") res = performance() print(res) logging.info(res) if '未找到' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') elif '保护场次' in res: print('测试结果:通过\n') logging.info('测试结果:通过\n') else: print('测试结果:不通过!!!\n') alter_delete = False logging.info('测试结果:不通过!!!\n') print('Advis测试结果统计:') logging.info('Advis测试结果统计:') if send_pack: print('Pack下发测试结果: %s' % '通过') logging.info('Pack下发测试结果: %s' % '通过') else: print('Pack下发测试结果: %s' % '不通过') logging.info(('Pack下发测试结果: %s' % '不通过')) if delete_pack: print('Pack删除测试结果: %s' % '通过') logging.info('Pack删除测试结果: %s' % '通过') else: print('Pack删除结果: %s' % '不通过') logging.info(('Pack删除测试结果: %s' % '不通过')) if alter_pack: print('Pack修改测试结果: %s' % '通过') logging.info('Pack修改测试结果: %s' % '通过') else: print('Pack修改测试结果: %s' % '不通过') logging.info(('Pack修改测试结果: %s' % '不通过')) if alter_delete: print('Pack删除测试结果: %s' % '通过') logging.info('Pack删除测试结果: %s' % '通过') else: print('Pack删除测试结果: %s' % '不通过') logging.info(('Pack删除测试结果: %s' % '不通过')) print('\n')
def multi_run(self, cvs_path): # 初始化多服务器设备 InitDeviceBatchMulti(root.get_root_path() + cvs_path).execute()
def request(self): txt = [] for line in open(root.get_root_path() + "/output/lms_uuid.txt", "r"): # 设置文件对象并读取每一行文件 txt.append(line) # 将每一行文件加入到list中 device_uuid = txt[0][:36] data = { "sEcho": 1, "iColumns": 10, "sColumns": "", "iDisplayStart": 0, "iDisplayLength": 100, "mDataProp_0": "function", "mDataProp_1": "function", "mDataProp_2": "function", "mDataProp_3": "function", "mDataProp_4": "function", "mDataProp_5": "function", "mDataProp_6": "function", "mDataProp_7": "function", "mDataProp_8": "function", "mDataProp_9": "function", "sSearch": "", "bRegex": False, "sSearch_0": "", "bRegex_0": False, "bSearchable_0": True, "sSearch_1": "", "bRegex_1": False, "bSearchable_1": True, "sSearch_2": "", "bRegex_2": False, "bSearchable_2": True, "sSearch_3": "", "bRegex_3": False, "bSearchable_3": True, "sSearch_4": "", "bRegex_4": False, "bSearchable_4": True, "sSearch_5": "", "bRegex_5": False, "bSearchable_5": True, "sSearch_6": "", "bRegex_6": False, "bSearchable_6": True, "sSearch_7": "", "bRegex_7": False, "bSearchable_7": True, "sSearch_8": "", "bRegex_8": False, "bSearchable_8": True, "sSearch_9": "", "bRegex_9": False, "bSearchable_9": True, "iSortCol_0": 3, "sSortDir_0": "asc", "iSortingCols": 1, "bSortable_0": False, "bSortable_1": False, "bSortable_2": False, "bSortable_3": False, "bSortable_4": True, "bSortable_5": True, "bSortable_6": True, "bSortable_7": True, "bSortable_8": True, "bSortable_9": False, "device_uuid": device_uuid } resp = requests.post(self._url + '/core/paginated/get_datatables_playlists', json=data, cookies=sw_db.database['cookies']) return resp