ad_json_add_unity.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # coding=utf-8
  2. """ 升级 ad.json 增加unity """
  3. from sdk.tool.ad_json_6 import *
  4. def _print_script_info():
  5. print "************************************************************"
  6. print "* 脚本作用: 更新ad.json 添加unity广告"
  7. print "* 参数说明:"
  8. print "* Unity的AppId"
  9. print "* 源ad.json文件路径"
  10. print "* 转换后写入ad.json文件路径(为空则写入源文件)"
  11. print "* 例:"
  12. print "* cd /project/my_project/res"
  13. print "* **/bulldog ad_json_unity 12345 ad.json ad_unity.json"
  14. print "************************************************************"
  15. print ""
  16. def _add_unity(ad_json, ad_type):
  17. pool = ad_json.get_pool(ad_type, AD_PLATFROM.UNITY)
  18. if pool is not None:
  19. Logging.error("已经存在{}池".format(AD_PLATFROM.string(AD_PLATFROM.UNITY)))
  20. exit(0)
  21. pool = AdPool({})
  22. unity_ids = [
  23. "unity_inter_I1_lv1",
  24. "unity_inter_I1_lv2",
  25. "unity_inter_I2_lv1",
  26. "unity_inter_I2_lv2"
  27. ]
  28. pool_configs = {
  29. unity_ids[0]: 4,
  30. unity_ids[1]: 6,
  31. unity_ids[2]: 8,
  32. unity_ids[3]: 10
  33. }
  34. for ad_id in pool_configs:
  35. p = pool_configs[ad_id]
  36. pool.add_ad_id(ad_id, p)
  37. ad_json.add_pool(ad_type, AD_PLATFROM.UNITY, pool)
  38. strategy = ad_json.get_strategy(ad_type, AD_PLATFROM.UNITY)
  39. if strategy is not None:
  40. Logging.error("已经存在{}池策略".format(AD_PLATFROM.string(AD_PLATFROM.UNITY)))
  41. exit(0)
  42. strategy = AdStrategy(AD_PLATFROM.UNITY)
  43. strategy.update(unity_ids)
  44. ad_json.add_strategy(ad_type, AD_PLATFROM.UNITY, strategy)
  45. for page in ad_json.get_ad_pages(ad_type):
  46. page.add_pool(AD_PLATFROM.string(AD_PLATFROM.UNITY))
  47. def add_unity(unity_app_id, old_ad_json_path, to_ad_json_path):
  48. print "源ad.json: {}".format(old_ad_json_path)
  49. ad_json = AdJson6()
  50. ad_json.read(old_ad_json_path)
  51. ad_json.add_platform_id(RED_SDK_AD_PLATFORM.UNITY, unity_app_id)
  52. _add_unity(ad_json, AD_TYPE.INTERSTITIAL)
  53. print "--------------------------"
  54. ad_json.print_desc()
  55. # 写入
  56. ad_json.write(to_ad_json_path)
  57. print "目标ad.json写入成功: {}".format(to_ad_json_path)
  58. def run(argv):
  59. _print_script_info()
  60. if len(argv) < 4:
  61. Logging.error("参数个数小于3个")
  62. exit(0)
  63. unity_app_id = argv[1]
  64. from_path = argv[2]
  65. to_path = argv[3]
  66. Logging.info("unity_app_id: {}".format(unity_app_id))
  67. Logging.info("from_path: {}".format(from_path))
  68. Logging.info("to_path: {}".format(to_path))
  69. add_unity(unity_app_id, from_path, to_path)
  70. if __name__ == '__main__':
  71. argv = [
  72. "ad_json_add_unity.py",
  73. "unity_app_id",
  74. "/Users/zhuge/Temp/20201226/test/ad.json",
  75. "/Users/zhuge/Temp/20201226/test/ad_unity.json"
  76. ]
  77. run(argv)