Exemplo n.º 1
0
    def report(self, is_test=False):
        def _check_need(time):
            _time = str(int(time.split(":")[0]))
            if _time == self.time_to_check:
                return True
            else:
                return False

        def _update_check_time():
            i = REPORT_TIME.index(self.time_to_check)
            if i >= len(REPORT_TIME) - 1:
                new_time = REPORT_TIME[0]
            else:
                new_time = REPORT_TIME[i + 1]
            self.time_to_check = new_time

            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("system_var_coll")
            coll.update({"key": "report_check_time"}, {"$set": {"value": new_time}})

        _date = datetime.now().strftime("%Y-%m-%d")
        _time = datetime.now().strftime("%H:%M:%S")
        if _check_need(_time):
            _update_check_time()

            # 执行
            info = self.get_info(is_test)

            send_message(subject="定时任务执行报告", content=info, attachments=[])
            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("report_info_coll")
            coll.insert(dict(date=_date, time=_time, datetime=datetime.now(), info=info))

        else:
            pass
Exemplo n.º 2
0
        def _update_check_time():
            i = REPORT_TIME.index(self.time_to_check)
            if i >= len(REPORT_TIME) - 1:
                new_time = REPORT_TIME[0]
            else:
                new_time = REPORT_TIME[i + 1]
            self.time_to_check = new_time

            conn = MongoConn(config=MONGODB_CONFIG)
            coll = conn.get_coll("system_var_coll")
            coll.update({"key": "report_check_time"}, {"$set": {"value": new_time}})
Exemplo n.º 3
0
def _save_query(question, jieba_segment, fool_segment, jieba_keywords,
                fool_keywords, fool_search_result, jieba_search_result):
    '''
    将查询的内容以及查询的结果存入数据库做结果的分析
    '''
    database = 'Unicom'
    collection = 'query_test'

    document = {
        'question': question,
        'jiebaSegment': jieba_segment,
        'foolSegment': fool_segment,
        'jiebaKeywords': jieba_keywords,
        'foolKeywords': fool_keywords,
        'foolSearchResult': fool_search_result,
        'jiebaSearchResult': jieba_search_result,
        'reason': '',
    }

    try:
        with MongoConn(database, collection) as conn:
            conn.insert_one(document)
    except Exception as err:
        print(err)
        return False, err

    return True
Exemplo n.º 4
0
def remove(words):
    ret = []
    with MongoConn('Unicom', 'propernouns') as proper:
        for word in words:
            if proper.count_documents({'properNouns': word}) > 0:
                ret.append(word)
    return ret
Exemplo n.º 5
0
    def __init__(self, func=None, *args, **kwargs):
        # hour
        self.time_to_check = None
        self.conn = MongoConn(config=MONGODB_CONFIG)
        self._init_check_time_from_db()

        self.func = func
Exemplo n.º 6
0
    def _init_check_time_from_db(self):

        conn = MongoConn(config=MONGODB_CONFIG)
        coll = conn.get_coll("system_var_coll")
        doc = coll.find_one(filter=dict(key="report_check_time"))
        if not doc:
            # 寻找最近将来时间点 默认有序
            _now_hour = datetime.now().hour
            for h in REPORT_TIME:
                if _now_hour - int(h) > 0:
                    continue
                else:
                    self.time_to_check = h
                    break
            if not self.time_to_check:
                self.time_to_check = REPORT_TIME[0]
            coll.insert(dict(key="report_check_time", value=self.time_to_check))
        else:
            self.time_to_check = doc['value']
Exemplo n.º 7
0
def createReset():
    """
        A factory to create an instance of Reset
    """
    json_file = resource_string(__name__, RESET_SETTINGS_FILE)
    settings = json.loads(json_file)
    mongodb_settings = settings.get('mongodb')
    mongo_conn = MongoConn(mongodb_settings.get('host'),
                            mongodb_settings.get('port'))
    rabbitmq_conn = RabbitMQConn()

    return Reset(mongo_conn, rabbitmq_conn)
Exemplo n.º 8
0
    def __init__(self):
        with MongoConn('Unicom', 'propernouns') as conn, \
                MongoConn('Unicom', 'synonym') as synonym,  \
                MongoConn('Unicom', 'stopwords') as stop:
            count = 0
            for doc in conn.find():
                jieba.add_word(doc['properNouns'], doc['weight'])
                fool.add_word(doc['properNouns'], doc['weight'])
                count += 1

            for doc in synonym.find():
                jieba.add_word(doc['standard'], 10)
                fool.add_word(doc['standard'], 10)
                count += 1

            print(f'{count} keyword load success!')

            count = 0

            for doc in stop.find():
                self.add_stop_word(doc['stopword'])
                count += 1

            print(f'{count} stopword load success!')
Exemplo n.º 9
0
def format(data):
    '''
    将es的查询结果整理成(电话,allname)的形式返回结果
    '''
    with MongoConn('Unicom', 'priority') as blacklist:
        return [
            {
                # 电话解码
                'phoneNum':
                binascii.a2b_hex(result['_source']['phoneNum']).decode(),
                'allName':
                result['_source']['allName'].replace(',', ' ').strip(),
            } for result in sorted(data['hits']['hits'],
                                   key=lambda d: d['_source']['frequency'])
            # 不显示黑名单中的电话信息
            if blacklist.count_documents(
                {'unitId': result['_source']['unitId']}) == 0
        ]
Exemplo n.º 10
0
def replace(words):
    if isinstance(words, str):
        if ',' in words:
            words = words.split(',')
        else:
            words = words.split()

    indexes = []
    print('before replace:', words)
    with MongoConn('Unicom', 'synonym') as synonym:
        for index, word in enumerate(words):
            regex = f'(.*/{word}/.*)|(/{word}$)|(^{word}/.*)|(^{word}$)'
            if synonym.count_documents({'synonyms': {'$regex': regex}}):
                standard = synonym.find_one({'synonyms': {
                    '$regex': regex
                }})['standard']
                words[index] = standard
                indexes.append(index)

    print('after replace:', words)
    return words, indexes
Exemplo n.º 11
0
 def restart(self):
     self._init_check_time_from_db()
     self.conn = MongoConn(config=MONGODB_CONFIG)
     self.prepare()
Exemplo n.º 12
0
 def restart(self):
     print("Monitor is Restarting")
     self._init_check_time_from_db()
     self.conn = MongoConn(config=MONGODB_CONFIG)
     self.prepare()
Exemplo n.º 13
0
 def __init__(self):
     # hour
     self.time_to_check = None
     self.conn = MongoConn(config=MONGODB_CONFIG)
     self._init_check_time_from_db()