Commit 77e6719a authored by 赵威's avatar 赵威

add monitor

parent 1a4e0fff
import base64
import hashlib
import hmac
import json
import time
import urllib
import requests
def send_msg_to_dingtalk(msg, mobiles=[]):
try:
secret = "SECffcdd05c1bb9ca2e6268b2593e4891872c5d0a8adf6751915bc77583076ed0b7"
timestamp = str(round(time.time() * 1000))
secret_enc = secret.encode("utf-8")
string_to_sign = "{}\n{}".format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode("utf-8")
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
headers = {"Content-Type": "application/json"}
data = {"msgtype": "text", "text": {"content": msg}}
if mobiles:
data = {"msgtype": "text", "text": {"content": msg}, "at": {"atMobiles": mobiles, "isAtAll": False}}
json_data = json.dumps(data)
url = "https://oapi.dingtalk.com/robot/send?access_token=661cf4d772916d54597d5cd1636fbc6890ef220908dd1f81fe074f44896b6aa2&sign={}&timestamp={}".format(
sign, timestamp)
response = requests.post(url=url, data=json_data, headers=headers)
return str(response.status_code) + " " + str(response.content.decode("utf-8"))
except Exception as e:
print(e)
return str(e)
...@@ -9,7 +9,7 @@ model_dir = os.path.join(base_dir, "_models") ...@@ -9,7 +9,7 @@ model_dir = os.path.join(base_dir, "_models")
data_dir = os.path.join(base_dir, "_data") data_dir = os.path.join(base_dir, "_data")
if __name__ == "__main__": if __name__ == "__main__":
id1 = ["202647", "386735"] # 下颚角 5/1252645 id1 = ["202647", "386735"] # 下颚角 9/1252645
id2 = ["87874", "84198"] # 双眼皮 95 id2 = ["87874", "84198"] # 双眼皮 95
with open(os.path.join(data_dir, "click_tractate_ids.csv"), "r") as f: with open(os.path.join(data_dir, "click_tractate_ids.csv"), "r") as f:
......
import multiprocessing import multiprocessing
import os import os
import time import time
import traceback
from gensim.models import Word2Vec, word2vec from gensim.models import Word2Vec, word2vec
from gm_rpcd.all import bind from gm_rpcd.all import bind
from utils.es import es_scan from utils.es import es_scan
from utils.message import send_msg_to_dingtalk
base_dir = os.getcwd() base_dir = os.getcwd()
print("base_dir: " + base_dir) print("base_dir: " + base_dir)
...@@ -48,7 +50,12 @@ def w2v_train(f_name, model_output_name): ...@@ -48,7 +50,12 @@ def w2v_train(f_name, model_output_name):
@bind("strategy_embedding/word_vector/word_similarity") @bind("strategy_embedding/word_vector/word_similarity")
def word_similarity(word): def word_similarity(word):
try:
return WORD2VEC_MODEL.wv.most_similar(word) return WORD2VEC_MODEL.wv.most_similar(word)
except Exception as e:
send_msg_to_dingtalk(str(e) + "\n" + str(traceback.format_exc()))
print(traceback.format_exc())
return []
def get_user_portrait_projects(score_limit=5): def get_user_portrait_projects(score_limit=5):
...@@ -106,6 +113,8 @@ def clicked_tractate_ids_item2vec_model(id, n=5): ...@@ -106,6 +113,8 @@ def clicked_tractate_ids_item2vec_model(id, n=5):
try: try:
return TRACTATE_CLICK_IDS_MODEL.wv.most_similar(id, topn=n) return TRACTATE_CLICK_IDS_MODEL.wv.most_similar(id, topn=n)
except Exception as e: except Exception as e:
send_msg_to_dingtalk(str(e) + "\n" + str(traceback.format_exc()))
print(traceback.format_exc())
return [] return []
......
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