Commit ba89d3ae authored by 赵威's avatar 赵威

Merge branch 'offic' into 'master'

Offic

See merge request !65
parents e03712e8 bfb7621f
......@@ -46,7 +46,7 @@ def es_insert_device_info(device_id, body, es=None, rw=None):
if es is None:
es = get_es()
index = es_index_adapt(index_prefix="gm-dbmw", doc_type="device", rw=None)
bulk_head = '{"index": {"_id":"%s"}}' % device_id
bulk_head = '{"index": {"_id": "%s"}}' % device_id
data_str = json.dumps(body, ensure_ascii=False)
bulk_one_body = bulk_head + "\n" + data_str + "\n"
return es.bulk(index=index, doc_type="device", body=bulk_one_body)
......@@ -4,7 +4,7 @@ import pytz
import redis
from es_tool import es_insert_device_info
from tool import get_user_portrait_tag3_from_redis
from tool import (get_user_portrait_tag3_from_redis, get_user_portrait_tag3_with_score)
redis_client = redis.StrictRedis.from_url("redis://:ReDis!GmTx*0aN6@172.16.40.133:6379")
redis_client2 = redis.StrictRedis.from_url("redis://:ReDis!GmTx*0aN9@172.16.40.173:6379")
......@@ -40,14 +40,38 @@ def user_portrait_scan_info():
print(e)
def _dict_to_name_score(d):
res = []
new_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
for (k, v) in new_d:
res.append({"name": k, "score": float(v)})
return res
def write_to_es(device_id):
body = get_user_portrait_tag3_from_redis(device_id)
if body:
body = {}
d = get_user_portrait_tag3_with_score(device_id)
if d:
first_demands_d = d.get("first_demands", {})
second_demands_d = d.get("second_demands", {})
first_positions_d = d.get("first_positions", {})
second_positions_d = d.get("second_positions", {})
first_solutions_d = d.get("first_solutions", {})
second_solutions_d = d.get("second_solutions", {})
projects_d = d.get("projects", {})
anecdote_tags = d.get("anecdote_tags", {})
body["device_id"] = device_id
body["last_modified"] = datetime.datetime.strftime(datetime.datetime.now(pytz.timezone("Asia/Shanghai")),
"%Y-%m-%dT%H:%M:%S.%f")[:-7] + "Z"
body["city_cn"] = ""
body["city_en"] = ""
body["first_demands"] = _dict_to_name_score(first_demands_d)
body["second_demands"] = _dict_to_name_score(second_demands_d)
body["first_positions"] = _dict_to_name_score(first_positions_d)
body["second_positions"] = _dict_to_name_score(second_positions_d)
body["first_solutions"] = _dict_to_name_score(first_solutions_d)
body["second_solutions"] = _dict_to_name_score(second_solutions_d)
body["projects"] = _dict_to_name_score(projects_d)
body["anecdote_tags"] = _dict_to_name_score(anecdote_tags)
es_insert_device_info(device_id, body)
......
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