123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- # coding=utf-8
- import os
- import json
- import sys
- import urllib2
- def GetFromWeb(package_name, tmp_response_txt_path):
- if False:
- with open(tmp_response_txt_path) as f:
- return json.load(f)
- url = "http://usertrack.appcpi.net/jinxihua/ec.php?packagename={}".format(package_name)
- print "请求网址: {}".format(url)
- print "请求线上ecpm中..."
- res_data = urllib2.urlopen(url)
- ret = res_data.read()
- if ret == "":
- sys.stderr.write("未能获取到数据!请检查包名、网络情况、是否在ROI系统内、是否是新上线的项目")
- return {}
- with open(tmp_response_txt_path, "w") as f:
- f.write(ret)
- print "请求结束,返回数据已写入:{}".format(tmp_response_txt_path)
- with open(tmp_response_txt_path) as ff:
- ad_config_json = json.load(ff)
- return ad_config_json
- def ParseAdConfig(ad_config_json):
- dic_counties = {}
- for ad_info in ad_config_json:
- ecpm = ad_config_json[ad_info]
- if ecpm > 0:
- arr = ad_info.split("_")
- ad_id = arr[0]
- country = arr[1]
- dic_country = {}
- if dic_counties.has_key(country):
- dic_country = dic_counties[country]
- else:
- dic_counties[country] = dic_country
- dic_country[ad_id] = ecpm
- return dic_counties
- def PrintConfigInfo(ad_worth):
- admobs = []
- facebooks = []
- for country in ad_worth:
- for ad_id in ad_worth[country]:
- if ad_id.startswith("ca-app"):
- if not admobs.__contains__(ad_id):
- admobs.append(ad_id)
- else:
- if not facebooks.__contains__(ad_id):
- facebooks.append(ad_id)
- print "共获取到Admob广告ID {} 个".format(len(admobs))
- for ad_id in admobs:
- print "\t{}".format(ad_id)
- print "共获取到Facebook广告ID {} 个".format(len(facebooks))
- for ad_id in facebooks:
- print "\t{}".format(ad_id)
- print "共获取到国家 {} 个".format(len(ad_worth))
- def main():
- package_name = sys.argv[1]
- current_dir = os.path.dirname(__file__)
- tmp_response_txt_path = os.path.join(current_dir, "response.txt")
- ad_config_json = GetFromWeb(package_name, tmp_response_txt_path)
- if len(ad_config_json) == 0:
- return
- ad_worth = ParseAdConfig(ad_config_json)
- PrintConfigInfo(ad_worth)
- ad_worth = {
- "countries": ad_worth
- }
- write_to_path = os.path.join(current_dir, "ad_worth.json")
- with open(write_to_path, "w") as ff:
- json.dump(ad_worth, ff)
- print "ad_worth.json生成完成: {}".format(write_to_path)
- if len(sys.argv) < 2:
- sys.stderr.write("输入有误")
- print "使用方法:python ad_worth_6.1.4.py com.your.package"
- print "注:iOS需要传入字符串的bundle id,而非数字版的app id!!!"
- else:
- main()
|