Commit 52e7b5cd by zhaoyanchao

修改脚本

parent 997e6ca2
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
import requests import requests
import codecs import codecs
import sys import sys
import traceback
reload(sys) reload(sys)
sys.setdefaultencoding('utf-8') sys.setdefaultencoding('utf-8')
...@@ -29,9 +31,12 @@ def trans_brand_id_2_name(brand_id): ...@@ -29,9 +31,12 @@ def trans_brand_id_2_name(brand_id):
try: try:
res = requests.get(solr_brand_query_url + str(brand_id)) res = requests.get(solr_brand_query_url + str(brand_id))
result = res.json() result = res.json()
return result.get('response')['docs'][0]['brandCName'] docs = result.get('response')['docs']
if len(docs)>0:
return docs[0]['brandCName']
return 'NO_BRAND_IN_SOLR'
except Exception as err: except Exception as err:
print(err) traceback.print_exc()
...@@ -68,7 +73,7 @@ def get_favor_brands(device_id): ...@@ -68,7 +73,7 @@ def get_favor_brands(device_id):
favor_brands.other_brand_names += trans_brand_id_2_name(brand_id) + ", " favor_brands.other_brand_names += trans_brand_id_2_name(brand_id) + ", "
except Exception as err: except Exception as err:
print(err) traceback.print_exc()
return favor_brands return favor_brands
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import requests import requests
import codecs import codecs
import sys
import traceback
file_path = r'G:\Code\python\search_custom_analyse\data\cateword_but_no_hit.txt' file_path = r'G:\Code\python\search_custom_analyse\data\cateword_but_no_hit.txt'
user_profile_file = r'user_brand_favor.txt' user_profile_file = r'user_brand_favor.txt'
...@@ -27,8 +29,11 @@ def trans_brand_id_2_name(brand_id): ...@@ -27,8 +29,11 @@ def trans_brand_id_2_name(brand_id):
res = requests.get(solr_brand_query_url + str(brand_id)) res = requests.get(solr_brand_query_url + str(brand_id))
result = res.json() result = res.json()
return result.get('response')['docs'][0]['brandCName'] return result.get('response')['docs'][0]['brandCName']
if len(docs)>0:
return docs[0]['brandCName']
return 'NO_BRAND_IN_SOLR'
except Exception as err: except Exception as err:
print(err) traceback.print_exc()
...@@ -64,7 +69,7 @@ def get_favor_brands(device_id): ...@@ -64,7 +69,7 @@ def get_favor_brands(device_id):
favor_brands.other_brand_names += trans_brand_id_2_name(brand_id) + ", " favor_brands.other_brand_names += trans_brand_id_2_name(brand_id) + ", "
except Exception as err: except Exception as err:
print(err) traceback.print_exc()
return favor_brands return favor_brands
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment