Commit 5be95f1e authored by 赵威's avatar 赵威

write data to es

parent 0202312e
......@@ -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,21 +40,44 @@ def user_portrait_scan_info():
print(e)
def _dict_to_name_score(d):
res = []
for (k, v) in d.items():
res.append({"name": k, "score": 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"] = anecdote_tags
es_insert_device_info(device_id, body)
if __name__ == "__main__":
# device_id = "androidid_a25a1129c0b38f7b"
# write_to_es(device_id)
device_id = "androidid_a25a1129c0b38f7b"
write_to_es(device_id)
user_portrait_scan_info()
# user_portrait_scan_info()
print("done: " + str(datetime.datetime.now()))
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