# -*- coding: utf-8 -*-
import json
import re
import threading
import time
import uuid

import fitz
import redis
import requests
from bs4 import BeautifulSoup
from obs import ObsClient
from retry import retry
from elasticsearch import Elasticsearch
from base import BaseCore

baseCore = BaseCore.BaseCore()
log = baseCore.getLogger()
baseCore = BaseCore.BaseCore()

cnx_ = baseCore.cnx_
cursor_ = cnx_.cursor()

lock = threading.Lock()
pathType_ = 'QYResearchReport/'
taskType = '企业研报/东方财富网'

pool = redis.ConnectionPool(host="114.115.236.206", port=6379, password='clbzzsn', db=6)

class EsMethod(object):

    def __init__(self):
        # 创建Elasticsearch对象，并提供账号信息
        self.es = Elasticsearch(['http://114.116.19.92:9700'],  http_auth=('elastic', 'zzsn9988'),timeout=300 )
        self.index_name='policy'

    '''
    删除
    '''
    def delete(self,index_name,id):
        result = self.es.delete(index=index_name
                                ,doc_type="_doc"
                                ,id=id)
        log.info('删除结果 %s' % result)

if __name__ == "__main__":
    esMethod = EsMethod()
    redis_conn = redis.Redis(connection_pool=pool)
    while True:
        # 从redis中读取数据，去附件表中根据title查询，更新查到的附件id
        item = redis_conn.lpop('YanBao:up')
        if item:
            log.info(item)
            id = item.decode()
            try:
                esMethod.delete(esMethod.index_name,id)
            except:
                continue
        else:
            log.info('已删除完毕')
            break

