# -*- coding: utf-8 -*-

import re
import time

import pandas as pd

# def writeaa():
#     detailList=[]
#     aa={
#         'id':3,
#         'name':'qqqwe'
#     }
#     detailList.append(aa)
#     writerToExcel(detailList)
# 将数据追加到excel
# def writerToExcel(detailList):
#     # filename='baidu搜索.xlsx'
#     # 读取已存在的xlsx文件
#     existing_data = pd.read_excel(filename,engine='openpyxl')
#     # 创建新的数据
#     new_data = pd.DataFrame(data=detailList)
#     # 将新数据添加到现有数据的末尾
#     combined_data = existing_data.append(new_data, ignore_index=True)
#     # 将结果写入到xlsx文件
#     combined_data.to_excel(filename, index=False)
#
# from openpyxl import Workbook
#
# if __name__ == '__main__':
#     filename='test1.xlsx'
#     # # 创建一个工作簿
#     workbook = Workbook(filename)
#     workbook.save(filename)
#     writeaa()

# gpdm = '01109.HK'
# if 'HK' in str(gpdm):
#     tmp_g = str(gpdm).split('.')[0]
#     if len(tmp_g) == 5:
#         gpdm = str(gpdm)[1:]
#         print(gpdm)
#     else:
#         pass
import redis
from bs4 import BeautifulSoup


def check_url():
    r = redis.Redis(host="114.115.236.206", port=6379, password='clbzzsn',db=6)
    res = r.exists('WeiXinGZH:infoSourceCode','IN-20220418-0001')
    print(res)
    if res == 1:
        print('True')
    else:
        print('False')
# check_url()


def test(dic_user_count):
    dic_user_count["A"] += 1
    # print(dic_user.items())
    for key,value in dic_user_count.items():
        print(key,value)
    return dic_user_count

def test1():
    dic_user_count = {}
    for i in range(3):
        dic_user_count = test(dic_user_count)
        print(dic_user_count)

def rm_style_attr(soup):
    # 查找所有含有style属性的标签
    style_tags = soup.find_all(style=True)
    # 遍历每个style标签
    for style_tag in style_tags:
        try:
            # 使用正则表达式替换
            styleattr = style_tag['style']
            styleattr = re.sub(r'visibility:(?s).{1,}?;', '', styleattr)
            styleattr = re.sub(r'font-family:(?s).{1,}?;', '', styleattr)
            styleattr = re.sub(r'color:(?s).{1,}?;', '', styleattr)
            styleattr = re.sub(r'font-size:(?s).{1,}?;', '', styleattr)
            style_tag['style'] = styleattr
        except:
            continue

    first_div = soup.select('div[id="js_content"]')

    if first_div:
        first_div = first_div[0]  # 获取第一个匹配的元素
        first_div['style'] = 'width: 814px ; margin: 0 auto;'  # 设置style属性
    # # 设置style属性
    # first_div['style'] = 'width: 814px ; margin: 0 auto;'
    # print(first_div)
    return soup
def aaa(dic_user_count):
    for i in range(3):
        if "A" in dic_user_count:
            dic_user_count["A"] += 1
        else:
            dic_user_count["A"] = 1

if __name__ == "__main__":
    # html = """<div class="rich_media_content js_underline_content autoTypeSetting24psection" id="js_content" style="width: 814px ; margin: 0 auto;"><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;">3月31日，中国十七冶建安分公司承建的黄石EOD项目大泉路生态廊道工程马鞍山路高架桥顺利通车。<br/></span></section><section style="white-space: normal;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;text-indent: 0em;"><img class="rich_pages wxw-img" data-backh="312" data-backw="578" data-imgfileid="100024978" data-ratio="0.539568345323741" data-src="https://mmbiz.qpic.cn/mmbiz_png/ibEX3YMicPu80BnkeVDWh45k2S5saQQqDfvKJfBiblZO6OjbyWrYSJ3c2fib2eQReXQSLMONFicRD0fT2OdFY4da0og/640?wx_fmt=png&amp;from=appmsg" data-type="png" data-w="695" style="border: none;width: 100%;height: auto;" title=""/></section><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;">马鞍山路高架桥全长315米，设计速度为60km/h，采用双向四车道。该桥横跨马鞍山路，建成后将缓解马鞍山路和大泉路交叉口的交通压力，对减轻市民们的出行焦虑有着重要意义，同时将进一步加强大冶、阳新与黄石城区的联系，为黄石更好融入“武鄂黄黄”都市圈奠定基础。</span></section><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;">为全力推动马鞍山路高架桥建成，项目管理团队锚定节点目标不动摇，倒排工期，通过精心组织，优化施工方案，主动出击，联合行政主管部门多次召开推进会，克服施工过程中的管线迁改难题，为马鞍山路高架桥顺利通车提供坚实组织保障。</span></section><section style="white-space: normal;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;text-indent: 0em;"><img class="rich_pages wxw-img" data-backh="374" data-backw="578" data-imgfileid="100024979" data-ratio="0.6474820143884892" data-src="https://mmbiz.qpic.cn/mmbiz_png/ibEX3YMicPu80BnkeVDWh45k2S5saQQqDfZBWgkUaG20wMwKDxZ4SjjFwZg0bvicuAcLPUia6ECktibM9KPj5NIrmicg/640?wx_fmt=png&amp;from=appmsg" data-type="png" data-w="695" style="border: none;width: 100%;height: auto;" title=""/></section><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;">项目部将牢牢把握“十七冶发展要义”，深入践行“24小时工作法”，全力打造精品工程、安全工程、民生工程,为黄石打造武汉都市圈贡献十七冶力量。</span></section><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;"></span></section><section style="white-space: normal;text-indent: 2em;margin-top: 16px;margin-bottom: 16px;line-height: 1.75em;"><span style="outline: 0px;color: rgb(51, 51, 51);letter-spacing: 0.544px;text-indent: 2em;"></span></section><section style="margin-top: 16px;margin-bottom: 16px;white-space: normal;text-indent: 2em;line-height: 1.75em;"><section data-id="103115" data-role="splitline" data-tools="135编辑器" style="outline: 0px;font-variant-ligatures: normal;letter-spacing: 0.544px;orphans: 2;widows: 2;background-color: rgb(255, 255, 255);color: rgb(34, 34, 34);font-size: 16px;font-family: 微软雅黑;text-indent: 32px;overflow-wrap: break-word !important;"><section style="margin: 16px auto;outline: 0px;text-align: center;text-indent: 2em;line-height: 1.75em;overflow-wrap: break-word !important;"><section style="outline: 0px;display: flex;justify-content: center;align-items: center;overflow-wrap: break-word !important;"><section style="margin-left: 2px;outline: 0px;height: 6px;width: 6px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(35, 35, 35);overflow: hidden;overflow-wrap: break-word !important;"><br data-filtered="filtered" style="outline: 0px;overflow-wrap: break-word !important;"/></section><section style="margin-left: 2px;outline: 0px;height: 6px;width: 6px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(35, 35, 35);overflow: hidden;overflow-wrap: break-word !important;"> <br data-filtered="filtered" style="outline: 0px;overflow-wrap: break-word !important;"/></section><section style="margin-left: 2px;outline: 0px;height: 6px;width: 6px;border-radius: 100%;border-width: 1px;border-style: solid;border-color: rgb(35, 35, 35);overflow: hidden;overflow-wrap: break-word !important;"><br style="outline: 0px;overflow-wrap: break-word !important;"/></section><section style="margin-left: 4px;outline: 0px;height: 1px;background-color: rgb(35, 35, 35);flex: 1 1 0%;overflow: hidden;overflow-wrap: break-word !important;"><br data-filtered="filtered" style="outline: 0px;overflow-wrap: break-word !important;"/></section></section></section></section><section style="margin: 16px 8px;outline: 0px;font-variant-ligatures: normal;letter-spacing: 0.544px;orphans: 2;text-indent: 0em;widows: 2;background-color: rgb(255, 255, 255);color: rgb(34, 34, 34);font-family: 微软雅黑;text-align: left;line-height: 1.75em;overflow-wrap: break-word !important;"><span style="outline: 0px;font-size: 14px;color: rgb(136, 136, 136);overflow-wrap: break-word !important;">来源：中国企业网</span><img class="rich_pages wxw-img __bg_gif" data-backh="192" data-backw="320" data-fileid="100002618" data-galleryid="" data-imgfileid="100024527" data-ratio="0.6" data-src="https://mmbiz.qpic.cn/mmbiz_gif/ibEX3YMicPu82TZf4RScpazSD7OuViaH4cEUx9rCibPavn2cJXiagJrmVuVTpOJgibBV8368H2RYxxYp3Fhn1a7SU20Q/640?wx_fmt=gif" data-type="gif" data-w="1000" style="letter-spacing: 0.544px;text-indent: 0em;outline: 0px;color: rgb(136, 136, 136);font-size: 15px;text-align: center;width: 562px;visibility: visible !important;height: auto !important;" width="320px"/></section></section><p style="display: none;"><mp-style-type data-value="3"></mp-style-type></p></div>"""
    # soup = BeautifulSoup(html, 'html.parser')
    # soup = rm_style_attr(soup)
    # print(soup)
    dic_user_count = {}
    aaa(dic_user_count)

    if dic_user_count:
        for key, value in dic_user_count.items():
            print(f"====账号{key}，采集公众号个数{value}")
