def check_cpa_platform2(rows): param = [] for r in rows: try: content = r.content.encode("utf-8") js_param_dic = set_cpa_platform_param(content.split("\t")) # print "running -->", js_param_dic.cpid post_result = utils.post_cpa_platform(json.dumps(js_param_dic, ensure_ascii=False)) match_rs = get_merge_info(post_result, js_param_dic) print match_rs if match_rs: # cmr = match_rs.replace(',', '\t ') poiid = '-1' cpa_msg = str(post_result.retResult) if not isinstance(match_rs, tuple): ls = match_rs.split(',') if len(ls) > 2: _poiid = ls[1].rstrip() if _poiid: poiid = _poiid cpa_msg = 'retry' param.append((poiid, "".join(match_rs), 2, cpa_msg, cpname, js_param_dic.cpid)) if len(param) > 10: conn.executemany(update, param) del param[0:] except: pass conn.executemany(update, param)
def check_cpa_platform(): """ 调用准入平台接口, match接口 """ with open("src_f", 'r') as fl, open("matche", 'w') as mt, open("unmatche", 'w') as no: for line in fl: js_param_dic = set_cpa_platform_param(line[:-1].split("\t")) # print "running -->", js_param_dic.cpid post_result = utils.post_cpa_platform(json.dumps(js_param_dic, ensure_ascii=False)) match_rs = get_merge_info(post_result, js_param_dic) if match_rs and not isinstance(match_rs, tuple): cmr = check_match_result(match_rs, line, no) if cmr: mt.write(cmr + '\t' + line) else: # print js_param_dic.cpid, match_rs no.write(line) mt.flush() no.flush()