# coding=utf-8 """ 升级 ad.json 增加unity """ from sdk.tool.ad_json_6 import * def _print_script_info(): print "************************************************************" print "* 脚本作用: 更新ad.json 添加unity广告" print "* 参数说明:" print "* Unity的AppId" print "* 源ad.json文件路径" print "* 转换后写入ad.json文件路径(为空则写入源文件)" print "* 例:" print "* cd /project/my_project/res" print "* **/bulldog ad_json_unity 12345 ad.json ad_unity.json" print "************************************************************" print "" def _add_unity(ad_json, ad_type): pool = ad_json.get_pool(ad_type, AD_PLATFROM.UNITY) if pool is not None: Logging.error("已经存在{}池".format(AD_PLATFROM.string(AD_PLATFROM.UNITY))) exit(0) pool = AdPool({}) unity_ids = [ "unity_inter_I1_lv1", "unity_inter_I1_lv2", "unity_inter_I2_lv1", "unity_inter_I2_lv2" ] pool_configs = { unity_ids[0]: 4, unity_ids[1]: 6, unity_ids[2]: 8, unity_ids[3]: 10 } for ad_id in pool_configs: p = pool_configs[ad_id] pool.add_ad_id(ad_id, p) ad_json.add_pool(ad_type, AD_PLATFROM.UNITY, pool) strategy = ad_json.get_strategy(ad_type, AD_PLATFROM.UNITY) if strategy is not None: Logging.error("已经存在{}池策略".format(AD_PLATFROM.string(AD_PLATFROM.UNITY))) exit(0) strategy = AdStrategy(AD_PLATFROM.UNITY) strategy.update(unity_ids) ad_json.add_strategy(ad_type, AD_PLATFROM.UNITY, strategy) for page in ad_json.get_ad_pages(ad_type): page.add_pool(AD_PLATFROM.string(AD_PLATFROM.UNITY)) def add_unity(unity_app_id, old_ad_json_path, to_ad_json_path): print "源ad.json: {}".format(old_ad_json_path) ad_json = AdJson6() ad_json.read(old_ad_json_path) ad_json.add_platform_id(RED_SDK_AD_PLATFORM.UNITY, unity_app_id) _add_unity(ad_json, AD_TYPE.INTERSTITIAL) print "--------------------------" ad_json.print_desc() # 写入 ad_json.write(to_ad_json_path) print "目标ad.json写入成功: {}".format(to_ad_json_path) def run(argv): _print_script_info() if len(argv) < 4: Logging.error("参数个数小于3个") exit(0) unity_app_id = argv[1] from_path = argv[2] to_path = argv[3] Logging.info("unity_app_id: {}".format(unity_app_id)) Logging.info("from_path: {}".format(from_path)) Logging.info("to_path: {}".format(to_path)) add_unity(unity_app_id, from_path, to_path) if __name__ == '__main__': argv = [ "ad_json_add_unity.py", "unity_app_id", "/Users/zhuge/Temp/20201226/test/ad.json", "/Users/zhuge/Temp/20201226/test/ad_unity.json" ] run(argv)