Procházet zdrojové kódy

删除冗余代码

dzr před 5 měsíci
rodič
revize
0d3c0294b6
3 změnil soubory, kde provedl 0 přidání a 148 odebrání
  1. 0 43
      utils/aliyun.py
  2. 0 55
      utils/es_query.py
  3. 0 50
      utils/title_participle.py

+ 0 - 43
utils/aliyun.py

@@ -1,43 +0,0 @@
-import oss2
-
-
-# 远程bucket配置
-oss_conf = {
-    "key_id": "LTAI4G5x9aoZx8dDamQ7vfZi",
-    "key_secret": "Bk98FsbPYXcJe72n1bG3Ssf73acuNh",
-    # "endpoint": "oss-cn-beijing-internal.aliyuncs.com",
-    "endpoint": "oss-cn-beijing.aliyuncs.com",
-    "bucket_name": "jy-datafile"
-}
-
-
-class AliYunService:
-
-    def __init__(self):
-        self.__acc_key_id = oss_conf['key_id']
-        self.__acc_key_secret = oss_conf['key_secret']
-        self.__endpoint = oss_conf['endpoint']
-        self.__bucket_name = oss_conf['bucket_name']
-
-    def push_oss_from_local(self, key, filename):
-        """
-        上传一个本地文件到OSS的普通文件
-
-        :param str key: 上传到OSS的文件名
-        :param str filename: 本地文件名,需要有可读权限
-        """
-        auth = oss2.Auth(self.__acc_key_id, self.__acc_key_secret)
-        bucket = oss2.Bucket(auth, self.__endpoint, self.__bucket_name)
-        bucket.put_object_from_file(key, filename)
-
-    def push_oss_from_stream(self, key, data):
-        """
-        流式上传oss
-
-        :param str key: 上传到OSS的文件名
-        :param data: 待上传的内容。
-        :type data: bytes,str或file-like object
-        """
-        auth = oss2.Auth(self.__acc_key_id, self.__acc_key_secret)
-        bucket = oss2.Bucket(auth, self.__endpoint, self.__bucket_name)
-        bucket.put_object(key, data)

+ 0 - 55
utils/es_query.py

@@ -1,55 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on 2024-02-02
----------
-@summary: es
----------
-@author: Lzz
-"""
-from elasticsearch import Elasticsearch
-from utils.title_participle import get_should
-
-
-# es:
-#   host: 172.17.4.184
-#   usename: "jybid"
-#   pwd: "Top2023_JEB01i@31"
-#   port: !!int 19905
-#   db: biddingall # es库别名
-
-
-def es_client():
-    cfg = {"host": "172.17.4.184",
-           "port": 19905,
-           "usename": "jybid",
-           "pwd": "Top2023_JEB01i@31"}
-    return Elasticsearch([{"host": cfg['host'], "port": cfg['port']}],http_auth=(cfg['usename'], cfg['pwd']))
-
-
-def es_search(title: str, publish_time: int):
-    """
-    查询es
-
-    :param title: 标题
-    :param publish_time: 发布时间
-    :return:
-    """
-    client = es_client()
-    stime = publish_time - 432000  # 往前推5天
-    etime = publish_time + 432000
-
-    time_limit = {"range": {"publishtime": {"from": stime, "to": etime}}}
-    should_list = get_should(title)   # 对标题进行分词组合query语句
-    # 通过发布标题和发布时间范围查询
-    query = {
-        "query": {
-            "bool": {
-                "must": [time_limit],
-                "should": should_list,
-                "minimum_should_match": "10<80%",
-            }
-        }
-    }
-    result = client.search(index="biddingall", body=query, request_timeout=100)
-    total = int(result['hits']['total']['value'])
-    return total

+ 0 - 50
utils/title_participle.py

@@ -1,50 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Created on 2023-10-10 
----------
-@summary: 标题分词,组合es查询语句
----------
-@author: Lzz
-"""
-from requests.auth import HTTPBasicAuth
-import requests
-import json
-
-
-def get_should(title):
-
-    # url = "http://192.168.3.149:9201/_analyze"  # 测试
-    url = "http://172.17.4.184:19905/_analyze"  # 线上
-    username = "jybid"
-    password = "Top2023_JEB01i@31"
-
-    headers = {"Content-Type": "application/json"}
-    auth = HTTPBasicAuth(username, password)
-    data = {
-        "analyzer": "ik_smart",
-        "text": title
-    }
-
-    res = requests.post(url, headers=headers, auth=auth, json=data, timeout=10)
-
-    try:
-        res_text = json.loads(res.text).get('tokens') or [{"token":title}]
-    except:
-        res_text = [{"token":title}]
-
-    should_list = []
-    for key in res_text:
-        single_dict = {
-            "multi_match": {
-                "query": f"{key.get('token')}",
-                "type": "phrase",
-                "fields": [
-                    "title"
-                ]
-            }
-        }
-        should_list.append(single_dict)
-
-    return should_list
-
-