Pārlūkot izejas kodu

v0.6
新增articles_match接口

罗俊辉 1 gadu atpakaļ
vecāks
revīzija
990b7dde43
3 mainītis faili ar 85 papildinājumiem un 2 dzēšanām
  1. 2 1
      deal/__init__.py
  2. 67 0
      deal/algorithm_deal.py
  3. 16 1
      routes/vta_routes.py

+ 2 - 1
deal/__init__.py

@@ -4,4 +4,5 @@
 from .videos_deal import RequestDeal
 from .publish_deal import PublishDeal
 from .db_deal import insert_text_mysql, get_text_by_id
-from .articles_deal import ArticleGeneral
+from .articles_deal import ArticleGeneral
+from .algorithm_deal import ArticleMatchAccount

+ 67 - 0
deal/algorithm_deal.py

@@ -0,0 +1,67 @@
+"""
+@author: luojunhui
+"""
+import json
+import requests
+
+
+class ArticleMatchAccount(object):
+    """
+    文章匹配小程序
+    """
+    base_url = 'http://192.168.100.31:8179'
+    account_list = None
+    text_list = None
+    rate = 0.1
+    min_time = None
+    max_time = None
+    interest_type = None
+    sim_type = "mean"
+    keys = ["Title", "show_view_count"]
+
+    def __init__(self, params):
+        self.params = params
+
+    def check_params(self):
+        """
+        check param
+        :return:
+        """
+        try:
+            self.account_list = self.params['accountList']
+            self.text_list = self.params['textList']
+            self.rate = self.params.get("rate", 0.1)
+            self.min_time = self.params.get("min_time", None)
+            self.max_time = self.params.get("max_time", None)
+            self.interest_type = self.params.get("interest_type", "by_avg")
+            self.sim_type = self.params.get("sim_type", "mean")
+            self.keys = self.params.get("keys", ["Title", "show_view_count"])
+            return None
+        except AttributeError as e:
+            return {'error': "params error:  {}".format(e)}
+
+    def get_score_list(self):
+        """
+        get score list
+        :return:
+        """
+        api_url = f'{self.base_url}/score_list'
+        payload = json.dumps({
+            "account_nickname_list": self.account_list,
+            "text_list": self.text_list,
+            "max_time": self.max_time,
+            "min_time": self.min_time,
+            "interest_type": self.interest_type,
+            "sim_type": self.sim_type,
+            "rate": self.rate,
+        })
+        res = requests.request("POST", api_url, headers={}, data=payload).json()
+        return res
+
+    def deal(self):
+        """
+        deal function
+        :return:
+        """
+        return self.check_params() if self.check_params() else self.get_score_list()
+

+ 16 - 1
routes/vta_routes.py

@@ -3,7 +3,11 @@
 """
 from quart import Blueprint, jsonify, request
 
-from deal import RequestDeal, insert_text_mysql, get_text_by_id, PublishDeal, ArticleGeneral
+from deal import RequestDeal
+from deal import ArticleMatchAccount
+from deal import ArticleGeneral
+from deal import PublishDeal
+from deal import insert_text_mysql, get_text_by_id
 from applications.functions import whisper
 
 
@@ -81,6 +85,17 @@ def VTARoutes(mysql_client):
         res = A.deal()
         return jsonify(res)
 
+    @bp.route("/match", methods=["POST"])
+    async def match_account():
+        """
+        匹配小程序
+        :return:
+        """
+        params = await request.get_json()
+        MA = ArticleMatchAccount(params=params)
+        res = MA.deal()
+        return jsonify(res)
+
     return bp