
"""sorted(title_extracted_by_h,key = lambda x:similarity(x,title_extracted_by_title),reverse=True)

etree.strip_elements(elements,tag) #tag是要删除的标签名
for child in children(element):  #children(element)是一个函数，获取当前HTML元素的所有子元素
    child.tag.lower() #获取标签名称
    etree.strip_tags(child,'span') #删除标签对

element.getparent() #获取给定元素的父元素


"""
# from io import StringIO
#
# import pandas as pd
# data = '"1234","456\r7","897"'
# print(data)
# aa = pd.read_csv(StringIO(data),escapechar='\r')
# print(aa)

# import pandas as pd
#
# # 读取txt文件
# data = pd.read_csv('D:\\美国证券交易委员会\\2022q4\\sub.txt', delimiter='\t')  # 根据实际情况选择正确的分隔符
#
# # 将数据保存为csv文件
# data.to_csv('D:\\美国证券交易委员会\\2022q4\\sub.csv', index=False)  # index=False表示不保存行索引
"""验证码识别测试"""
# import ddddocr
#
# ocr = ddddocr.DdddOcr()
#
# with open("D:\\kkwork\\captchaNew (3).jfif", 'rb') as f:
#     image = f.read()
#
# res = ocr.classification(image)
# print(res)
"""测试中国执行信息公开网  模拟浏览器"""

import ddddocr
from PIL import Image
import re

import requests, time, random, json, pymysql, redis

import urllib3
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from obs import ObsClient
from kafka import KafkaProducer

from base.BaseCore import BaseCore
# baseCore = BaseCore()
# log = baseCore.getLogger()
# cnx_ = baseCore.cnx
# cursor_ = baseCore.cursor
#
# def use_ocr(img):
#     ocr = ddddocr.DdddOcr()
#     with open(img, 'rb') as f:
#         image = f.read()
#     res = ocr.classification(image)
#     print(res)
#     return res
#
# if __name__=="__main__":
#     requests.DEFAULT_RETRIES = 5
#     time_start = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
#     log.info(f'开始时间为：{time_start}')
#
#     requests.adapters.DEFAULT_RETRIES = 3
#     headers = {
#         'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
#     }
#
#     opt = webdriver.ChromeOptions()
#     opt.add_argument(
#         'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36')
#
#     opt.add_argument("--ignore-certificate-errors")
#     opt.add_argument("--ignore-ssl-errors")
#     opt.add_experimental_option("excludeSwitches", ["enable-automation"])
#     opt.add_experimental_option('excludeSwitches', ['enable-logging'])
#     opt.add_experimental_option('useAutomationExtension', False)
#     opt.binary_location = r'D:/Google/Chrome/Application/chrome.exe'
#     chromedriver = r'D:/cmd100/chromedriver.exe'
#     browser = webdriver.Chrome(chrome_options=opt, executable_path=chromedriver)
#     url = "http://zxgk.court.gov.cn/shixin/"
#     browser.get(url)
#     # 可改动
#     time.sleep(20)
#     page_source = browser.page_source
#     soup = BeautifulSoup(page_source, 'html.parser')
#     img_url = soup.select('img[id="captchaImg"]')[0]['src']
#
#     browser.find_element(By.ID, 'pName').send_keys('北京远翰国际教育咨询有限责任公司')
#
#
#     browser.find_element(By.ID, 'yzm').send_keys(yzm)
#     browser.find_element(By.ID, 'searchForm').click()
#     wait = WebDriverWait(browser, 30)
#     wait.until(EC.presence_of_element_located((By.TAG_NAME, "body")))

# screen_img_path = "D:/screen/xxx.png"
# out_img_path = "D:/out/xxx.png"
# ele = driver.find_element(By.ID, 'XXXX')
#
# code = use_ocr(out_img_path)
# 验证码输入框元素.send_keys(code)
# import requests
# headers = {
#     # 'Accept': '*/*',
#     # 'Accept-Encoding': 'gzip, deflate, br',
#     # 'Accept-Language': 'zh-CN,zh-TW;q=0.9,zh;q=0.8',
#     # 'Cache-Control': 'no-cache',
#     # 'Connection': 'keep-alive',
#     # 'Host': 'search-api-web.eastmoney.com',
#     # 'Pragma': 'no-cache',
#     # 'Sec-Fetch-Dest': 'script',
#     # 'Sec-Fetch-Mode': 'no-cors',
#     # 'Sec-Fetch-Site': 'same-site',
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
#     # 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
#     # 'sec-ch-ua-mobile': '?0',
#     # 'sec-ch-ua-platform': '"Windows"'
# }
# url = "https://www-private-oss.mob.com/academy_reports/2023/03/31/Mob%E7%A0%94%E7%A9%B6%E9%99%A2%E3%80%8A2023%E5%B9%B4%E4%B8%AD%E5%9B%BD%E6%96%87%E6%97%85%E4%BA%A7%E4%B8%9A%E5%8F%91%E5%B1%95%E8%B6%8B%E5%8A%BF%E6%8A%A5%E5%91%8A%E3%80%8B.pdf?response-content-disposition=attachment&OSSAccessKeyId=LTAI5t5mdPuMS9gNj93RPowJ&Expires=1703839064&Signature=X1mpakYGVaBffNokvhvW917UH%2Fk%3D"
#
#
# # res = requests.get(url).text[1:-1]
# res = requests.get(url=url, headers=headers)
# with open('./a.pdf','wb') as f:
#     f.write(res.content)


import datetime
import json

import requests
import pymongo
from base import BaseCore
baseCore = BaseCore.BaseCore()
log = baseCore.getLogger()


db_storage = pymongo.MongoClient('mongodb://114.115.221.202:27017/', username='admin', password='ZZsn@9988').中科软[
    '数据源_0504']

datas = db_storage.find({'postCode':'2'}).limit(1)
for data in datas:
    title = data['titleForeign']
    contentWithTag = data['richTextForeign']
    summary = data['contentForeign']
    dic_info = {
        'title':title,
        # 'summary':summary,
        'contentWithTag':contentWithTag
    }
    headers = {
        'Content-Type': 'application/json',
    }
    dic_info_ = json.dumps(dic_info)
    # print(dic_info_)
    # with open('./data.json','w') as f:
    #     f.write(dic_info_)
    # break
    # req = requests.post('http://192.168.1.236:5000/translate',data=dic_info_,headers=headers)
    req = requests.post('http://117.78.23.14:5000/translate',data=dic_info_,headers=headers)
    log.info(req.text)

# import re, datetime
#
#
# def paserTime(publishtime):
#     timeType = ['年前', '月前', '周前', '前天', '昨天', '天前', '今天', '小时前', '分钟前']
#     current_datetime = datetime.datetime.now()
#     publishtime = publishtime.strip()
#     print(publishtime)
#
#     try:
#         if '年前' in publishtime:
#             numbers = re.findall(r'\d+', publishtime)
#             day = int(numbers[0])
#             delta = datetime.timedelta(days=365 * day)
#             publishtime = current_datetime - delta
#         elif '月前' in publishtime:
#             numbers = re.findall(r'\d+', publishtime)
#             day = int(numbers[0])
#             delta = datetime.timedelta(months=day)
#             publishtime = current_datetime - delta
#         elif '周前' in publishtime:
#             numbers = re.findall(r'\d+', publishtime)
#             day = int(numbers[0])
#             delta = datetime.timedelta(weeks=day)
#             publishtime = current_datetime - delta
#         elif '天前' in publishtime:
#             numbers = re.findall(r'\d+', publishtime)
#             day = int(numbers[0])
#             delta = datetime.timedelta(days=day)
#             publishtime = current_datetime - delta
#         elif '前天' in publishtime:
#             delta = datetime.timedelta(days=2)
#             publishtime = current_datetime - delta
#         elif '昨天' in publishtime:
#             current_datetime = datetime.datetime.now()
#             delta = datetime.timedelta(days=1)
#             publishtime = current_datetime - delta
#         elif '今天' in publishtime or '小时前' in publishtime or '分钟前' in publishtime:
#             if '小时' in publishtime:
#                 hour = publishtime.split("小时")[0]
#             else:
#                 hour = 0
#             if hour != 0:
#                 min = publishtime.split("小时")[1].split("分钟")[0]
#             else:
#                 min = publishtime.split("分钟")[0]
#
#             delta = datetime.timedelta(hours=int(hour), minutes=int(min))
#             publishtime = current_datetime - delta
#         elif '年' in publishtime and '月' in publishtime:
#             time_format = '%Y年%m月%d日'
#             publishtime = datetime.datetime.strptime(publishtime, time_format)
#         elif '月' in publishtime and '日' in publishtime:
#             current_year = current_datetime.year
#             time_format = '%Y年%m月%d日'
#             publishtime = str(current_year) + '年' + publishtime
#             publishtime = datetime.datetime.strptime(publishtime, time_format)
#     except Exception as e:
#         print('时间解析异常！！')
#     return publishtime
#
# if __name__ == "__main__":
#     publishtime_ = '1小时17分钟前'
#     publish_time = paserTime(publishtime_).strftime("%Y-%m-%d")
#     print(publish_time)