コード例 #1
0
ファイル: jilin.py プロジェクト: wagaman/jgcf
def jilin_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '吉林保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('吉林保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'(吉银?保监[罚处].*?\d{4}.*?\d+.*?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'2015年2月11日,吉林保监局向新华人寿保险股份有限公司长春中心支公司下发监管函|'
                r'2015年,新华人寿保险股份有限公司吉林中心支公司存在代抄录风险提示语句的违法行为。|'
                r'.*?对.*?现场检查|.*?存在.*?行为|'
                r'2008年7-8月,你公司所属南关营销服务部二部在客户答谢会上给予投保人蚕丝被、夏凉被等现场签单奖励|'
                r'你公司自2007年8月至检查日止从未组织过业务员参加代理人资格考试,截止检查日公司有营销员55人|'
                r'你在任阳光财险长春市二道区支公司负责人期间|'
                r'2007年6月,你公司承保车号为吉G41805、吉G42589、吉G42518等三辆车的交强险业务|'
                r'2007年6月13日,你公司所属洮南营销服务部承保了车号为吉G31290车的交强险业务|'
                r'你公司于2007年6月25日承保车牌号码为吉A7A263捷达轿车的商业车险业务|'
                r'2006年9月至2007年2月间,你公司虚列营业费用226,310.67元|'
                r'2006年11月至2007年2月间,你公司虚列营业费用257,484.49元)')
            litigant = litigant_compiler.search(content_text).group(1).replace(
                '中国保监会行政处罚决定书', '').strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'2015年2月11日,吉林保监局向新华人寿保险股份有限公司长春中心支公司下发监管函|'
                r'2015年,新华人寿保险股份有限公司吉林中心支公司存在代抄录风险提示语句的违法行为。|'
                r'.*?对.*?现场检查|.*?存在.*?行为|'
                r'2008年7-8月,你公司所属南关营销服务部二部在客户答谢会上给予投保人蚕丝被、夏凉被等现场签单奖励|'
                r'你公司自2007年8月至检查日止从未组织过业务员参加代理人资格考试,截止检查日公司有营销员55人|'
                r'你在任阳光财险长春市二道区支公司负责人期间|'
                r'2007年6月,你公司承保车号为吉G41805、吉G42589、吉G42518等三辆车的交强险业务|'
                r'2007年6月13日,你公司所属洮南营销服务部承保了车号为吉G31290车的交强险业务|'
                r'你公司于2007年6月25日承保车牌号码为吉A7A263捷达轿车的商业车险业务|'
                r'2006年9月至2007年2月间,你公司虚列营业费用226,310.67元|'
                r'2006年11月至2007年2月间,你公司虚列营业费用257,484.49元|'
                r'你公司于\n2007年5月30日\n承保车牌号吉 BA6292 捷达车的商业车险业务|'
                r'2007年4月29日\n,你公司承保吉AH5950号家庭自用车的交强险业务|'
                r'2007年6月1日,人保财险长春市南关支公司委托吉林省宏大保险代理公司|'
                r'你在担任新华人寿保险股份有限公司延边中心支公司副总经理(主持工作)期间|'
                r'你公司未经我局批准,擅自在安图县二道镇、松江镇、两江镇设立营业网点|'
                r'2007年4月9日,你公司朝阳营销服务部(现安华农业保险股份有限公司长春市朝阳支公司)承保吉A19714号车的商业车险业务|'
                r'2005年7月至2006年6月,你公司共10次以现金方式向保险兼业代理机构长春通立汽车服务有限\n?公司支付代理手续费|'
                r'你公司于\n2006年4月21日\n承保了车牌号为吉A27130的车险业务|'
                r'2005年12月末,安华农业保险股份有限公司四平中心支公司委托时任安华农业'
                r'保险股份有限公司辽源营销服务部经理王全勇在东丰县筹建东丰营销服务部|'
                r'2005年12月末,你受安华农业保险股份有限公司四平中心支公司委托在东丰县筹建东丰营销服务部)')
            litigant = litigant_compiler.search(content_text).group(1).replace(
                '中国保监会行政处罚决定书', '').strip()

        truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:)' \
                         r'([\s\S]*?)' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等(证据|书证)(在案)?(证明|为证)(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'你公司未及时履行赔偿保险金义务、制作“鸳鸯保单”、异地开展车险业务|' \
                         r'人民广场支公司采用账外经营的方式,办理商业车险业务,导致公司业务财务数据不真实|' \
                         r'你部以上行为违反了《保险法》第一百二十二条的规定|' \
                         r'人保财险德惠支公司上述行为违反了《保险法》第二十四条的规定。|' \
                         r'你公司违规减收保费,给予被保险人保费优惠的行为|' \
                         r'平安财险长春市经济技术开发区支公司给予被保险人额外利益的行为|' \
                         r'上述\n行为违反了《保险法》第一百二十二条的规定。|' \
                         r'人保财险磐石支公司采用制作“鸳鸯单”,保费收入不入账的行为|' \
                         r'人保财险长春市高新支公司扩展责任条款未向保险监管部门报备的行为|' \
                         r'人保财险通化市分公司第一营业部异地承保车险业务,且未与有业务往来的代理公司签订代理合同的行为|' \
                         r'你公司通过改变车辆使用性质变相降低费率的行为|' \
                         r'绿园支公司虚列应收保费的行为违反了《保险法》第一百二十二条的规定|' \
                         r'你公司虚列应收保费的行为违反了《保险法》第一百二十二条的规定|' \
                         r'你公    司向未取得代理资格的代理人支付商业车险和交强险手续费的行为|' \
                         r'安邦财险吉林分公司营业部向未取得保险代理资格的代理人支付商业车险和交强险手续费的行为|' \
                         r'上述事实行为违反了《中华人民共和国保险法\n?》第八十条之规定|' \
                         r'你公司未经保险监管部门批准擅自设立分支机构开办保险业务的行为违反了《保险法》第八十条的规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r'上述委托未取得《保险代理从业人员资格证书》人员开展保险业务的行为,违反了《保险营销员管理规定》第\n四十三条的规定|' \
                                        r'你公司所属分支机构未及时履行赔偿保险金义务的行为违反了《保险法》第二十四条的规定|' \
                                        r'你公司采用系统外出单方式承保车险业务的行为|' \
                                        r'你公司采用制作“鸳鸯”单的方式给予被保险人优惠的行为)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?(行为|问题).*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在(法定|规定)期限内(未)?(提出|提交)(了)?(听证要求|陈述申辩|陈述申辩及听证要求|陈述、申辩材料)|' \
                               r'[^,。,;\n]*?申辩称)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|经复核|鉴于你公司|' \
                               r'依据现场检查及听证情况|' \
                               r'经我局复核|我局经过复核认为|当事人并未对我局认定的违法事实、处罚理由及依据提出异议|' \
                               r'复核认为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                          r'有关依法从轻或减轻行政处罚的规定。|在规定期限内,你公司未行使陈述权和申辩权。|' \
                                                          r'应对该支公司的违法违规问题承担责任。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依\n?据|根据)[^。;]*?第[^。;]*?条[^。;]*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?\n?作出|拟对你|拟给予|现对你处以)|' \
                                       r'我局经复核认为|我局决定[^。;\n]*?作出(如下|以下)(行政)?处罚:|综上,决定作出如下处罚:|' \
                                       r'我局决定[^。;\n]*?|依据该条规定,现给予)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请.*?接到本处罚决定书之日|如不服从本处罚决定|二〇〇八年九月十八日|请你公司及时向总公司汇报处罚结论|' \
                                       r'.*?应当在接到本处罚决定书之日)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第?.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'上述行为违反了《保险法》(2015年修正)(以下同)八十六条之规定',
            r'我局认为,上述行为致使公司个险期缴保费数据在较短时间内出现波动,影响了公司财务、业务数据的真实性,'
            r'其行为违反了《中华人民共和国保险法》第八十六条的规定。\n曹磊时任该公司主要负责人,应对上述违法行为负直接责任',
            r'人民广场支公司采用账外经营的方式,办理商业车险业务,导致公司业务财务数据不真实,'
            r'违反了《保险法》第一百二十二条的规定,你作为该支公司经理对以上违法行为负有直接领导责任。根据《保险法》第一百五十条的规定',
            r'我局认为,上述行为违反了《保险法》第一百一十六条第十三项及《关于加强和完善保险营销员管理工作有关事项的通知》'
            r'(保监发[2009]98号)第三条、第六条的规定。\n当事人翟廷杰应对上述违规招聘营销员的行为负直接责任'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            '.(\n?依\n?据|\n?根据|\n?鉴于|\n?我局决定|\n?翟廷杰在申辩材料中称|\n?中国人寿松原分公司在申辩材料中称)',
            re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '吉林银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('吉林保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('吉林保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('吉林保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #2
0
ファイル: qingdao.py プロジェクト: wagaman/jgcf
def qingdao_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '青岛保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('青岛保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'(青岛保监罚.\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有.*?关规定|抽查|经抽查|'
                r'.*?(现场检查|举报检查|业务核查|举报调查|检查中发现|青岛保监局关于整顿和规范保险市场的具体要求))')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有.*?关规定|抽查|经抽查|'
                r'.*?(现场检查|举报检查|举报调查|业务核查|检查中发现|青岛保监局关于整顿和规范保险市场的具体要求))')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'((经查|经检查)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上|该).*?(事实|行为|事实)(,|,)?有.*?等(证据)?(材料)?(在案)?(证明|佐证)(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant.replace(r'*', r'\*') + \
                             r'([\s\S]*?)' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|事实行为)(,|,)?有.*?等(证据)?(在案)?(证明|佐证|作证)(,|,|。)(足以认定。)?|' \
                             r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                             r'上述违反了《中华人民共和国保险法》第一百二十二条的规定|' \
                             r'上述行为《中华人民共和国保险法》第一百二十二条的规定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'当事人在法定期限内未提出申辩意见|你公司在规定时间内提出陈述申辩并提出三条理由|' \
                               r'在规定期限内,你提出了陈述和申辩|你.*?在申辩书中提出|你公司提到的.*?陈述申辩材料)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'我局依法对陈述申辩意见进行了复核|' \
                               r'对你公司|' \
                               r'经复核|' \
                               r'我局在处罚裁量时已充分考虑此情节|' \
                               r'没有相关证据支持)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'予以采纳。|此申辩不被采纳。|我局不予采纳。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|我局拟对|我局决定对)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人如对本处罚决定不服|' \
                                       r'你公司应严格按照《关于保险公司缴纳罚款等有关问题的通知》)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'上述违反了《中华人民共和国保险法》第一百二十二条的规定', r'上述行为《中华人民共和国保险法》第一百二十二条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            '.(\n?(应当)?依据|\n?(应当)?根据|\n?鉴于|\n?我局决定|\n?按照)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '青岛银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('青岛保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('青岛保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('青岛保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #3
0
ファイル: liaoning.py プロジェクト: wagaman/jgcf
def liaoning_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '辽宁保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('辽宁保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(
            r'(辽保监[罚告].\d{4}.\d+号|辽保监[罚告]\d{4}.\d+.号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'个险部内勤经查|'
                r'.*?公司在|你公司上报的监管报表显示|'
                r'.*?(期间|经营过程中|业务经营中).*?存在.*?(行为|问题)|'
                r'我局调查组于.*?对.*?进行调查,发现|'
                r'你公司在2007年1-12月业务经营和管理中)')

            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'个险部内勤经查|'
                r'.*?公司在|你公司上报的监管报表显示|'
                r'.*?(期间|经营过程中|业务经营中).*?存在.*?(行为|问题)|'
                r'中国人民人寿保险股份有限公司本溪营销服务部在2009年业务经营过程中)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'((经查|经检查|检查发现|现场检查,发现|抽查|经抽查|你公司在2007年1-12月业务经营和管理中)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上)\n?.*?\n?(事实|行为|事实)(,|,)?\n?有[\s\S]*?等\n?证\n?据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'上述事实行为违反了|' \
                         r'依据)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上)\n?.*?\n?(事实|行为|事实)(,|,)?有.*?等\n?证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r'上述违法违规事实)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'当事人在法定期限内未提出陈述申辩意见,也未提出听证申请|' \
                               r'当事人.*?提出了陈述、申辩|你在申辩中称|' \
                               r'我局向.*?送达《行政处罚事先告知书》后.*?(申辩|听证))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对.*?(陈述申辩意见|听证意见)进行了.*?复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'案件现已审理终结。|' \
                               r'我局认为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|案件现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?(申辩(意见|理由)|请求)(不予|予以)采纳|因此.*?申辩.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   r'我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。|' \
                                   r'根据《中华人民共和国行政处罚法》第三十一条、第三十二条、《中国保险监督管理委员会行政处罚程序规定》第五条和第四十三条的规定,可在收到本告知书之日起10日内到辽宁保监局(地址:沈阳市沈河区北京街29号)进行陈述和申辩。逾期视为放弃陈述权和申辩权。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据|按照)[^。;]*?第?[^。;]*?条[^。;]*?(规定)?\n?.?(我局)?(决定|责令|给予)|' \
                                       r'我局(决定)?.*?作出(如下|以下)(行政)?处罚|综上,我局作出如下处罚|' \
                                       r'依\n?据[^。;]*?规定(,我局决定|对你公司|,决定给予)|' \
                                       r'依据上述法律法规,鉴于你公司对发现的问题较为重视,违规情节较轻,同时在事后采取了积极的补救措施,未造成严重的后果,决定给予|' \
                                       r'综上,我局作出如下处罚)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人应当在接到本处罚决定之日|' \
                                       r'当事人应当在接到处罚决定书之日|(当事人)?如对(本)?处罚决定不服|' \
                                       r'请当事人在接到本处罚决定书之日|你.*?应当在接到本处罚决定书之日|' \
                                       r'如你公司对我局认定的违法事实、处罚理由及依据有异议)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;,]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反([\s\S]*?)',
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;,]' + '(' + punishment_basis_str + ')' +
            '.(\n?依\n?据|\n?根据|\n?鉴于)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '辽宁银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('辽宁保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('辽宁保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('辽宁保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #4
0
ファイル: ningxia.py プロジェクト: wagaman/jgcf
def ningxia_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '宁夏保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('宁夏保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚信息' in title:
            litigant_compiler = re.compile(r'行政处罚信息.(.*?).$')
            litigant = litigant_compiler.search(title).group(1).strip()
            document_code_compiler = re.compile(r'(宁银保监筹?罚决字.\d{4}.\d+号)')
            if document_code_compiler.search(content_text.split('\n')[0]):
                document_code = document_code_compiler.search(
                    content_text.split('\n')[0]).group(1).strip()
            else:
                document_code = ''

            publish_date_text = content_text.split('\n')[0]
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1].replace(
                                              ' ', '')
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'
        else:
            document_code_compiler = re.compile(r'(\d{4}.\d*.?\d+号)')
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''

            litigant_compiler = re.compile(r'^([\s\S]*?)\n' +
                                           r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                                           r'你公司于2008年1月至6月,先后与.*?建立了委托代理关系)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

            publish_date_text = content_text
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1].replace(
                                              ' ', '')
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'

        truth_text_str = r'((经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:|经查明,|二、|三、|' \
                         r'长安保险销售有限公司存在.*?违规行为)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?[^。,\n]*?(上述|以上)[^。,\n]*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?[^。,\n]*?(上述|以上)[^。,\n]*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'(。|,|\n)[^。,]*?违反了.*?第.*?条.*?规定)'
        truth_compiler = re.compile(truth_text_str)
        truth_list = truth_compiler.findall(content_text)
        truth = '\n'.join([each_truth[0] for each_truth in truth_list])

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                     r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                     r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   r'我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局|宁夏保监局)?(决定|责令|给予|于.*?向.*?发出|对|拟对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|$|\n.*?应在接到本处罚决定书之日)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;\s]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反([^\n。;\s]*?)\n?([^\n。;\s]*?)'
            r'第([^\n。;\s]*?)条\n?.*?((的|之|等)(相关)?规定)?', r'违反了.*?第.*?条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'(。|\n|;|经查,)' + '(' + punishment_basis_str + ')' +
            '.(\n?依据|\n?根据|\n?鉴于|\n?上述违法事实|\n?对于你公司.*?违法违规行为)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[1].strip() for kk in punishment_basis_list])

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '宁夏银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('宁夏保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('宁夏保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('宁夏保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #5
0
ファイル: heilongjiang.py プロジェクト: wagaman/jgcf
def heilongjiang_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '黑龙江保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('黑龙江保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()
        document_code = re.search(
            r'((黑银?保监罚字?|黑银保监(筹)保罚字|佳银?保监罚字).\d{4}.\d+号)',
            title).group(1).strip()

        if re.search(r'((黑银?保监罚字?|黑银保监(筹)保罚字|佳银?保监罚字).\d{4}.\d+号)\n',
                     content_text):
            text_document_code = re.search(
                r'((黑银?保监罚字?|黑银保监(筹)保罚字|佳银?保监罚字).\d{4}.\d+号)\n',
                content_text).group(1)
            litigant_compiler = re.compile(
                text_document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n?([\s\S]*?)\n' +
                r'(依据.*?有关规定|.*?(黑龙江保监局)?(检查组)?.*?对?.*?(现场)?检查|'
                r'一、违法事实及证据|一、违法事实和证据|经查|你.*?于.*?违反.*?规定)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' +
                r'(依据.*?有关规定|.*?,(黑龙江保监局)?(检查组)?.*?对.*?(现场)?检查|一、违法事实及证据|一、违法事实和证据|经查|'
                r'.*?我局.*?对.*?进行(检查|调查)|阳光财产保险股份有限公司伊春中心支公司于2008年经营交强险业务过程中)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        litigant = litigant.replace('行政处罚决定书', '').strip()

        truth_text_str = r'((经查|二、|三、|(二)|(三)|黑龙江保监局经检查发现下列事实|检查发现下列事实|经检查发现下列事实|经检查发现|' \
                         r'(黑龙江保监局|我局).*?对.*?进行(现场)?检查,发现.*?存在.*?行为|黑龙江保监局经现场检查,发现如下事实|' \
                         r'黑龙江保监局.*?对.*?检查,发现.*?以下问题|' \
                         r'我局对阳光财险黑龙江省分公司和阳光财险哈尔滨营业部进行了现场检查)' \
                         r'([\s\S]*?))' \
                         r'((上述|该|以上)(违法|违法违规)?(事实|行为).*?(有)?.*?等证据(在案)?(证明|佐证)(在案)?(.*?足以认定)?|' \
                         r'上述第一项行为违反了《中华人民共和国保险法》(2009)第一百一十六条第(六)项的规定|' \
                         r'当事人邹基德,对虚列业务及管理费负有直接责任)'
        truth_compiler = re.compile(truth_text_str)
        truth_list = truth_compiler.findall(content_text)
        if len(truth_list) > 0:
            truth = '\n'.join([each_truth[0]
                               for each_truth in truth_list]).strip()
        else:
            truth_compiler = re.compile(
                r'(违法事实和证据|违法事实及证据)' + r'([\s\S]*?)' +
                r'((上述|该|以上)(违法|违法违规)?(事实|行为).*?(有)?.*?等证据(在案)?(证明|佐证)(在案)?(.*?足以认定)?)'
            )
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(2).strip()
            else:
                truth_compiler = re.compile(
                    litigant.replace(r'(', r'\(').replace(r')', r'\)') +
                    r'([\s\S]*?)' +
                    r'(依据《中华人民共和国保险法》第一百四十五条第(八)项的规定|你是负有直接责任的高级管理人员。|'
                    r'(上述|该|以上)(违法)?(事实|行为).*?(有)?.*?等证据(在案)?(证明|佐证)(在案)?(.*?足以认定)?|'
                    r'(依据|根据).*?第.*?条.*?规定|'
                    r'上述事实(行为)?.*?违反了.*?第?.*?条)')
                truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|[^,。,;\n]*?未[^,。,;\n]*?提出陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?(申辩材料|陈述申辩|申辩)中?称|' \
                               r'[^,。,;\n]*?陈述申辩.*?(要求|请求)|' \
                               r'[^,。,;\n]*?提出陈述申辩|' \
                               r'人保寿险鹤岗中心支公司对行政处罚认定的事实无异议,但请求减轻行政处罚。|' \
                               r'阳光财险黑龙江省分公司在陈述申辩材料中请求不吊销阳光财险哈尔滨营业部经营保险业务许可证|' \
                               r'当事人提出了听证及陈述申辩意见)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'黑龙江保监局经复核认为|' \
                               r'黑龙江保监局经审理(后)?认为|' \
                               r'黑龙江保监局认为|' \
                               r'黑龙江保监局经过调查核实后认为|' \
                               r'我局认为,阳光财险黑龙江省分公司在陈述申辩材料中提出的理由与违法行为无关,不予采纳。|' \
                               r'我局依法举行了听证并对陈述申辩意见进行了复核)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                         r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                         r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                         r'决定对.*?罚款数额适当下调。|' \
                                                         r'综上,我局.*?陈述申辩意见不予采纳|' \
                                                         r'黑龙江保监局对.*?申辩意见不予采纳。|' \
                                                         r'综上,黑龙江保监局.*?(陈述)?申辩(理由|内容)?不予采纳。|' \
                                                         r'综上,黑龙江保监局采纳.*?陈述申辩意见。|' \
                                                         r'综上,对.*?上述(陈述)?申辩理由不予采纳。|' \
                                                         r'五是人保财险黑龙江省分公司在检查前主动自查整改并报告,具有主动减轻违法行为危害后果的情节。|' \
                                                         r'组织落实自查整改并报告,具有主动减轻违法行为危害后果的情节。|' \
                                                         r'黑龙江保监局对.*?陈述申辩(理由)?不予采纳。|' \
                                                         r'黑龙江保监局对大地财险大庆中心支公司陈述申辩予以采纳,酌情给予从轻处罚。|' \
                                                         r'其辩称家庭原因和悔改表现不是法定从轻、减轻理由,不予采信。|' \
                                                         r'故对其第二项陈述申辩内容不予采纳|' \
                                                         r'故对其陈述申辩不予采纳。|' \
                                                         r'我局认为,阳光财险黑龙江省分公司在陈述申辩材料中提出的理由与违法行为无关,不予采纳。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                defense_response = defense_response_compiler.search(
                    content_text).group(1).strip()
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据)[^。;\n]*?第?[^。;\n]*?条[^。;\n]*?(规定)?.?(我局|黑龙江保监局)?' \
                                       r'(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|依法撤销|对.*?给予)|' \
                                       r'(综上,)?我局.*?决定.*?作出(如下|以下)(行政)?处罚:)' \
                                       r'([\s\S]*?))' \
                                       r'(当事人应当在接到本处罚决定书之日|当事人.*?如对本处罚决定不服|本处罚决定书自送达之日起执行|' \
                                       r'你公司如不服本处罚决定|请你.*?在接到本处罚决定书之日|如不服本处罚决定|请你公司在接到本处罚决定书之日|' \
                                       r'请.*?在接到本处罚决定书之日|\n.*?履行方式及期限|.*?在收到本处罚决定书之日|请在收到本处罚决定书之日)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision_list = punishment_decision_compiler.findall(
            content_text)
        punishment_decision = '\n'.join([
            each_punishment_decision[0]
            for each_punishment_decision in punishment_decision_list
        ]).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实|中华联黑龙江分公司虚列增值服务费|人保财险道外支公司未按照规定使用车险条款费率|'
            r'人保财险南岗支公司2015年虚列宣传费)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'上述第一项行为违反《中华人民共和国保险法》第一百二十四条的规定。'
            r'上述第二项行为违反《中华人民共和国保险法》第八十六条、第一百三十三条的规定。'
            r'上述第三项行为违反《保险专业代理机构监管规定》(2013)第六十二条的规定。'
            r'上述第四项行为违反《保险专业代理机构监管规定》(2013)第三十二条的规定',
            r'你单位于2009年违反交强险费率浮动规定,违反了《中华人民共和国保险法》第一百零七条的规定',
            r'上述事实行为违反了《保险法》一百零七条、一百二十二条', r'上述事实行为违反了《保险法》一百二十二条',
            r'上述事实行为违反了《保险法》一百零七条', r'上述事实行为违反了《保险法》第八十条、一百零六条',
            r'上述事实行为违反了《保险法》一百零七条、一百零九条、一百二十二条',
            r'1、2008年未经批准在海伦设立黑龙江润融保险代理有限公司分支机构并担任主要负责人,经营保险代理业务,违反了《保险代理机构管理规定》第二条规定',
            r'1、黑龙江润融保险代理有限公司2008年未经批准在海伦设立分支机构,经营保险代理业务,违反了《保险代理机构管理规定》第二条规定',
            r'1、你公司2008年未经批准在海伦设立分支机构,经营保险代理业务,违反了《保险代理机构管理规定》第二条规定',
            r'上述事实行为违反了《机动车交通事故责任强制保险条例》的规定',
            r'新华人寿宁安支公司对业务员使用违规产品计划书销售保险产品未能实施有效管控,违反《保险公司管理规定》第五十五条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            '[。\n;]' + '(' + punishment_basis_str + ')' +
            r'.(\n*?依据|\n*?根据|\n*?鉴于|\n*?[^\n。;]*?陈述申辩)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list]).strip()

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '黑龙江银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('黑龙江保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('黑龙江保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('黑龙江保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #6
0
ファイル: qinghai.py プロジェクト: wagaman/jgcf
def qinghai_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '青海保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('青海保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((青保监罚|青银保监筹?).\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(document_code + r'\n([\s\S]*?)\n' +
                                           r'(经查|经检查|(依据|根据).*?有关规定|抽查|'
                                           r'经抽查|'
                                           r'依据.*?本案现已审理终结)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(r'^([\s\S]*?)\n' +
                                           r'(经查|经检查|(依据|根据).*?有关规定|抽查|经抽查|'
                                           r'依据.*?本案现已审理终结)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:|经查:|' \
                         r'我局在.*?现场检查中发现.*?存在以下违法行为:)' \
                         r'([\s\S]*?)' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上|该).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'综上,做出如下处罚决定:)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r',违反了《保险法》第一百二十二条“保险公司的营业报告、财务会计报告、精算报告及其他有关报表、' \
                                        r'文件和资料必须如实记录保险业务事项,不得有虚假记载、误导性陈述和重大遗漏”的规定|' \
                                        r'依据.*?第.*?条.*?的规定,我局决定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'当事人[^,。,;\n]*?提出了陈述申辩)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   r'我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|综上,青海保监局决定作出如下行政处罚:|' \
                                       r'依据该规定,我局决定|依据.*?第.*?条“对违反\n.*?\n.*?之规定,我局决定对你做出以下行政处罚:)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|\n.*?接到本处罚决定书)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;\s]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)?违反([^\n。;\s]*?)\n?([^\n。;\s]*?)'
            r'第([^\n。;\s]*?)条\n?.*?((的|之|等)(相关)?规定)?', r'.*?违反了.*?第.*?条规定',
            r'(以上|该)行为([^\n。;\s]*?)违反了([^\n。;\s]*?)第.*?条.*?的规定。\n你作为.*?,对此负有直接责任'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[\n。;]' + '(' + punishment_basis_str + ')' +
            r'.(\n?(事实一)?依据|\n?根据|\n?鉴于|'
            r'\n?有?.*?为证|\n?二|\n?三)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '青海银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('青海保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('青海保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('青海保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #7
0
ファイル: fujian.py プロジェクト: wagaman/jgcf
def fujian_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '福建保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('福建保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((闽保监罚|闽银保监罚决字).\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)' + r'(\n经查|\n经检查|'
                                  r'\n?依据.*?的有关规定|\n抽查|\n经抽查|'
                                  r'\n.*?现场检查|\n.*?进行调查|\n.*?调查|'
                                  r'\n.*?信访核查|\n.*?行政许可审核中发现|'
                                  r'\n?.*?我局根据信访件提供的线索|'
                                  r'\n?2008年3月21日)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|.*?现场检查|'
                                                              r'.*进行调查)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'((经查|.*?存在.*?行为)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?[^,。,;\n]*?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'你公司虚列会议费套取费用用于其他方面开支的行为,违反了《保险法》|' \
                         r'你公司未按规定使用经核准或备案的条款费率行为,违反了《保险法》|' \
                         r'根据《保险法》第一百五十条的规定,对你处以2万元罚款)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'你在.*?材料中(称|提出)|你[^,。,;\n]*?在.*?中未对我局认定的(违法|违规)事实|' \
                               r'[^,。,;\n]*?申辩称)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'我局对陈述和申辩材料进行了复核,我局认为|' \
                               r'经查|我局认为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                          r'不予采纳。|因此,不予采纳当事人的陈述申辩意见。|' \
                                                          r'因此,对你提出的陈述和申辩意见不予采纳。))'
                defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'我局作出如下处罚)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|[^。;\n]*?如对本处罚决定不服|' \
                                       r'[^。;\n]*?对以上行政处罚决定(如)?不服)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;::]*?)(问题|行为|事项|情况|事实|财务不真实|财务数据不真实)([^\n。;]*?)违(反|法)([^\n。;]*?)第.*?条.*?((的|之|等)(相关)?规定)?',
            r'吴淑汝代替投保人抄录风险提示语句,违反了《人身保险新型产品信息披露管理办法》第六条的规定',
            r'平安人寿上海电销中心上述行为《保险法》(2014年修正)第一百一十六条第一项的规定',
            r'富邦财产保险有限公司福州营销服务部未严格执行条款费率,违反了《保险法》第一百三十六条的规定',
            r'账外暗中支付给中介机构委托合同以外的利益,违反了《保险公司中介业务违法行为处罚办法》第十条',
            r'对代理人培训不到位、执行代理业务核查制度不到位,违反了《保险公司中介业务违法行为处罚办法》第六条和第七条',
            r'中国平安财产保险股份有限公司宁德中心支公司违反了《保险法》第一百一十六条第十项的规定',
            r'一、富邦财产保险有限公司福州营销服务部未严格执行条款费率,违反了《保险法》第一百三十六条的规定',
            r'二、富邦财产保险有限公司福州营销服务部虚列费用,违反了《保险法》第八十六条第二款的规定',
            r'我局认为,你公司未缴存保证金,也未投保职业责任保险,违反了《保险专业代理机构监管规定》第三十九条',
            r'你公司未按照要求及时预缴当年及清缴上年的监管费,违反了《保险专业代理机构监管规定》第六十三条',
            r'经查,在你任中国人民财产保险股份有限公司福清支公司经理期间,该公司在参加2009年福清市行政事业单位公务车辆统一投保项目(招标编号:0624-09180123)的投标活动中,违反了《保险法》第一百零七条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(r'[。\n;::]' + '(' + punishment_basis_str + ')' +
                                               '.(\n?依据|\n?根据|\n?鉴于)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
            replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
            m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '福建银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('福建保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('福建保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('福建保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #8
0
ファイル: neeq_parse.py プロジェクト: wagaman/jgcf
def parse_neeq():
    # download pdf files
    for each_neeq_document in db.neeq_data.find(
        {'status': {
            '$nin': ['ignored']
        }}):
        announcement_url = each_neeq_document['url']
        announcement_title = each_neeq_document['title']

        if db.neeq_data.find({
                'url': announcement_url
        }).count() >= 2 and each_neeq_document['type'] != '纪律处分':
            logger.warning(announcement_url + ' ' + announcement_title +
                           ' 在纪律处分与监管措施中一起出现')
            db.neeq_data.update_one({'_id': each_neeq_document['_id']},
                                    {'$set': {
                                        'status': 'ignored'
                                    }})
            logger.info('股转系统' + ' 重复数据' + ' -- 修改status完成')
            continue

        if '备案材料审查进度表' in announcement_title or \
                '撤销对' in announcement_title or \
                '关于对未按期披露2017年半年度报告的挂牌公司及相关信息披露责任人采取自律监管措施的公告' in announcement_title or \
                '关于对未按期披露2016年年度报告的挂牌公司及相关信息披露责任人采取自律监管措施的公告' in announcement_title or \
                '关于对未按期披露2017年年度报告的挂牌公司及相关信息披露责任人采取自律监管措施的公告' in announcement_title or \
                '关于对未按期披露2018年第一季度报告的挂牌公司及相关信息披露责任人采取自律监管措施的公告' in announcement_title:
            logger.warning(announcement_url + ' ' + announcement_title +
                           ' 与监管处罚无关')
            db.neeq_data.update_one({'_id': each_neeq_document['_id']},
                                    {'$set': {
                                        'status': 'ignored'
                                    }})
            logger.info('股转系统' + ' 无关数据' + ' -- 修改status完成')
            continue

        if db.neeq_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('Url to parse: ' + announcement_url)

        response = request_site_page(announcement_url)
        if response is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue

        with open('./test/tmp.pdf', 'wb') as f:
            f.write(response.content)
        content_text = pdf_to_text('./test/tmp.pdf')
        logger.info(content_text)

        with open('./test/tmp.pdf', 'rb') as pdf_file:
            pdf_content = pdf_file.read()

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_neeq_document['_id'],
                'oss_file_type': 'pdf',
                'oss_file_name': announcement_title,
                'oss_file_content': pdf_content,
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.pdf',
                         pdf_content)
            db.neeq_data.update_one({'_id': each_neeq_document['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.neeq_data.update_one({'_id': each_neeq_document['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']
            db.parsed_data.update_one(
                {'_id': file_id},
                {'$set': {
                    'origin_url_id': each_neeq_document['_id']
                }})

        try:
            if each_neeq_document['type'] == '监管措施':
                announcement_code_text = re.search(
                    r'^(全国中小企业股份转让系统文件\n)?(.*?)\n',
                    content_text).group(2).strip()
                if '股转系统发' in announcement_code_text:
                    announcement_code = announcement_code_text
                else:
                    announcement_code = '股转系统发〔' + announcement_code_text[:4] + '〕' + announcement_code_text[
                        4:] + '号'

                if re.search(
                        r'(自律\n?监管\n?措\n?施的?决定|纪律\n?处分\n?的决定|'
                        r'约见谈话措施的决定|监管措施的决定|通报批评的决定|'
                        r'自律监管措施的决定的公告)' + r'([\s\S]*?)'
                        r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                        r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                        r'经查明,拥湾汇)', content_text):
                    litigant = re.search(
                        r'(自律\n?监管\n?措\n?施的?决定|纪律\n?处分\n?的决定|'
                        r'约见谈话措施的决定|监管措施的决定|通报批评的决定|'
                        r'自律监管措施的决定的公告)' + r'([\s\S]*?)'
                        r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                        r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                        r'经查明,拥湾汇)', content_text).group(2).strip()
                else:
                    try:
                        litigant = re.search(
                            announcement_code_text + r'([\s\S]*?)'
                            r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                            r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                            r'经查明,拥湾汇)', content_text).group(1).strip()
                    except Exception as e:
                        # logger.error(e)
                        litigant = re.search(
                            '((当事人)' + r'[\s\S]*?)'
                            r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                            r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                            r'经查明,拥湾汇|'
                            r'2018年2月至5月,雷磊以资金拆借方式|'
                            r'2018年7月25日,我司发出《关于对雷蒙德(北京))',
                            content_text).group(1).strip()

                punishment_decision = re.search(
                    r'(((鉴于|基于)(以上|上述)(违规)?事实([和与及]情节)?.*?(根据|经|依据)|'
                    r'鉴于前述事实,根据|鉴于上述.*?事实和情节,根据|'
                    r'根据《全国中小企业股份转让系统业务规则\(试行\)》第6.1条|'
                    r'据《全国\n?中小企业股份转让系统业务规则\(试行\)》|'
                    r'鉴于你公司存在上述违规行为后,公司管理层能够积极整改|'
                    r'根据《业务规则》第6.1条之规定,我司决定|'
                    r'鉴于中道糖业存在上述违规事实,并考虑其在前两次发行|'
                    r'鉴于三联交通及财务总监方向勇存在上述违规事实,根据|'
                    r'鉴于.*?存在上述多项违规事实,违规情节恶劣,根据)'
                    r'[\s\S]*?)'
                    r'(\n全国股转|$)', content_text).group(1).strip()

                truth_text_str = litigant.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                                     .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*') \
                                     .replace(r'+', r'\+') + \
                                 r'([\s\S]*?)' \
                                 r'((。)[^。]*?行为[^。\n]*?违反|综上|你公\n司上述行为违反了|' + \
                                 punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                                     .replace(r'[', r'\[').replace(r']', r'\]') \
                                     .replace(r'*', r'\*').replace(r'+', r'\+') + ')'

                truth_compiler = re.compile(truth_text_str, re.MULTILINE)
                truth_list = truth_compiler.findall(content_text)
                truth = '\n'.join([kk[0]
                                   for kk in truth_list]).replace('査',
                                                                  '查').strip()

                punishment_basis_text_str = truth_list[-1][0].replace(r'(', r'\(').replace(r')', r'\)') \
                                                .replace(r'.', r'\.') \
                                                .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*') \
                                                .replace(r'+', r'\+').replace(r'>', r'\>').replace(r'?', r'\?') \
                                            + r'([\s\S]*?)' \
                                            + punishment_decision.replace(r'(', r'\(').replace(r')', r'\)') \
                                                .replace(r'.', r'\.').replace(r'[', r'\[').replace(r']', r'\]') \
                                                .replace(r'*', r'\*').replace(r'+', r'\+')
                punishment_basis_compiler = re.compile(
                    punishment_basis_text_str, re.MULTILINE)
                punishment_basis = punishment_basis_compiler.search(
                    content_text).group(1).strip()
                if punishment_basis != '' and punishment_basis[0] == '。':
                    punishment_basis = punishment_basis[1:].strip()

                publish_date_text = re.search(
                    punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                    .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*').replace(r'+', r'\+')
                    + r'([\s\S]*?)$', content_text).group(1).strip()
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一ー二ニ两三四五六七八九十O-]+年)([0-9一ー二ニ两三四五六七八九十]+)月([0-9一ー二ニ两三四五六七八九十+]+)([号日])",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    # publish_date = each_neeq_document['publishDate'].split('-')
                    real_publish_date = ''
                    # str(int(publish_date[0])) + '年' + str(int(publish_date[1])) + '月' + \
                    #                 str(int(publish_date[2])) + '日'

                result_map = {
                    'announcementTitle':
                    announcement_title,
                    'announcementOrg':
                    '股转系统',
                    'announcementDate':
                    real_publish_date,
                    'announcementCode':
                    announcement_code,
                    'facts':
                    truth,
                    'defenseOpinion':
                    '',
                    'defenseResponse':
                    '',
                    'litigant':
                    litigant[:-1].strip() if litigant[-1] == ':'
                    or litigant[-1] == ':' else litigant.strip(),
                    'punishmentBasement':
                    punishment_basis,
                    'punishmentDecision':
                    punishment_decision,
                    'type':
                    '监管措施',
                    'oss_file_id':
                    file_id,
                    'status':
                    'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({
                        'announcementTitle': announcement_title,
                        'oss_file_id': file_id
                }).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('股转系统 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('股转系统 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id},
                                          {'$set': {
                                              'parsed': True
                                          }})
                logger.info('股转系统 数据解析 ' + ' -- 修改parsed完成')
                logger.info('删除TMP文件')
                if os.path.exists('./test/tmp.pdf'):
                    os.remove('./test/tmp.pdf')
            elif each_neeq_document['type'] == '纪律处分':
                announcement_code_text = re.search(
                    r'^(全国中小企业股份转让系统文件\n)?(.*?)\n',
                    content_text).group(2).strip()
                if '股转系统发' in announcement_code_text:
                    announcement_code = announcement_code_text
                else:
                    announcement_code = '股转系统发〔' + announcement_code_text[:4] + '〕' + announcement_code_text[
                        4:] + '号'

                if re.search(
                        r'(自律\n?监管\n?措\n?施的?决定|纪律\n?处分\n?的决定|'
                        r'约见谈话措施的决定|监管措施的决定|通报批评的决定|'
                        r'自律监管措施的决定的公告)' + r'([\s\S]*?)'
                        r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                        r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                        r'经查明,拥湾汇)', content_text):
                    litigant = re.search(
                        r'(自律\n?监管\n?措\n?施的?决定|纪律\n?处分\n?的决定|'
                        r'约见谈话措施的决定|监管措施的决定|通报批评的决定|'
                        r'自律监管措施的决定的公告)' + r'([\s\S]*?)'
                        r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                        r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                        r'经查明,拥湾汇)', content_text).group(2).strip()
                else:
                    litigant = re.search(
                        announcement_code_text + r'([\s\S]*?)'
                        r'(\n经査|\n经查|\n查明|\n首创证券推荐挂牌的世纪天鸿|'
                        r'\n世纪天鸿于2016年6月23日|\n2016年1月至2017年4月|'
                        r'经查明,拥湾汇)', content_text).group(1).strip()

                punishment_decision = re.search(
                    r'(((鉴于|基于)(以上|上述)(违规)?事实([和与及]情节)?.*?(根据|经|依据)|'
                    r'鉴于前述事实,根据|鉴于上述.*?事实和情节,根据|'
                    r'根据《全国中小企业股份转让系统业务规则\(试行\)》第6.1条|'
                    r'据《全国\n?中小企业股份转让系统业务规则\(试行\)》|'
                    r'鉴于你公司存在上述违规行为后,公司管理层能够积极整改|'
                    r'根据《业务规则》第6.1条之规定,我司决定|'
                    r'鉴于中道糖业存在上述违规事实,并考虑其在前两次发行|'
                    r'鉴于三联交通及财务总监方向勇存在上述违规事实,根据|'
                    r'鉴于.*?存在上述多项违规事实,违规情节恶劣,根据)'
                    r'[\s\S]*?)'
                    r'(\n全国股转|$)', content_text).group(1).strip()

                truth_text_str = litigant.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                                     .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*') \
                                     .replace(r'+', r'\+') + \
                                 r'([\s\S]*?)' \
                                 r'((。)[^。]*?行为[^。\n]*?违反|综上|你公\n司上述行为违反了|' + \
                                 punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                                     .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*') \
                                     .replace(r'+', r'\+') + ')'

                truth_compiler = re.compile(truth_text_str, re.MULTILINE)
                truth_list = truth_compiler.findall(content_text)
                truth = '\n'.join([kk[0]
                                   for kk in truth_list]).replace('査',
                                                                  '查').strip()

                punishment_basis_text_str = truth_list[-1][0].replace(r'(', r'\(').replace(r')', r'\)') \
                                                .replace(r'.', r'\.') \
                                                .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*') \
                                                .replace(r'+', r'\+').replace(r'>', r'\>').replace(r'?', r'\?') \
                                            + r'([\s\S]*?)' \
                                            + punishment_decision.replace(r'(', r'\(').replace(r')', r'\)') \
                                                .replace(r'.', r'\.').replace(r'[', r'\[').replace(r']', r'\]') \
                                                .replace(r'*', r'\*').replace(r'+', r'\+')
                punishment_basis_compiler = re.compile(
                    punishment_basis_text_str, re.MULTILINE)
                punishment_basis = punishment_basis_compiler.search(
                    content_text).group(1).strip().strip()
                if punishment_basis != '' and punishment_basis[0] == '。':
                    punishment_basis = punishment_basis[1:].strip()

                publish_date_text = re.search(
                    punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'.', r'\.') \
                    .replace(r'[', r'\[').replace(r']', r'\]').replace(r'*', r'\*').replace(r'+', r'\+')
                    + r'([\s\S]*?)$', content_text).group(1).strip()
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一ー二ニ两三四五六七八九十O-]+年)([0-9一ー二ニ两三四五六七八九十]+)月([0-9一ー二ニ两三四五六七八九十+]+)[号日]",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    # publish_date = each_neeq_document['announcementDate']
                    # real_publish_date = str(int(publish_date['year'])) + '年' + str(
                    #     int(publish_date['month'])) + '月' + \
                    #                     str(int(publish_date['day'])) + '日'
                    real_publish_date = ''

                result_map = {
                    'announcementTitle':
                    announcement_title,
                    'announcementOrg':
                    '股转系统',
                    'announcementDate':
                    real_publish_date,
                    'announcementCode':
                    announcement_code,
                    'facts':
                    truth,
                    'defenseOpinion':
                    '',
                    'defenseResponse':
                    '',
                    'litigant':
                    litigant[:-1].strip() if litigant[-1] == ':'
                    or litigant[-1] == ':' else litigant.strip(),
                    'punishmentBasement':
                    punishment_basis,
                    'punishmentDecision':
                    punishment_decision,
                    'type':
                    '纪律处分',
                    'oss_file_id':
                    file_id,
                    'status':
                    'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({
                        'announcementTitle': announcement_title,
                        'oss_file_id': file_id
                }).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('股转系统 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('股转系统 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id},
                                          {'$set': {
                                              'parsed': True
                                          }})
                logger.info('股转系统 数据解析 ' + ' -- 修改parsed完成')
                logger.info('删除TMP文件')
                if os.path.exists('./test/tmp.pdf'):
                    os.remove('./test/tmp.pdf')
        except Exception as exc:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            logger.error('出错行数:%s' % str(exc_tb.tb_lineno))
            logger.error(exc)
            logger.info('删除TMP文件')
            if os.path.exists('./test/tmp.pdf'):
                os.remove('./test/tmp.pdf')
            if os.path.exists('./test/tmp.txt'):
                os.remove('./test/tmp.txt')
            if os.path.exists('./test/tmp/'):
                for each_txt in os.listdir('./test/tmp'):
                    os.remove('./test/tmp/' + each_txt)
                os.rmdir('./test/tmp')
            if os.path.exists('./test/tmp.doc'):
                os.remove('./test/tmp.doc')
            if os.path.exists('./test/tmp.docx'):
                os.remove('./test/tmp.docx')
            continue
コード例 #9
0
ファイル: shanxi.py プロジェクト: wagaman/jgcf
def shanxi_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '山西保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('山西保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if re.search(r'((晋银?保监罚字|晋银保监筹罚字).\d{4}.\d+号)\n', content_text):
            text_document_code = re.search(r'((晋银?保监罚字|晋银保监筹罚字).\d{4}.\d+号)\n',
                                           content_text).group(1)
            litigant_compiler = re.compile(
                text_document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|'
                r'依据.*?有关规定|\d{4}年.*?[月日],我(机关|局)对.*?进行(了)?(现场检查|信访检查|.*?专项检查)|'
                r'\d{4}年.*?[月日],中发现保监会、财政部联合检查组对.*进行了现场检查|'
                r'我(机关|局)对.*?进行(了)?(现场检查|信访检查|.*?专项检查)|在你任职.*?期间|'
                r'2015年,三合保险代理公司向我局提交了虚假行政许可申请资料。|'
                r'我局(检查组)?于?.*?对.*?进行了现场检查[。,]|我局检查组于?.*?对.*?进行了调查[。,]|'
                r'山西鑫晟保险代理有限公司未按规定期限向我局申请延续《经营保险代理业务许可证》)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
            document_code = text_document_code.strip()
        else:
            if re.search(r'((晋银?保监罚字|晋银保监筹罚字).\d{4}.\d+号)', title):
                document_code = re.search(r'((晋银?保监罚字|晋银保监筹罚字).\d{4}.\d+号)',
                                          title).group(1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' +
                r'(我局检查组于?.*?对.*?进行了现场检查。|我局检查组于?.*?对.*?进行了调查,|'
                r'山西鑫晟保险代理有限公司未按规定期限向我局申请延续《经营保险代理业务许可证》|'
                r'经查|山西中铁十二局保险代理公司的《经营保险代理业务许可证》于2016年2月8日到期|'
                r'我局在日常监管中|我(机关|局)对.*?进行(了)?(现场检查|信访检查|.*?专项检查)|'
                r'我局(检查组)?于?.*?对.*?(进行|开展|实施)了?.*?(专项检查|现场检查|暗访)(中)?(发现)?.*?[。,]|'
                r'我局在非现场检查中发现你公司存在以下违法违规行为:|根据举报|我局在对你公司的非现场监管中|经检查|'
                r'在你任职.*?期间|依据.*?有关规定|'
                r'你公司存在.*?的违规行为|你公司未经我局批准|在2008年清理整顿保险兼业代理市场工作中)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:|经审核)' \
                         r'([\s\S]*?)' \
                         r'(上述(违法)?事实(,)?有[\s\S]*?等证据(在案)?(证明|佐证)(在案)?(,|,)足以认定。|' \
                         r'上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                         r'该违法事实,有.*?等证据在案证明,足以认定|' \
                         r'\n.*?等证据材料可证明上述事实。|' \
                         r'该公司上述行为违反了《保险法》第.*?条|' \
                         r'综上,决定给予你公司.*?的行政处罚|' \
                         r'(上述|以上)(违法)?(事实(行为)?|行为)(分别)?违反了.*?第.*?条(的)?(规定)?|' \
                         r'依据《保险营销员管理规定》第.*条规定|' \
                         r'我局认为,.*?的规定|上述事实行为违反了\n《保险法》(\n2002\n年)第.*?条\n的规定|' \
                         r'上述事实行为违反了《中华人民共和国保险法》(\n2002\n年修正)第一百二十二条规定|' \
                         r'以上行为违反了《保险法》第.*?条.*?的规定|' \
                         r'你营销服务部的上述行为,造成了财务数据不真实|' \
                         r'根据《保险营销员管理规定》第五十六条“保险公司组织、参与、协助保险营销员考试作弊的|' \
                         r'违反了《保险公司管理规定》第.*?条|' \
                         r'违反了《保险营销员管理规定》第.*?条|' \
                         r'违反了《保险法》第.*?条|' \
                         r'上述事实行为违反了《保险公司管理规定》第.*?条|' \
                         r'依据《保险营销员管理规定》第.*?条|' \
                         r'依据《保险代理机构管理规定》第.*?条|' \
                         r'上述事实违反了《保险公司管理规定》(保监会令[2004]3号)第.*条|' \
                         r'阳光财险山西省分公司的上述事实有该公司以及相关人员出具的相关说明、现场检查事实确认书、相关记账凭证复印件等证据在案佐证,足以认定。|' \
                         r'你公司提供虚假材料的行为,违反了《保险专业代理机构监管规定》第二十四条)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = r'(经查,|经查,|经查实,)' \
                             r'([\s\S]*?)' \
                             r'[^,。,;\n]*?(上述(违法)?事实(,|,)?.*?(有)?.*?等证据(在案)?(证明|佐证)(在案)?(,|,)足以认定。|' \
                             r'上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                             r'该违法事实,有.*?等证据在案证明,足以认定|' \
                             r'该公司上述行为违反了《保险法》第.*?条|' \
                             r'综上,决定给予你公司.*?的行政处罚|' \
                             r'(上述|以上)(违法)?(事实(行为)?|行为)(分别)?违反了.*?第.*?条(的)?(规定)?|' \
                             r'依据《保险营销员管理规定》第.*条规定|' \
                             r'我局认为,.*?的规定|上述事实行为违反了\n《保险法》(\n2002\n年)第.*?条\n的规定|' \
                             r'你时任泰康人寿朔州中支的总经理,并负责财务管理,对上述行为负有直接责任。|' \
                             r'你作为.*负有直接责任。|' \
                             r'应当对上述行为负责。|' \
                             r'保险代理机构任用高级管理人员,其任职资格应当报经中国保监会核准。”的规定。|' \
                             r'该行为违反了《保险代理\n?机构管理规定》第.*?条|' \
                             r'你公司.*?的行为,违反了《保险专业代理机构监管规定》第.*?条|' \
                             r'(以上行为)?造成了.*?,违反了《保险公司管理规定》第.*?条|' \
                             r'以上行为造成了.*?,违反了《保险代理机构管理规定》第.*?条|' \
                             r'(以上行为)?造成了.*?,违反了《保险代理机构管理规定》第.*?条|' \
                             r'违反了《.*?》第.*?条|' \
                             r'以上违规行为有相关资料佐证。)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(2).strip()
            else:
                truth_text_str = r'(' + litigant + r'\n)' \
                                                   r'([\s\S]*?)' \
                                                   r'[^,。,;\n]*?(上述(违法)?事实' \
                                                   r'(,|,)?.*?(有)?.*?\n?.*?等证据(在\n?案)?\n?(证明|佐证)(在案)?(,|,)足以认定。|' \
                                                   r'上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                                                   r'该违法事实,有.*?等证据在案证明,足以认定|你作为.*负有直接责任。|' \
                                                   r'违反了《中华人民共和国保险法》第八十条|' \
                                                   r'违反了《关于调整保险业务监管费收费标准和收费办法的通知》|' \
                                                   r'违反了《中华人民共和国保险法》第.*?条|' \
                                                   r'你作为.*?负有直接责任)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(2).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|当事人[^,。,;\n]*?未提出陈述申辩意见|' \
                               r'[^,。,;\n]*?向我局(报送|递交)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'我局认为.*?的行为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                     r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                     r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                     r'因此不予采纳申辩意见。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                defense_response = defense_response_compiler.search(
                    content_text).group(1).strip()
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'依据《保险法》第一百七十九条“违反法律、行政法规的规定,情节严重的,国务院保险监督管理机构可以禁止有关责任人员\n一定期限直至终身进入保险业。” 的规定|' \
                                       r'依据《保险专业代理机构监管规定》第七十六条[\s\S]*?的规定,我局决定|' \
                                       r'依据该规定,我局决定[\s\S]*?\n|' \
                                       r'依据.*?第.*?条[\s\S]*?的规定,我局决定[\s\S]*?\n|' \
                                       r'依据该规定,决定给予你公司作出警告,并罚款5000元的行政处罚。)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人如对本处罚决定不服|' \
                                       r'请及时联系我局办公室确认缴纳罚款事宜)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实|数据不真实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'经查实[\s\S]*?违反[\s\S]*?规定(.*?负有直接责任)?',
            r'你公司拒不缴存保证金,且情节严重,违反了《中华人民共和国保险法》第一百三十二条的规定',
            r'在2008年清理整顿保险兼业代理市场工作中,我局于2007年12月27日和2008年5月23日两次在《山西日报》发布要求缴清监管费的公告后,'
            r'下列机构拒不缴纳监管费,违反了《关于调整保险业务监管费收费标准和收费办法的通知》(保监发[2006]13号)“对从事保险兼业代理的机构,'
            r'按每年每家机构500元定额收取保险业务监管费。”'
            r'和《中华人民共和国保险法》第一百零九条“保险监督管理机构有权检查保险公司的业务状况、财务状况及资金运用状况,'
            r'有权要求保险公司在规定的期限内提供有关的书面报告和资料。保险公司依法接受监督检查。”的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            r'.(\n*?依据|\n*?根据|\n*?鉴于|\n*?上述事实|\n?按照)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace(r'\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○O]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text.strip()
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '山西银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('山西保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('山西保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('山西保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #10
0
ファイル: yantai.py プロジェクト: wagaman/jgcf
def yantai_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '烟台保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('烟台保监分局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚事项' in title:
            if len([
                    urljoin(announcement_url, each_link.attrs['href'])
                    for each_link in content_soup.find_all('a')
                    if '.xls' in each_link.attrs['href']
            ][0]) > 0:
                xlsx_link = [
                    urljoin(announcement_url, each_link.attrs['href'])
                    for each_link in content_soup.find_all('a')
                    if '.xls' in each_link.attrs['href']
                ][0]

                response = request_site_page(xlsx_link)
                with open('./test/tmp.xlsx', 'wb') as out_file:
                    for chunk in response.iter_content(chunk_size=1024):
                        if chunk:
                            out_file.write(chunk)
                with open('./test/tmp.xlsx', 'rb') as xlsx_file:
                    xlsx_content = xlsx_file.read()

                if db.parsed_data.find({
                        'origin_url': announcement_url,
                        'oss_file_origin_url': xlsx_link
                }).count() == 0:
                    oss_file_map = {
                        'origin_url': announcement_url,
                        'oss_file_origin_url': xlsx_link,
                        'origin_url_id': each_circ_data['_id'],
                        'oss_file_type': 'xlsx',
                        'oss_file_name': announcement_title,
                        'oss_file_content': xlsx_content,
                        'parsed': False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(
                        ali_bucket,
                        str(file_id) + '/' + announcement_title + '.xlsx',
                        xlsx_content)
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                    file_id = db.parsed_data.find_one({
                        'origin_url':
                        announcement_url,
                        'oss_file_origin_url':
                        xlsx_link
                    })['_id']

                excel_data = open_workbook('./test/tmp.xlsx')

                logger.info('删除Tmp文件')
                os.remove('./test/tmp.xlsx')

                sheet = excel_data.sheets()[0]
                result_map_list = []
                for i in range(sheet.nrows):
                    if sheet.ncols == 8:
                        if i >= 1:
                            document_code = sheet.cell(i, 0).value
                            real_title = '行政处罚决定书' + '(' + str(
                                document_code) + ')'
                            litigant = sheet.cell(i, 1).value
                            if sheet.cell(i, 2).ctype == 3:
                                publish_date = xldate_as_tuple(
                                    sheet.cell_value(i, 2),
                                    excel_data.datemode)
                                publish_date = str(
                                    publish_date[0]) + '年' + str(
                                        publish_date[1]) + '月' + str(
                                            publish_date[2]) + '日'
                            else:
                                publish_date = str(
                                    sheet.cell(i, 2).value.year) + '年' + str(
                                        sheet.cell(
                                            i, 2).value.month) + '月' + str(
                                                sheet.cell(i,
                                                           2).value.day) + '日'
                            truth = litigant + sheet.cell(i, 6).value
                            defense = defense_response = ''

                            punishment_decision = '依据' + sheet.cell(i, 5).value + ',我局对' + \
                                                  litigant + '作出以下处罚:' + \
                                                  sheet.cell(i, 3).value
                            punishment_basis = litigant + '上述行为违反了' + sheet.cell(
                                i, 4).value
                            litigant = sheet.cell(
                                i, 1).value + '\n' + sheet.cell(i, 7).value

                            each_map = {
                                'announcementTitle':
                                real_title,
                                'announcementOrg':
                                '烟台银保监分局',
                                'announcementDate':
                                publish_date,
                                'announcementCode':
                                document_code,
                                'facts':
                                truth,
                                'defenseOpinion':
                                defense,
                                'defenseResponse':
                                defense_response,
                                'litigant':
                                litigant[:-1]
                                if litigant[-1] == ':' else litigant,
                                'punishmentBasement':
                                punishment_basis,
                                'punishmentDecision':
                                punishment_decision,
                                'type':
                                '行政处罚决定',
                                'oss_file_id':
                                file_id,
                                'status':
                                'not checked'
                            }
                            if db.announcement.find({
                                    'announcementTitle': real_title,
                                    'oss_file_id': file_id
                            }).count() == 0:
                                db.announcement.insert_one(each_map)
                                logger.info('烟台保监分局 数据解析 ' + ' -- 数据导入完成')
                            else:
                                logger.info('烟台保监分局 数据解析 ' + ' -- 数据已经存在')
                            result_map_list.append(each_map)
                if len(result_map_list) > 0:
                    db.parsed_data.update_one({'_id': file_id},
                                              {'$set': {
                                                  'parsed': True
                                              }})
                    logger.info('烟台保监分局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.info('烟台保监分局 数据解析 ' + ' -- 没有数据')

        else:
            if db.parsed_data.find({
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url
            }).count() == 0:
                oss_file_map = {
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url,
                    'origin_url_id': each_circ_data['_id'],
                    'oss_file_type': 'html',
                    'oss_file_name': announcement_title,
                    'oss_file_content':
                    r.text.encode(r.encoding).decode('utf-8'),
                    'parsed': False
                }
                insert_response = db.parsed_data.insert_one(oss_file_map)
                file_id = insert_response.inserted_id
                oss_add_file(ali_bucket,
                             str(file_id) + '/' + announcement_title + '.html',
                             r.text.encode(r.encoding).decode('utf-8'))
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
            else:
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
                file_id = db.parsed_data.find_one({
                    'origin_url':
                    announcement_url,
                    'oss_file_origin_url':
                    announcement_url
                })['_id']

            document_code_compiler = re.compile(r'(烟保监罚.\d{4}.\d+号)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?有关规定|抽查|经抽查)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(
                        1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(r'^([\s\S]*?)\n' +
                                               r'(经查|经检查|依据.*?有关规定|抽查|经抽查)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()

            litigant = litigant.replace('行政处罚决定书', '').strip()

            truth_text_str = r'((经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:)' \
                             r'([\s\S]*?))' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等.*?证明(,|,|。)(足以认定。)?|' \
                             r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                             r'.*?的行为.*?违反了.*?第.*?条的规定|' \
                             r'上述情况违反了.*?第.*?条)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(1).strip()
            else:
                truth_text_str = litigant + r'([\s\S]*?)' \
                                            r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                            r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核(认为|决定)|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'经我局审核,决定|' \
                                   r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                   r'我局对陈述申辩意见进行了复核|' \
                                   r'经我局审核|' \
                                   r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                   r'经查,我局认为|' \
                                   r'依据现场检查及听证情况)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0].strip()
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                         r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                         r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                    defense_response_compiler = re.compile(
                        defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(
                            content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = '(当事人在法定期限内未提出听证要求及陈述申辩意见。)'
                    defense_compiler = re.compile(defense_text_str,
                                                  re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(
                        1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?我局(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                           r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                           r'根据《中华人民共和国保险法》第一百六十二的规定,我局责令)' \
                                           r'([\s\S]*?))' \
                                           r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                           r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|请当事人在接到本处罚决定书之日|' \
                                           r'当事人如不服本处罚决定)'

            punishment_decision_compiler = re.compile(
                punishment_decision_text_str)
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(1).strip()

            punishment_basis_str_list = [
                r'([^\n。;\s]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(
                r'[。\n;]' + '(' + punishment_basis_str + ')' +
                '.(\n?(应当)?依据|\n?根据|\n?鉴于)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(
                content_text)
            punishment_basis = ';'.join(
                [kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(
                    r')', r'\)').replace(r'[', r'\[').replace(
                        r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1].replace(
                                              ' ', '')
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '烟台银保监分局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find({
                    'announcementTitle': title,
                    'oss_file_id': file_id
            }).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('烟台保监分局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('烟台保监分局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id},
                                      {'$set': {
                                          'parsed': True
                                      }})
            logger.info('烟台保监分局 数据解析 ' + ' -- 修改parsed完成')
コード例 #11
0
def shanghai_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '上海保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('上海保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code = re.search(r'(沪银?保监罚.\d{4}.\d+号).*?$',
                                  title).group(1).strip()

        if re.search(r'^(沪银?保监罚.*)\n', content_text):
            text_document_code = re.search(r'(沪银?保监罚.*)\n',
                                           content_text).group(1)
            litigant_compiler = re.compile(
                text_document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' +
                r'(经查|依据.*?有关规定|\d{4}年.*?[月日],我(机关|局)对.*?进行(了)?(现场检查|信访检查|.*?专项检查)|'
                r'\d{4}年.*?[月日],中发现保监会、财政部联合检查组对.*进行了现场检查|'
                r'我(机关|局)对.*?进行(了)?(现场检查|信访检查|.*?专项检查)|在你任职.*?期间|'
                r'2015年,三合保险代理公司向我局提交了虚假行政许可申请资料。|'
                r'我局(检查组)?于?.*?对.*?进行了现场检查[。,]|我局检查组于?.*?对.*?进行了调查[。,]|'
                r'山西鑫晟保险代理有限公司未按规定期限向我局申请延续《经营保险代理业务许可证》)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' +
                r'(依据.*?的有关规定|.*?违法事实和证据|.*违规事实和证据|.*违法事实及证据|'
                r'2009年6月至11月间,你.*代理销售保险产品|'
                r'你公司于.*?在.*?保险(代理|经纪)人职业责任保险|'
                r'经查|你公司在.*中,存在.*?情况。|在你担任.*?期间|你公司在.*?业务过程中|'
                r'你公司.*?安排进出口货运险业务时|经检查并在现场检查取证记录.*?签章确认|'
                r'.*?你.*?担任.*?期间|你公司于.*?期间|'
                r'你公司.*?为|你公司.*?过程中)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'(经查,|经查,|经查实,|检查发现,|违法事实和证据|违规事实和证据|违法事实及证据|' \
                         r'经检查并在现场检查取证记录04号中经你公司签章确认,)' \
                         r'([\s\S]*?)' \
                         r'((上述|以上)(违法)?(事实|行为).*?证据(材料)?(在案|予以)?(证明|佐证)?(在案)?((,|,)足以认定。)?|' \
                         r'上述.*?事实*等证据证明|上述违法事实有.*?等证据在案证明,足以认定|.*行政处罚的依据(和|及)决定|.*处罚依据及处罚决定|' \
                         r'依据.*?第.*?条规定,我局拟对你公司处1万元罚款的行政处罚。|' \
                         r'上述行为分别违反了《中华人民共和国保险法》一百二十二条和一百零六条的相关规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_compiler = re.compile(
                litigant + r'([\s\S]*?)' +
                r'(根据《中华人民共和国保险法》第一百六十条规定,决定给予你支行如下行政处罚:|'
                r'你.*?上述行为违反了.*?第.*?条的相关规定。|'
                r'依据.*?第.*?条的?规定,现给予你.*?的行政处罚。|'
                r'依据.*?第.*?条规定,我局拟给予你.*?的行政处罚。|'
                r'依据.*?第.*?条规定,现责令你公司改正,给予你.*?的行政处罚。|'
                r'上述事实有(以下|如下)证据证明)')
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(你[^,。,;\n]*?未[^,。,;\n]*?(申请)?听证(申请)?,)?[^,。,;\n]*?未?提出陈述申辩意见|' \
                               r'[^,。,;\n]*?向我局(报送|递交)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:|我局已于.*?向.*?送达了.*?在规定期限内未(再)?提出申辩意见。|' \
                               r'我局已于.*?向.*?送达了|我局已于.*?向.*?送达了.*?在规定期限内.*?未提出申辩意见。)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'我局经审核后|' \
                               r'我局不予采纳|三、(行政)?处罚的履行方式和期限|经审核|' \
                               r'根据申辩意见和崇明县人民法院刑事判决书|经复核)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') + \
                                       r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                   r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                   r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                   r'因此.*?我局.*?不予采纳。|我局调整了原定的处罚决定。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'((综上,我局(决定)?.*作出如下处罚:|我局决定.*作出如下处罚:|根据.*?第.*?条的?规定,决定|根据.*?第.*?条的?相关规定,决定|' \
                                       r'依据.*?第.*?条的?规定,现|依据.*?第.*?条的?规定,我局)' \
                                       r'([\s\S]*?))' \
                                       r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|' \
                                       r'你公司如不服本处罚决定|请你.*?在接到本处罚决定书之日|如不服本处罚决定|请你公司在接到本处罚决定书之日|' \
                                       r'请.*?在接到本处罚决定书之日|你.*?应当在接到本处罚决定书之日|\n.*?处罚的履行方式和期限|' \
                                       r'\n.*?应在收到本决定书之日|我局已于.*?送达了)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        if punishment_decision_compiler.search(content_text):
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(1).strip()
        else:
            punishment_decision_text_str = r'(行政处罚的依据和决定|行政处罚的依据及决定|处罚依据及处罚决定)' \
                                           r'([\s\S]*?)' \
                                           r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|' \
                                           r'你公司如不服本处罚决定|请你.*?在接到本处罚决定书之日|如不服本处罚决定|请你公司在接到本处罚决定书之日|' \
                                           r'请.*?在接到本处罚决定书之日|我局已于.*?送达了|\n.*?应在收到本决定书之日|' \
                                           r'三、不服本行政处罚决定、申请行政复议或者提起行政诉讼的途径和期限|三、行政处罚的履行方式和期限|' \
                                           r'三、处罚的履行方式和期限 )'
            punishment_decision_compiler = re.compile(
                punishment_decision_text_str, re.MULTILINE)
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(2).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)负有直接责任',
            r'你公司聘任不具有任职资格的人员,违反了《中华人民共和国保险法》(2015年修正)第一百二十一条的规定',
            r'华康上分变更营业场所未按规定报告,违反了中国保监会《保险专业代理机构监管规定》(2015年修订)第十四条的规定',
            r'你公司未按规定妥善保管业务档案,违反了中国保监会《保险专业代理机构监管规定》(2015年修订)第五十七条的规定',
            r'你公司2008年1-9月为保险公司代开保险中介服务统一发票累计80.25万元,占总业务收入的14.3%,违反了《保险代理机构管理规定》第一百三十六条的规定',
            r'你公司2007年度从事保险代理业务过程中,未建立规范完整的业务档案并对保单、投保单等单证进行复印留存,违反了《保险代理机构管理规定》第九十六条的规定',
            r'你公司通过要求保险公司开具费率为0.3%的保单,实际按照0.1%与投保人结算保费的方式给予投保人保险合同以外的利益,违法了《保险代理机构管理规定》第一百零二条的规定',
            r'该公司通过要求保险公司开具费率为0.3%的保单,实际按照0.1%与投保人结算保费的方式给予投保人保险合同以外的利益,违反了《保险代理机构管理规定》第一百零二条的规定',
            r'你公司于2007年10月至2007年12月期间,私自印刷瑞福德健康保险股份有限公司10天期的公交意外险保单41500张,并分散到各网点销售,违反了《中华人民共和国保险法》第一百四十条的规定',
            r'你于2007年10月至2007年12月在华顺保险代理有限公司担任总经理期间,私自印刷瑞福德健康保险股份有限公司10天期的公交意外险保单41500张,'
            r'并分散到各网点销售,违反了《保险代理机构管理规定》第一百零一条的规定',
            r'海发代理违反了《保险法》第一百二十一条、《保险专业代理机构监管规定》第三十三条、《保险法》第一百三十一条的规定',
            r'2008年度你公司共以上述名义向投保人支付.*?违反了《保险代理机构管理规定》第一百零二条的规定',
            r'你公司在2008年度为平安财产保险股份有限公司上海分公司代理学平险业务过程中,私自印刷保险凭证,签发所谓保险协议,私自扩展保险责任期限,侵占、截留保险赔款,违反了《中华人民共和国保险法》第一百三十一条的规定',
            r'你公司2008年.*?违反了《保险经纪机构管理规定》第一百二十八条规定',
            r'上述行为分别违反了《中华人民共和国保险法》一百二十二条和一百零六条的相关规定',
            r'你公司违反了《保险法》第一百二十一条、《保险专业代理机构监管规定》第三十三条、《保险法》第一百三十一条的规定,'
            r'根据《保险法》第一百六十九条 、《保险专业代理机构监管规定》第八十八条、《保险法》第一百六十六条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            '[。\n;]' + '(' + punishment_basis_str + ')' +
            r'.(\n?依据|\n?根据|\n?鉴于|\n?应?按照|\n?决定吊销你公司的)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○O]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '上海银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('上海保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('上海保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('上海保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #12
0
ファイル: xiamen.py プロジェクト: wagaman/jgcf
def xiamen_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '厦门保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('厦门保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(
            r'((厦保监[罚处]|厦银保监((筹))?罚决字).\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'近期,我局对.*一案进行了调查、审理|'
                r'你在.*?期间|'
                r'我局于.*?对.*?进行了现场检查,查明|'
                r'你公司在2009年协助天安保险股份有限公司厦门分公司思明营销服务部虚构保险中介业务套取费用|'
                r'你公司在\n2006\n年7-12月业务经营过程中,违反了《保险法》第一百二十二条的规定)')
            litigant = litigant_compiler.search(content_text).group(1).replace(
                '行政处罚决定书', '').strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'近期,我局对.*一案进行了调查、审理|'
                r'你在.*?期间|我局于.*?对.*?进行了现场检查,查明|'
                r'你公司在2009年协助天安保险股份有限公司厦门分公司思明营销服务部虚构保险中介业务套取费用|'
                r'你公司在\n2006\n年7-12月业务经营过程中,违反了《保险法》第一百二十二条的规定|'
                r'我局在对[\s\S]*?现场检查|'
                r'你公司在参与中国农业银行厦门市分行“\n2007\n年度保险项目招标”过程中|'
                r'根据中国保监会《关于做好\n2006\n年全国财产保险专项现场检查工作的通知》|'
                r'你公司于\n2006\n年8月11日|'
                r'你于\n2006\n年8月12日上午\n在厦门广播电视大学|'
                r'你公司未经批准在厦设立出单点,违反了《保险法》第八十条的规定|'
                r'你公司于2005年7月至2005年11月期间未经批准在厦门市金榜路凯旋广场六楼设立出单点,违反了《保险法》第八十条的规定)'
            )
            litigant = litigant_compiler.search(content_text).group(1).replace(
                '行政处罚听证权利告知书', '').replace('行政处罚事先告知书', '').replace(
                    '行政处罚决定书', '').replace('中国保监会厦门监管局',
                                           '').replace('中国保监会厦门监管局行政处罚事先告知书',
                                                       '').strip()

        truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:|现场检查,查明|' \
                         r'现场检查中发现,)' \
                         r'([\s\S]*?)' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'以上事实,有现场检查事实确认书、电销中心旧址和新\n址租赁合同、电销业务清单、中国保监会厦门监管局现场勘验笔录、调查笔录等证据在案证明,足以认定。|' \
                         r'根据《保险销售从业人员监管办法》第三十四条规定|综上,我局决定|' \
                         r',该行为违反了《保险营销员管理规定》第五十二条的规定|' \
                         r'你的行为违反了《保险营销员管理规定》第三十六条的规定|' \
                         r',违反了《保险法》第一百二十二条、《保险公司管理规定》第九十五条的规定|' \
                         r',违反了《保险法》第一百二十二条的规定|' \
                         r'依据《保险代理机构管理规定》第一百三十六条规定|' \
                         r',依据《保险统计管理暂行规定》第三十八条规定|' \
                         r'依据《保险统计管理暂行规定》第三十八条规定,我局拟对你公司作出警告的行政处罚。|' \
                         r',依据《保险法》第一百四十五条规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r',违反了《人身保险新型产品信息披露管理办法》第.*?条的规定|' \
                                        r'根据《保险营销员管理规定》、《厦门市保险代理人资格考试违规处理办法》|' \
                                        r'根据.*?第.*?条.*?规定|' \
                                        r'依据《保险法》第一百四十七条的规定,我局拟对你公司作出罚款10万元的行政处罚|' \
                                        r'依据《保险法》第一百四十七条的规定,我局拟责令你公司改正上述违规行为,处以罚款10万元的行政处罚。|' \
                                        r'依据《保险代理机构管理规定》第一百三十六条规定|' \
                                        r',依据《保险法》第一百三十九条及《保险公司管理规定》第九十九条规定|' \
                                        r'依据《保险法》第一百三十九条、《保险公司管理规定》第九十九条规定|' \
                                        r',综合考虑公司积极配合检查并主动进行整改|' \
                                        r'依据《保险法》第一百三十九条、《中华人民共和国行政处罚法》第二十七条的规定|' \
                                        r',鉴于情节较轻,依据《保险法》第一百三十九条第二款及《保险公司管理规定》第九十九条规定|' \
                                        r'依据《保险公司管理规定》第九十九条规定,我局拟对你公司作出警告的行政处罚|' \
                                        r'依据《保险营销员管理规定》第七章第五十二条规定,拟对你予以警告处分,并处叁仟元罚款)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                     r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                     r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'(可在收到本告知书之日起10日内到我局(厦门市鹭江道98号建行大厦39层)进行陈述和申辩。逾期视为放弃陈述权和申辩权。|' \
                                   r'可以在收到本告知书之日起10日内向我局或中国保监会提出书面的陈述、申辩意见。逾期视为放弃陈述或申辩的权利。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|综上,我局做出如下处罚:|' \
                                       r'根据《保险营销员管理规定》、《厦门市保险代理人资格考试违规处理办法》|我局决定)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|\n.{4}年.*?月.*?日|联系部门:厦门保监局|' \
                                       r'逾期视为放弃陈述权和申辩权)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;\s]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'中国人寿财产保险股份有限公司厦门市分公司上述行文违反了《中华人民共和国保险法》(2015年修正)第八十六条',
            r'鉴于你作为该公司的主要负责人,对上述违规行为负有责任',
            r'经查,你公司存在财务数据不真实,违反了《保险法》第一百二十二条的规定',
            r'经查,你公司违反了国家税务总局、中国保险监督管理委员会《关于规范保险中介服务发票有关问题的通知》(国税发\[\n2004\n\]51号)中第二条的规定',
            r'你公司在\n2006\n年7-12月业务经营过程中,违反了《保险法》第一百二十二条的规定',
            r'我局在对你公司的保险中介业务现场检查中发现,你公司\n违反了《保险代理机构管理规定》第三十九条、第五十六条及国家税务总局、中国保险监督管理委员会《关于规范保险中介服务发票有关问题的通知》(国税发\[\n2004\n\]51号)中第二条的规定',
            r'经查,你公司\n违反了《保险法》第一百零六条规定',
            r'你公司在参与中国农业银行厦门市分行“\n2007\n年度保险项目招标”过程中,违反了《保险法》第一百零六条的规定',
            r'经查,你公司\n违反了《保险法》第一百零六条的规定',
            r'经查,你公司未按照相关规定对公司员工王少伟发放《执业证书》,违反了《保险代理机构管理规定》第五十六条的规定',
            r'我局在对你公司的保险中介业务现场检查中发现,你公司\n存在在营业场所外另设代理网点开展代理业务等\n问题,违反了《保险兼业代理管理暂行办法》第二十一条的规定',
            r'我局在对厦门祥安保险代理有限公司的保险中介业务现场检查中发现,违反了《保险代理机构管理规定》第九十一条的规定',
            r'我局在对你公司的保险中介业务现场检查中发现,你公司违反了《保险代理机构管理规定》第九十一条的规定',
            r'经查,你公司\n违反了《保险法》第一百二十二条和《保险统计管理暂行规定》第二十四条、第二十五条的规定',
            r'我局在对中国人民财产保险股份有限公司厦门市分公司的保险统计现场检查中发现,你公司在\n2005\n年的业务经营过程中,违反了《保险法》第一百二十二条和《保险统计管理暂行规定》第二十四条、第二十五条的规定',
            r'我局在对中国人民财产保险股份有限公司厦门市分公司的保险统计现场检查中发现,'
            r'你公司在\n2005\n年全年和\n2006\n年1季度的业务经营过程中,违反了《保险法》第一百二十二条和《保险统计管理暂行规定》第二十四条、第二十五条的规定',
            r'经查,你公司违反了《保险法》第一百零六条、第一百二十二条、《保险公司管理规定》第九十五条的规定',
            r'你公司于\n2006\n年8月11日\n在翔安区公务用车统一保险招标竞争性谈判项目中,违反了《保险法》第一百零六条、第一百二十二条,《保险公司管理规定》第九十五条的规定',
            r'你于\n2006\n年8月12日上午\n在厦门广播电视大学举行的保险代理从业人员基本资格电子化考试中代替陈亚勉参加考试,该行为违反了《保险营销员管理规定》',
            r'经查,你公司存在下列未经批准设立出单点并在出单点接受投保、开展业务、打印保单等变相设立分支机构的行为,\n违反了《保险法》第八十条的规定',
            r'你公司未经批准在厦设立出单点,违反了《保险法》第八十条的规定',
            r'你公司于2005年7月至2005年11月期间未经批准在厦门市金榜路凯旋广场六楼设立出单点,违反了《保险法》第八十条的规定',
            r'经查,你在担任厦门祥安保险代理有限公司总经理期间,该公司违反了《保险代理机构管理规定》第九十一条的规定',
            r'经查,你公司\n违反了《保险法》第一百零六条的规定,综合考虑公司积极配合检查并主动进行整改'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            '.(\n?依据|\n?根据|\n?鉴于|\n?我局决定)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '厦门银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('厦门保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('厦门保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('厦门保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #13
0
ファイル: jiangsu.py プロジェクト: wagaman/jgcf
def jiangsu_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '江苏保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('江苏保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(
            table_content.find_all('tr')[3]).replace('(2015\n年修订)',
                                                     '(2015年修订)')
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(
            r'((苏保监罚|苏银保监罚决字).\n?\d{4}\n?.\n?\d+\n?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
        else:
            document_code = ''

        litigant_compiler = re.compile(
            document_code.replace(r'[', r'\[').replace(r']', r'\]') +
            r'\n([\s\S]*?)\n' + r'(依据有关法律规定|依据.*?的有关规定|经查,|经查,|经检查|'
            r'2015年5月,大童保险销售服务有限公司南通营业部|'
            r'根据《农业保险条例》第十五条第三款的规定|'
            r'你公司存在给予投保人保险合同约定以外其他利益的行为|'
            r'2011年,你公司赔案号为605012011320000000259等89笔赔案|'
            r'2009\n年\n2\n月至\n2010\n年\n8\n月期间|'
            r'2007\n年\n12\n月\n19\n至\n20\n日|2007\n年\n11\n月\n13\n日|'
            r'2009年11月26-27日|2008年6月6日—8月6日|2008年7月22—23日|'
            r'2007年.*?(以来|期间)|2008年4月江苏保监局对你公司现场检查|'
            r'在你任.*?期间|2007年,你单位采取批单注销保单和批减保额、保费的方式|'
            r'2007\n年\n4\n月以来|2007\n年\n6\n月\n20\n日|'
            r'2006年4月17日)')
        litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|公司存在以下问题:|存在以下违规问题:|2007年.*?以来|2007年.*?期间|' \
                         r'南京市秦淮区中山东路300号2幢1601室|主要负责人:孙伟群|主要负责人:韩安萍|主要负责人:陆刚|地址:泰州市江洲南路117号|' \
                         r'单位地址:泰州市江洲南路117号|你单位在经营中存在以下违法行为:|我局发现|本案现已审理终结。)' \
                         r'([\s\S]*?)' \
                         r'(上述事实(,|,)?有.*?等证据证明(,|,|。)(足以认定。)?|' \
                         r'上述行为违反了《保险代理机构管理规定》第六十三条的规定|' \
                         r'[^,。,;\n]*?上述.*?(违法|事实)?(行为|问题).*?违反了.*?第.*?条.*?的?规定|上述保单出具批单、批注或补充协议属于该公司权限,该公司应对上述行为负责。|' \
                         r'[^,。,;\n]*?上述违法行为(,|,)我局决定对.*?作出以下行政处罚:|' \
                         r'针对你在未取得执业证书的情况从事保险销售的行为|' \
                         r'2013年8月至11月,江苏太平先后与江苏中诚保险销售有限公司和江苏华邦保险销售有限公司签订代理协议|' \
                         r'针对.*?上述违法行为.{1}我局决定对.*?作出(如下|下列)(行政)?处罚:|' \
                         r'你公司的上述行为《中华人民共和国保险法》(以下简称《保险法》)第一百三十一条第(八)项的规定|' \
                         r'根据《保险销售从业人员监管办法》第三十一条的规定|上述行为构成了.*?第.*?条规定的违规行为|' \
                         r'此行为构成了《保险营销员管理规定》第五十二条规定的违规行为|该行为违反了《保险公司管理规定》第六十二条和第六十三条的规定|' \
                         r'依据.*?第.*?规定|[^,。,;\n]*?(行为|问题)[^。;\n]*?违反了.*?第[\s\S]*?条.*?的?规定)'
        truth_compiler = re.compile(truth_text_str)
        truth = truth_compiler.search(content_text).group(2).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|当事人[^,。,;\n]*?未?提出陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:|' \
                               r'你公司可在收到本告知书之日起10日内到我局进行陈述和申辩。|' \
                               r'你未?提出陈述申辩)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'我局经过?复核认为|' \
                               r'逾期视为放弃陈述权和申辩权。|' \
                               r'经对你公司陈述申辩意见进行复核,我局认为|' \
                               r'经复核你的陈述申辩意见和案卷材料,我局认为|' \
                               r'我局认为,对你的调查笔录|' \
                               r'我局复核认为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                          r'不予采纳。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense or '你公司可在收到本告知书之日起10日内到我局进行陈述和申辩。' in defense:
                        defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据)[^。;\n]*?第[^。;\n]*?条[^。;\n]*?(规定)?.?(我局)?' \
                                       r'(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'根据《保险法》第一百七十一的规定,我局决定|依据《保险公司管理规定》第六十九的规定,我局责令|' \
                                       r'根据《中华人民共和国行政许可法》第七十八的规定,我局决定|' \
                                       r'根据《中华人民共和国保险法》一百七十三条的规定,我局决定|' \
                                       r'根据《中华人民共和国保险法》第一百六十二条、第一百七十二条和《中华人民共和国行政处罚法》第二十七条的规定\n,\n我局责令|' \
                                       r'根据《中华人民共和国保险法》第一百六十二的规定,我局责令|' \
                                       r'根据有关证据及听证会情况,我局决定如下:|' \
                                       r'根据该条(规定)?,我局|按照《行政处罚法》第二十七条的规定依法减轻行政处罚,我局决定|' \
                                       r'根据《中华人民共和国保险法》一百五十条之规定,我局决定|' \
                                       r'依据《保险代理机构管理规定》第\n129\n条、第\n132\n条、第\n138\n条、第\n140\n条、第\n142\n条和第\n143\n条的规定)' \
                                       r'([\s\S]*?))' \
                                       r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|你公司如不服本处罚决定|' \
                                       r'请在接到本处罚决定书之日|如不服本处罚决定|因你公司现已搬离南京市鼓楼区管家桥85号华荣大厦410室)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)(违反|构成).*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'你公司的上述行为《中华人民共和国保险法》(以下简称《保险法》)第一百三十一条第(八)项的规定',
            r'上述行为违反了《中华人民共和国保险法》一百三十六条的规定',
            r'上述行为构成了《保险专业代理机构监管规定》第八十七条规定的违规行为。你作为该公司的董事长兼总经理,对上述违规行为直接负责',
            r'上述行为构成了《保险专业代理机构监管规定》第八十七条规定的违规行为',
            r'此行为构成了《保险营销员管理规定》第五十二条规定的违规行为',
            r'上述事实行为违反了《保险代理机构管理规定》第\n21\n条、第\n41\n条、第\n56\n条、'
            r'第\n91\n条、第\n96\n条、第\n101\n条、第\n104\n条、第\n107\n条和第\n108\n条的规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            '[。\n;]' + '(' + punishment_basis_str + ')' +
            r'.(\n?(应当?)?依据|\n?(应当)?根据|\n?鉴于|\n?应你的要求|\n?.*?陈述申辩)',
            re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '江苏银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('江苏保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('江苏保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('江苏保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #14
0
def dalian_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '大连保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('大连保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚明细' in title or '行政处罚事项' in title:
            sub_table_content = table_content.find_all('tr')[3].find_all('table')[0]
            result_map_list = []
            if title == '大连保监局2011年8月行政处罚事项':
                for tr in sub_table_content.find_all('tr'):
                    if '行政处罚公开信息' not in tr.text and '行政处罚事项' not in tr.text and '处罚决定文号' not in tr.text and \
                            len(tr.find_all('td')) > 1 and tr.find_all('td')[0].text != tr.find_all('td')[1].text:
                        real_title = '大连保监局行政处罚决定书(' + tr.find_all('td')[0].text + ')'
                        publish_date_text = tr.find_all('td')[2].text

                        real_publish_date = publish_date_text.split('-')[0] + '年' + \
                                            publish_date_text.split('-')[1] + '月' + \
                                            publish_date_text.split('-')[2] + '日'

                        result_map = {
                            'announcementTitle': real_title,
                            'announcementOrg': '大连保监局',
                            'announcementDate': real_publish_date,
                            'announcementCode': tr.find_all('td')[0].text,
                            'facts': tr.find_all('td')[1].text + tr.find_all('td')[6].text,
                            'defenseOpinion': '',
                            'defenseResponse': '',
                            'litigant': tr.find_all('td')[1].text,
                            'punishmentBasement': tr.find_all('td')[1].text + '上述行为违反了' + tr.find_all('td')[4].text,
                            'punishmentDecision': '依据' + tr.find_all('td')[5].text + ',' +
                                                  '我局对' + tr.find_all('td')[1].text +
                                                  '作出以下处罚:' + tr.find_all('td')[3].text,
                            'type': '行政处罚决定',
                            'oss_file_id': file_id,
                            'status': 'not checked'

                        }
                        logger.info(result_map)
                        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                            db.announcement.insert_one(result_map)
                            logger.info('大连保监局 数据解析 ' + ' -- 数据导入完成')
                        else:
                            logger.info('大连保监局 数据解析 ' + ' -- 数据已经存在')
                        result_map_list.append(result_map)
                if len(result_map_list) > 0:
                    db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                    logger.info('大连保监局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.warning('大连保监局 数据解析 ' + ' -- 没有数据')
            else:
                for tr in sub_table_content.find_all('tr'):
                    if '行政处罚公开信息' not in tr.text and '行政处罚事项' not in tr.text and '处罚决定文号' not in tr.text and \
                            len(tr.find_all('td')) > 1 and tr.find_all('td')[0].text != tr.find_all('td')[1].text:
                        real_title = '大连银保监局行政处罚决定书(' + tr.find_all('td')[0].text + ')'
                        publish_date_text = table_content.find_all('tr')[1].text
                        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                            publish_date = re.findall(r'.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
                            m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                                         publish_date)
                            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(
                                cn2dig(m.group(3))) + '日'
                        else:
                            publish_date_text = table_content.find_all('tr')[1].text
                            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                            real_publish_date = publish_date.split('-')[0] + '年' + str(
                                int(publish_date.split('-')[1])) + '月' + str(
                                int(publish_date.split('-')[2])) + '日'

                        result_map = {
                            'announcementTitle': real_title,
                            'announcementOrg': '大连银保监局',
                            'announcementDate': real_publish_date,
                            'announcementCode': tr.find_all('td')[0].text,
                            'facts': tr.find_all('td')[1].text + tr.find_all('td')[5].text,
                            'defenseOpinion': '',
                            'defenseResponse': '',
                            'litigant': tr.find_all('td')[1].text,
                            'punishmentBasement': tr.find_all('td')[1].text + '上述行为违反了' + tr.find_all('td')[3].text,
                            'punishmentDecision': '依据' + tr.find_all('td')[4].text + ',' + '我局对' + tr.find_all('td')[
                                1].text + '作出以下处罚:' + tr.find_all('td')[2].text,
                            'type': '行政处罚决定',
                            'oss_file_id': file_id,
                            'status': 'not checked'
                        }
                        logger.info(result_map)
                        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                            db.announcement.insert_one(result_map)
                            logger.info('大连保监局 数据解析 ' + ' -- 数据导入完成')
                        else:
                            logger.info('大连保监局 数据解析 ' + ' -- 数据已经存在')
                        result_map_list.append(result_map)
                if len(result_map_list) > 0:
                    db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                    logger.info('大连保监局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.warning('大连保监局 数据解析 ' + ' -- 没有数据')
        else:
            document_code_compiler = re.compile(r'((连保监罚(告)?|大银保监罚决字).\d{4}.\d+号|连保监罚\d{4}.\d+.号)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|经调查|'
                                        r'中国人民财产保险股份有限公司大连市|'
                                        r'你公司于2010年10 月31日聘任朱利为国际保险部总经理|'
                                        r'你公司于2010年8 月下旬|'
                                        r'.*?(现场检查|综合性检查|案件调查|举报信反映)|'
                                        r'你公司于.*?期间|'
                                        r'近日,我局在处理投诉人郑金涛投诉你公司委托非法)')
                litigant = litigant_compiler.search(content_text).group(1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|经调查|'
                                                                  r'中国人民财产保险股份有限公司大连市|'
                                                                  r'你公司于2010年10 月31日聘任朱利为国际保险部总经理|'
                                                                  r'你公司于2010年8 月下旬|'
                                                                  r'.*?(现场检查|综合性检查|案件调查|举报信反映)|'
                                                                  r'你公司于.*?期间|近日,我局在处理投诉人郑金涛投诉你公司委托非法)')
                litigant = litigant_compiler.search(content_text).group(1).strip()

            litigant = litigant.replace('行政处罚决定书', '').replace('行政处罚事先告知书', '').strip()

            truth_text_str = r'((经查|经检查|检查发现|抽查|经抽查|经查明|存在下列(违法)?违规行为)' \
                             r'([\s\S]*?))' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                             r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                             r'违反了.*?第.*?条|' \
                             r'二、处理意见|' \
                             r'违反了\n《保险法》第一百二十二条|' \
                             r'你公司的以上行为违反了《保险兼业代理管理暂行办法》第十三条|' \
                             r'根据《保险统计管理暂行规定》第三十八条的规定)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(1).strip()
            else:
                truth_text_str = litigant.replace(r'*', r'\*') \
                                 + r'([\s\S]*?)' \
                                   r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                   r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                   r'我局于2014年12月10日以当面送达的方式第一次向你送达了行政处罚事先告知书|' \
                                   r'你在收到行政处罚事先告知书后,在法定时限内提出了如下陈述申辩意见|' \
                                   r'依据.*?第.*?条)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?(行为|事实).*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                                   r'你在收到行政处罚事先告知书后,在法定时限内提出了如下陈述申辩意见|' \
                                   r'你向我局提出申辩意见)' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核(认为|决定)|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'经我局审核,决定|' \
                                   r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                   r'我局对陈述申辩意见进行了复核|' \
                                   r'经我局审核|' \
                                   r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                   r'经查,我局认为|' \
                                   r'依据现场检查及听证情况|' \
                                   r'我局.*?补充调查|' \
                                   r'经研究|我局认为)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0].strip()
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                              r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                              r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                              r'经查不能作为减轻处罚的依据。|申辩意见不予采纳。|该申辩意见不成立。))'
                    defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = '(可于2010年5月20日前到我局进行申辩,或于2010年5月20日前向我局提交书面的陈述书和申辩书。逾期视为放弃陈述和申辩。)'
                    defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据|依照)[^。;\n]*?第?.*?条.*?(规定)?.?' \
                                           r'(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对)|' \
                                           r'我局决定.*?作出(如下|以下)(行政)?处罚:|决定作出如下处罚|' \
                                           r'依据《中华人民共和国行政处罚法》第二十七条之规定、\n《中华人民共和国保险法》第一百六十二条、第一百七十二条之规定,我局决定|' \
                                           r'依据《行政处罚法》\n第二十七条、《保险法》第一百五十条规定,决定给予|' \
                                           r'依据《保险\n公司管理规定》第九十九条的规定,决定给予)' \
                                           r'([\s\S]*?))' \
                                           r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                           r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人如对本处罚决定不服|' \
                                           r'请在接到本处罚决定之日起15日|如你公司对我局认定的违法事实)'

            punishment_decision_compiler = re.compile(punishment_decision_text_str)
            punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
                r'我局认为,中人保险经纪有限公司大连分公司违反了《中华人民共和国保险法》(2009年2月28日修订)第一百三十一条第(八)的规定',
                r'我局认为,中国大地财产保险股份有限公司大连市旅顺支公司违反了《中华人民共和国保险法》(2009年2月28日修订)第八十六条的规定',
                r'经查,你机构在内控制度及执行方面、业务合规性方面存在违规行为,\n违反了《保险公司管理规定》第五十六条、第六十七条的规定',
                r'2014年10月,我局对你公司开展了现场检查,你公司以营业场所租赁他用,业务台账、财务账册、原始单证无法找到为由,'
                r'拒绝向我局提供检查资料,导致我局无法正常开展现场检查工作,妨碍了监管部门依法监督检查,违反了《保险法》第一百五十六条的规定,属情节严重',
                r'2014年10月,我局对大连久久保险代理有限公司开展了现场检查,大连久久保险代理有限公司以营业场所租赁他用,业务台账、财务账册、原始单证无法找到为由,'
                r'拒绝向我局提供检查资料,导致我局无法正常开展现场检查工作,妨碍了监管部门依法监督检查,违反了《保险法》第一百五十六条的规定'
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(r'[。\n;]' + '(' + punishment_basis_str + ')' +
                                                   '.(\n?依据|\n?根据|\n?鉴于|\n?属|\n?上述违法事实|\n?依照)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(content_text)
            punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
                replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
                m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
                real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '大连银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('大连保监局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('大连保监局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('大连保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #15
0
def hebei_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '河北保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('河北保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(
            r'((保监冀罚|冀保监罚|冀银保监筹保罚决字)\s*?\n?.\n?\s*?\d{4}\n?.\n?\d+\n?\s*?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' +
                r'(经查|经检查|依据.*?有关规定|抽查|经抽查|.*?(现场检查|信访检查|专项检查))')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(
                r'^(中国银保监会河北监管局筹备组\n行政处罚决定书|河北保监局行政处罚决定书|中国保监会河北监管局行政处罚决定书)?([\s\S]*?)\n'
                + r'(经查|经检查|依据.*?有关规定|抽查|经抽查|.*?(现场检查|信访检查|专项检查))')
            litigant = litigant_compiler.search(content_text).group(2).strip()

        litigant = litigant.replace('中国保监会河北监管局行政处罚决定书', '').strip()

        truth_text_str = r'(经查,.*?存在以下违法行为:\n|经查,.*存在下列违法违规行为:\n|经抽查发现,|经查。你公司存在下列违法行为:|' \
                         r'经查,.*存在下列违法行为:\n?|经查,.*存在下列违规行为:\n?|经查,你.*?存在下列违法行为:\n?|经查,你存在下列违法\n行为:\n?|' \
                         r'经查,你公司违法违规行为)' \
                         r'([\s\S]*?)' \
                         r'(上述(违法)?事实,有.*?等证据(在案)?证明(在案)?(,|,)足以认定。|上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                         r'该违法事实,有.*?等证据在案证明,足以认定|' \
                         r'该公司上述行为违反了《保险法》第.*?条|' \
                         r'综上,决定给予你公司.*?的行政处罚|' \
                         r'(上述|以上)(违法)?(事实(行为)?|行为)(分别)?违反了.*?第.*?条(的)?(规定)?|' \
                         r'依据《保险营销员管理规定》第.*条规定|' \
                         r'我局认为,.*?的规定|上述事实行为违反了\n《保险法》(\n2002\n年)第.*?条\n的规定|' \
                         r'上述事实行为违反了《中华人民共和国保险法》(\n2002\n年修正)第一百二十二条规定|' \
                         r'违反了《保险法》第一百二十二条、一百零七条规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = r'(经查,|经查,)' \
                             r'([\s\S]*?)' \
                             r'(上述(违法)?事实,有.*?等证据(在案)?证明(在案)?(,|,)足以认定。|上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                             r'该违法事实,有.*?等证据在案证明,足以认定|' \
                             r'该公司上述行为违反了《保险法》第.*?条|' \
                             r'综上,决定给予你公司.*?的行政处罚|' \
                             r'(上述|以上)(违法)?(事实(行为)?|行为)(分别)?违反了.*?第.*?条(的)?(规定)?|' \
                             r'依据《保险营销员管理规定》第.*条规定|' \
                             r'我局认为,.*?的规定|上述事实行为违反了\n《保险法》(\n2002\n年)第.*?条\n的规定)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(2).strip()
            else:
                truth_text_str = r'(' + litigant + r'\n)' \
                                                   r'([\s\S]*?)' \
                                                   r'(上述(违法)?事实,有.*?等证据(在案)?证明(在案)?(,|,)足以认定。|' \
                                                   r'上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                                                   r'该违法事实,有.*?等证据在案证明,足以认定|' \
                                                   r'该公司上述行为违反了《保险法》第.*?条|' \
                                                   r'综上,决定给予你公司.*?的行政处罚|' \
                                                   r'(上述|以上)(违法)?(事实(行为)?|行为)(分别)?违反了.*?第.*?条(的)?(规定)?|' \
                                                   r'依据《保险营销员管理规定》第.*条规定|' \
                                                   r'我局认为,.*?的规定|上述事实行为违反了\n《保险法》(\n2002\n年)第.*?条\n的规定)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(2).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|当事人[^,。,;\n]*?未提出陈述申辩意见|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:|当事人提出陈述申辩|' \
                               r'[^,。,;\n]*?提出[^,。,;\n]*?陈述申辩意见)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'我局对.*?审核|' \
                               r'我局审核后认为)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                         r'对[^,。,;\n]*?申辩意见(不予|予以|不)采纳|因此.*?申辩理由.*?成立。|' \
                                                         r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                         r'综上,我局对.*?陈述申辩意见不予采纳|决定对上述三人的陈述申辩意见不予采纳))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                defense_response = defense_response_compiler.search(
                    content_text).group(1).strip()
            else:
                defense = re.search(
                    r'(当事人盛衡公估提出陈述申辩,我局对陈述申辩意见进行了审核,并依法重新制发了《行政处罚事先告知书》。法定期限内,当事人未再提出陈述申辩。)',
                    content_text).group(1).strip()
                defense_response = '本案现已审理终结。'
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据)[^。;]*?第[^。;]*?条[^。;]*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'(综上,)?我局决定.*?作出(如下|以下)(行政)?处罚|' \
                                       r'依据《中华人民共和\n国保险法》(2009年修订)第一百七十二条的规定,责令改正,决定给予)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人如对本处罚决定不服|' \
                                       r'.*?如不服本处罚决定|请在接到本处罚决定书之日|.*?应在收到本处罚决定书之日)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'永安财险石家庄中支达成赔偿协议后支付赔款时间超过10日,违反了《中华人民共和国保险法》(2015年修正)第二十三条和第一百一十六条第(五)项的规定,且情节严重',
            r'永安财险石家庄中支列支劳务费贴补代理公司手续费,违反了《中华人民共和国保险法》(2015年修正)第八十六条的规定',
            r'华夏人寿河北分公司对保险产品的不确定利益承诺保证收益,违反了《中华人民共和国保险法》(2015年修正)第一百一十六条第(一)项的规定',
            r'农行中长街分理处代理销售的部分保险业务客户信息不真实、不完整,违反了《中华人民共和国保险法》(2015年修正)第八十六条和第一百三十二条的规定',
            r'信泰人寿邯郸中支理赔业务部分数据不真实,违反了《中华人民共和国保险法》(2015年修正)第八十六条的规定,且情节严重',
            r'信泰人寿邯郸中支财务、业务系统数据不真实,违反了《中华人民共和国保险法》(2015年修正)第八十六条的规定',
            r'信泰人寿邯郸中支部分业务客户信息不真实,违反了《中华人民共和国保险法》(2015年修正)第八十六条的规定',
            r'信泰人寿邯郸中支未按监管规定完成犹豫期内新单回访,违反了《人身保险新型产品信息披露管理办法》第十条的规定',
            r'上述事实行为违反了[\s\S]*?规定(.*?负有直接责任)?',
            r'我机关认为[\s\S]*(行为|代理保险业务)[\s\S]*?违\n?反[\s\S]*?规定',
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            '[。\n;]' + '(' + punishment_basis_str + ')' +
            r'.(\n?依据|\n?根据|\n?鉴于)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '河北银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('河北保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('河北保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('河北保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #16
0
ファイル: sichuan.py プロジェクト: wagaman/jgcf
def sichuan_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '四川保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if '行政处罚实施情况' in announcement_title:
            logger.warning(announcement_url + ' ' + announcement_title + ' 与监管处罚无关')
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'ignored'}})
            logger.info('四川保监局' + ' 无关数据' + ' -- 修改status完成')
            continue

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('四川保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚事项' in title or '行政处罚公开信息' in title:
            table_list = table_to_list(table_content.find_all('tr')[3].find_all('table')[-1])
            result_map_list = []
            for each_table_list in table_list:
                if each_table_list[0] == '序号':
                    continue
                result_map_list.append({
                    'announcementTitle': '四川银保监局行政处罚决定书(' + each_table_list[2] + ')',
                    'announcementOrg': '四川银保监局',
                    'announcementDate': format_date(each_table_list[1]),
                    'announcementCode': each_table_list[2],
                    'facts': each_table_list[4],
                    'defenseOpinion': '',
                    'defenseResponse': '',
                    'litigant': each_table_list[3],
                    'punishmentBasement': each_table_list[5],
                    'punishmentDecision': '依据' + each_table_list[6] + ',' + each_table_list[7],
                    'type': '行政处罚决定',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                })
            logger.info(result_map_list)
            if len(result_map_list) > 0:
                logger.info('四川保监局' + '解析 -- 一共有%d条数据' % len(result_map_list))
                db.announcement.insert_many(result_map_list)
                logger.info('四川保监局' + '解析 -- 数据导入完成')
                db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                logger.info('四川保监局' + '解析 -- 修改parsed完成')
            else:
                logger.warning('四川保监局' + '解析 -- 解析未能完成')
        else:
            if '处罚决定书送达公告' in title or '事先告知书送达公告' in title:
                document_code_compiler = re.compile(r'(川保监公告.\d{4}.\d+号)')
                document_code = document_code_compiler.search(title).group(1).strip()
                litigant_compiler = re.compile(r'^([\s\S]*?):\n' + '(经查|经检查|依据.*?有关规定)')
                litigant = litigant_compiler.search(content_text).group(1).replace('四川保监局行政处罚事先告知书送达公告', '').strip()
            else:
                document_code_compiler = re.compile(r'((川|宜宾)银?保监罚决?字?.\d{4}.\d+号)')
                if document_code_compiler.search(content_text):
                    document_code = document_code_compiler.search(content_text).group(1).strip()
                    litigant_compiler = re.compile(
                        document_code.replace(r'[', r'\[').replace(r']', r'\]') + r'\n([\s\S]*?)\n' +
                        r'(经查|经检查|依据.*?有关规定|'
                        r'.*?期间|经我局查实|'
                        r'.*?存在.*?违[法规]行为|'
                        r'.*?委托未取得合法资格的个人从事保险销售活动|'
                        r'.*?我局对.*?(开展|进行)了.*?现场检查|'
                        r'财政部驻四川财政监察专员办事处检查发现|'
                        r'根据举报,我局查实)')
                    litigant = litigant_compiler.search(content_text).group(1).strip()
                else:
                    if document_code_compiler.search(title):
                        document_code = document_code_compiler.search(title).group(1).strip()
                    else:
                        document_code = ''
                    litigant_compiler = re.compile(r'^([\s\S]*?)\n' +
                                                   r'(经查|经检查|依据.*?有关规定|.*?期间|.*?存在.*?违[法规]行为|'
                                                   r'.*?委托未取得合法资格的个人从事保险销售活动|经我局查实|'
                                                   r'.*?我局对.*?(开展|进行)了.*?现场检查|'
                                                   r'财政部驻四川财政监察专员办事处检查发现|'
                                                   r'根据举报,我局查实)')
                    litigant = litigant_compiler.search(content_text).group(1).strip()

            truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|检查发现:|现场检查。检查发现|我局查实|经我局查实,)' \
                             r'([\s\S]*?)' \
                             r'(上述(违法|违规)?(事实|行为)(及相关人员责任)?(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                             r'根据《中华人民共和国保险法》第一百七十一条的规定|当事人唐晓峰在申辩材料中辩称:|' \
                             r'中国平安财产保险股份有限公司成都市锦城支公司的上述违法行为中|' \
                             r'(该|你)公司.*?存在的.*?的.*?行为|上述行为违反了.*?第.*?条.*?规定|' \
                             r'2009年10月1日前经营活动中存在的上述违法行为,违反了《中华人民共和国保险法》(修订前)第122条的规定|' \
                             r'上述行为分别违反了《人身保险新型产品信息披露管理办法》(保监会令〔2009〕3号)第10条和第33条的规定|' \
                             r',违反了《中华人民共和国保险法》(2009年2月28日修订)第一百三十三条、《保险专业代理机构监管规定》第六十一条的规定|' \
                             r'你的行为违反了《中华人民共和国保险法》(2009年2月28日修订)第一百二十二条的规定|' \
                             r'分别违反了《保险专业代理机构监管规定》第四十九条、第六十一条和《中华人民共和国保险法》(2009年2月28日修订)第一百三十三条的规定|' \
                             r'上述行为分别违反了《中华人民共和国保险法》第116条第(八)款和《保险统计管理暂行规定》(保监会令〔2004〕11号)第25条的规定|' \
                             r'上述行为违反了《中华人民共和国保险法》第116条第(十\n三)项和《机动车交通事故责任强制保险条例》第10条的规定|' \
                             r',应该按照该法第一百七十三条予以处罚|' \
                             r'你公司的上述违法行为中,保费收入不真实、车辆使用费不真实的行为违反了《中华人民共和国保险法》(2009年2月28日修订)第八十六条的规定,应当按照该法第一百七十二条予以处罚|' \
                             r'上述行为分别违反了《中华人民共和国保险法》(2002年修正版)第122条、《中华人民共和国保险法》' \
                             r'(2009年修订版)第116条规定和《保险统计管理暂行规定》(保监会令(2004)11号)第25条规定|' \
                             r'上述行为违反了《中华人民共和国保险法》(修订前,下同)第106条的规定|' \
                             r'上述行为违反了原《保险法》第107条、第122条及《保险营销员管理规定》第43条的规定,新《保险法》第86条、第136条也作出了相应规定|' \
                             r'该行为违反了《保险代理机构管理规定》第2条的规定。依据《保险代理机构管理规定》第130条第一款的规定|' \
                             r',该行为违反《保险代理机构管理规定》第56条的规定|' \
                             r'上述行为违反了《中华人民共和国保险法》第122条的规定|' \
                             r'上述行为违反了《中华人民共和国保险法》第107条的规定|' \
                             r'依据《保险代理机构管理规定》第141条,我局决定|' \
                             r'上述行为违反了《中华人民共和国保险法》第132条|' \
                             r'上述行为违反了《中华人民共和国保险法》第80条规定)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(2).strip()
            else:
                truth_text_str = litigant + r'([\s\S]*?)' \
                                            r'(\n上述(违规|违法)?(事实|行为)(及相关人员责任)?(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                            r'上述行为分别违反了《保险营销员管理规定》第三十六条第(十八)项和第(二十一)项的规定|' \
                                            r'上述行为违反了《中华人民共和国保险法》(修订前,下同)第107条的规定|' \
                                            r'综上,决定对你公司处以罚款人民币壹万伍仟元(¥15,000.00)的行政处罚。)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中(辩)?称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                                   r'在规定的?期限内,[^,。,;\n]*?提交了(陈述申辩材料|陈述申辩书面材料|书面陈述申辩材料))' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核(认为|决定)|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'经我局审核,决定|' \
                                   r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                   r'我局对陈述申辩意见进行了复核|' \
                                   r'经我局审核|' \
                                   r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                   r'经查,我局认为|' \
                                   r'依据现场检查及听证情况|' \
                                   r'经复核)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0]
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                              r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                              r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                              r'不予处罚的情形。|足以认定其并非违法行为的直接责任人。|' \
                                                              r'我局对.*?请求不予采纳。))'
                    defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = r'(你享有陈述和申辩的权利,可在送达之日起10个工作日内将陈述和申辩的书面材料提交至中国保险监督管理委员会四川监管局。逾期视为放弃陈述权和申辩权。|' \
                                       r'在规定的?期限内.*?(未|没有)进行陈述和?申辩。|' \
                                       r'在规定的期限内.*?既未进行陈述和申辩,也未要求举行听证。)'
                    defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据|按照).*?第.*?条.*?规定,(我局决定)?|依据前述法律规定,我局决定|' \
                                           r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                           r'依据《中华人民共和国保险法》第172条、《保险营销员管理规定》第57条,我局决定|' \
                                           r'依据《保险营销员管理规定》第57条,我局决定|' \
                                           r'依据《中华人民共和国保险法》第147条和《行政处罚法》第27条,我局决定|' \
                                           r'依据《中华人民共和国保险法》第145条的规定,我局决定|' \
                                           r'依据《保险代理机构管理规定》第141条,我局决定|' \
                                           r'依据《中华人民共和国保险法》第145条和《保险代理机构管理规定》第138条的规定,我局决定|' \
                                           r'依据《中华人民共和国保险法》第145条,我局决定)' \
                                           r'([\s\S]*?))' \
                                           r'(\n.*?本处罚决定书之日|现依法向你公告送达上述决定,自公告之日起经过60日视为送达。|' \
                                           r'如不服本处罚决定|请严格按照《关于调整非税收入执行单位和管理办法的通知》(川保监发〔2007〕212号)规定)'
            punishment_decision_compiler = re.compile(punishment_decision_text_str, re.MULTILINE)
            punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
                r'我局认为,阳光人寿四川分公司利用保险代理人,从事以虚构保险中介业务方式套取费用等违法活动,违反了《保险法》第116条第(十)项的规定',
                r'我局认为,人保隆昌支公司故意编造未曾发生的保险事故、故意夸大已经发生的保险事故的损失程度进行虚假理赔,骗取保险金或者牟取其他不正当利益,违反了《保险法》第116条第(六)项的规定',
                r'经查,成都五丰保险代理有限公司存在编制并提供虚假的业务台帐的违法违规行为,违反了《中华人民共和国保险法》'
                r'(2009年2月28日修订)第一百三十三条、《保险专业代理机构监管规定》第六十一条的规定。你时任成都五丰保险代理有限公司总经理,系对该违法违规行为直接负责的主管人员',
                r'经查,成都五丰保险代理有限公司存在编制并提供虚假的业务台帐的违法违规行为,违反了《中华人民共和国保险法》'
                r'(2009年2月28日修订)第一百三十三条、《保险专业代理机构监管规定》第六十一条的规定。你时任成都五丰保险代理有限公司业务主任,系该违法违规行为的直接责任人员'
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(r'[。\n;]' + '(' + punishment_basis_str + ')' +
                                                   '.(\n?依据|\n?根据|\n?鉴于|\n?(应当)?按照)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(content_text)
            punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
                replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1]
                m = re.match("([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
                real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '四川银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find(
                    {'announcementTitle': result_map['announcementTitle'],
                     'oss_file_id': file_id,
                     'litigant': result_map['litigant']}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('四川保监局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('四川保监局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('四川保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #17
0
ファイル: ningbo.py プロジェクト: wagaman/jgcf
def ningbo_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '宁波保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('宁波保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((甬保监罚|甬银保监罚决字).\d{4}.\d+.*?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|'
                                    r'抽查|经抽查|经调查|'
                                    r'.*?(专项检查|现场检查|进行.*?调查))')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|经调查|.*?(专项检查|现场检查|进行.*?调查))')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'((经查|经检查发现)' \
                         r'([\s\S]*))' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为)(,|,)?(有|由)[^。;]*?等证\n?据(在案|予以)?(证明|证实)(,|,|。)(足以认定。)?|' \
                         r'(上述|以上).*?(事实|行为|事实行为)违反了)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        litigant = litigant.replace('宁波保监局行政处罚决定书', '').replace('甬\n', '').replace('、\n', '')

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'当事人提出了听证申请和陈述申辩意见|当事人岑国景提出了听证及陈述申辩意见|' \
                               r'你公司于2018年8月24日提出申辩。|' \
                               r'[^,。,;\n]*?辩称)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'我局依\n?法组\n?织了听证。|' \
                               r'我局认为|' \
                               r'对此,我局认为|' \
                               r'经核查)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                          r'我局依\n?法组\n?织了听证。|故不采纳该申辩意见。|申辩理由不成立。))'
                defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'(当事人未进行陈述申辩。|当事人未进行陈述申辩和听证。|当事人提出了陈述申辩意见。|' \
                                   r'当事人未陈述申辩,未要求听证。|当事人未陈述申辩。|当事人未陈述申辩,未提出听证申请。|' \
                                   r'当事人放弃陈述申辩和听证权利。|当事人未提\n?出陈\n?述\n?申辩\n?意见。|' \
                                   r'当事人提出了陈述\n?申辩意见。|当事人未在法定期限内提出陈述申辩意见。|' \
                                   r'当事人未在法定期限内提出陈述申辩意见和听证要求。|' \
                                   r'[^,。,;\n]*?未在规定期限内(提出|进行)陈述(或|和)申辩。|' \
                                   r'当事人未进行听证和陈述申辩。|' \
                                   r'当事人提交了陈述申辩材料,未提出听证申请。|' \
                                   r'当事人未提出听证申请,提交了陈述申辩材料。|' \
                                   r'当事人未进行陈述申辩,未提出听证申请。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据)\n?.*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局经复核认为|我局(决定)?.*?作出(如下|以下)(行政)?处罚)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人应在接到本处罚决定书之日|' \
                                       r'如不服从本处罚决定)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;:]*?)\n?([^\n。;:]*?)(问题|行\n?为|事项|情况|事实)([^。;]*?)违\n?反([^。]*?)第.*?条?.*?\n?.*?((的|之|等)(相关)?规定)?',
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(r'[。\n;:]' + '(' + punishment_basis_str + ')' +
                                               '.(\n?依据|\n?根\n?据|\n?鉴于|\n?公司在检查前自查|\n?由于)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
            replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '').replace(' ', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
            m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '宁波银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('宁波保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('宁波保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('宁波保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #18
0
ファイル: jiangxi.py プロジェクト: wagaman/jgcf
def jiangxi_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '江西保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'parsed': True
        }).count() >= 1:
            continue

        logger.info('江西保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '2008年1-5月行政处罚决定' in title or '2008年以前行政处罚决定' in title:
            rar_link = [
                urljoin(announcement_url, each_link.attrs['href'])
                for each_link in content_soup.find_all('a')
                if '.rar' in each_link.attrs['href']
            ][0]
            response = request_site_page(rar_link)
            with open('./test/tmp.rar', 'wb') as out_file:
                for chunk in response.iter_content(chunk_size=1024):
                    if chunk:
                        out_file.write(chunk)

            if not os.path.exists('./test/tmp'):
                os.mkdir('./test/tmp')
            patoolib.extract_archive('./test/tmp.rar', outdir='./test/tmp')

            doc_file_list = []
            for root, dirs, files in os.walk("./test/tmp", topdown=False):
                for name in files:
                    doc_file_list.append(os.path.join(root, name))

            for each_doc_file in doc_file_list:
                doc_title = re.split(r'[./]', each_doc_file)[-2]
                if not os.path.exists('./test/tmp/' + doc_title + '.docx'):
                    shell_str = config['soffice']['soffice_path'] + ' --headless --convert-to docx ' + \
                                each_doc_file + ' --outdir ./test/tmp'
                    process = subprocess.Popen(shell_str.replace(
                        r'(', r'\(').replace(r')', r'\)'),
                                               shell=True,
                                               stdout=subprocess.PIPE)
                    process.wait()

                with open('./test/tmp/' + doc_title + '.docx',
                          'rb') as docx_file:
                    docx_content = docx_file.read()

                if db.parsed_data.find({
                        'origin_url': announcement_url,
                        'oss_file_name': doc_title
                }).count() == 0:
                    oss_file_map = {
                        'origin_url': announcement_url,
                        'oss_file_origin_url': rar_link,
                        'origin_url_id': each_circ_data['_id'],
                        'oss_file_type': 'docx',
                        'oss_file_name': doc_title,
                        'oss_file_content': docx_content,
                        'parsed': False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(ali_bucket,
                                 str(file_id) + '/' + doc_title + '.docx',
                                 docx_content)
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                    file_id = db.parsed_data.find_one({
                        'origin_url':
                        announcement_url,
                        'oss_file_name':
                        doc_title
                    })['_id']

                doc = docx.Document('./test/tmp/' + doc_title + '.docx')
                full_text = []
                for para in doc.paragraphs:
                    full_text.append(para.text)
                content_text = '\n'.join(full_text)

                document_code_compiler = re.compile(
                    r'(赣银?保监罚\n?.*?\d+\n?\d+\n?.*?\n?\d+\n?号)')
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()

                real_title = '中国银保监会江西监管局行政处罚决定书(' + document_code + ')'

                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|依据.*?的有关规定|抽查|'
                    r'经抽查|经检查|.*?存在以下(问题|违法行为)|'
                    r'.*?认定事实|.*?存在.*?(行为|业务数据不真实)|'
                    r'你.*?于.*?期间|'
                    r'经调查|'
                    r'经我局查实|'
                    r'你.*?于.*?业务经营|'
                    r'.*?于.*?期间在展业过程|'
                    r'你公司吉水营销服务部承保车牌号为赣D/38008货车商业机车险时|'
                    r'你.*?进行.*?宣传|'
                    r'.*?于.*?业务经营|'
                    r'你公司.*?业务经营中|'
                    r'.*?在.*?期间|'
                    r'你公司于2006年1-\n?12月期间|'
                    r'.*?在.*?业务经营中存在)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()

                truth_text_str = r'((经查|一、|二、|三、|经检查|.*?存在以下(问题|违法行为)|.*?认定事实|.*?存在.*?(行为|业务数据不真实)|你公司于.*?期间)' \
                                 r'([\s\S]*?))' \
                                 r'((,|,)?(综合)?(依据|鉴于|根据))'
                truth_compiler = re.compile(truth_text_str)
                truth_list = truth_compiler.findall(content_text)
                if len(truth_list) > 0:
                    truth = '\n'.join([kk[0].strip() for kk in truth_list])
                else:
                    truth_text_str = litigant + r'([\s\S]*?)' \
                                                r'((,|,)?(综合)?(依据|鉴于|根据))'
                    truth_compiler = re.compile(truth_text_str)
                    truth = truth_compiler.search(content_text).group(
                        1).strip()

                if '申辩' in content_text:
                    defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                       r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                       r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见|陈述材料|申辩书)中称|[^,。,;\n]*?在听证阶段提出|' \
                                       r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                                       r'在法定期限内,当事人未提出|[^,。,;\n]*?提出了?陈述、申辩|[^,。,;\n]*?提出以下陈述申辩意见|' \
                                       r'[^,。,;\n]*?放弃陈述、申辩权利|[^,。,;\n]*?提出以下陈述(申辩理由|意见)|' \
                                       r'[^,。,;\n]*?陈述申辩材料中辩称|[^,。,;\n]*?陈述材料中提出|[^,。,;\n]*?提出以下申辩意见|' \
                                       r'[^,。,;\n]*?申辩中提出)' \
                                       r'([\s\S]*?))' \
                                       r'(因此,我局决定|' \
                                       r'我局经复核(认为|决定)|' \
                                       r'本案现已审理终结|' \
                                       r'我局经复查[^,。,;\n]*?情况|' \
                                       r'我局[^,。,;\n]*?认真复核|' \
                                       r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                       r'我局认为.*?申辩理由|' \
                                       r'依据.*?我局认为.*?的申辩理由|' \
                                       r'经研究,我局认为.*?申辩意见|' \
                                       r'经我局审核,决定|' \
                                       r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                       r'我局对陈述申辩意见进行了复核|' \
                                       r'经我局审核|' \
                                       r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                       r'经查,我局认为|' \
                                       r'依据现场检查及听证情况|' \
                                       r'我局认为|我局经核查|对此,我局认为|我局经审理认为|我局在处罚幅度裁量时)'
                    defense_compiler = re.compile(defense_text_str,
                                                  re.MULTILINE)
                    defense_list = defense_compiler.findall(content_text)
                    if len(defense_list) != 0:
                        defense = defense_list[-1][0].strip()
                        defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                               + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                                  r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                                  r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                                  r'不予采纳其陈述申辩理由。|维持原处罚决定。|不予采纳。|' \
                                                                  r'不予采纳.*?(陈述)?申辩(意见|理由)?。|' \
                                                                  r'我局认定你公司行为构成销售误导。|你公司的申辩不成立。))'
                        defense_response_compiler = re.compile(
                            defense_response_str, re.MULTILINE)
                        if defense_response_compiler.search(content_text):
                            defense_response = defense_response_compiler.search(
                                content_text).group(1).strip()
                        else:
                            if '未' in defense:
                                defense_response = ''
                    else:
                        defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                           '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                        defense_compiler = re.compile(defense_text_str,
                                                      re.MULTILINE)
                        defense = defense_compiler.search(content_text).group(
                            1).strip()
                        defense_response = ''
                else:
                    defense = defense_response = ''

                punishment_decision_text_str = r'(((依\n?据|根据)[^。;]*?第[^。;]*?条[\s\S]*?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                               r'(我局)?决定.*?(作出|给予)(如下|以下)(行政)?处罚:|' \
                                               r'依据《保险公司管理规定》九十九条的规定,我局决定)' \
                                               r'([\s\S]*?))' \
                                               r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                               r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|.*?如对本处罚决定不服|' \
                                               r'请在接到本处罚决定书之日|.*?须于收到本处罚决定书之日|' \
                                               r'.*?应在接到本处罚决定书之日|.*?应严格按照保监发|.*?应该在收到本决定之日|' \
                                               r'.*?收到本处罚决定书之日|.*?应于收到本处罚决定书之日)'
                punishment_decision_compiler = re.compile(
                    punishment_decision_text_str)
                punishment_decision_list = punishment_decision_compiler.findall(
                    content_text)
                if len(punishment_decision_list) > 0:
                    punishment_decision = '\n'.join(
                        [kk[0].strip() for kk in punishment_decision_list])

                punishment_basis_str_list = [
                    r'((上\n?述|以上|该)(事实|实施)?行为)?违反[^。;]*?第[^,。,;]*?条[\s\S]*?',
                ]
                punishment_basis_str = '|'.join(punishment_basis_str_list)
                punishment_basis_compiler = re.compile(
                    r'[。\n;,]' + '(' + punishment_basis_str + ')' +
                    '.(\n?依\n?据|\n?根据|\n?鉴于|\n?上述事实有现场检查确认书)', re.MULTILINE)
                punishment_basis_list = punishment_basis_compiler.findall(
                    content_text)
                punishment_basis = ';'.join(
                    [kk[0].strip() for kk in punishment_basis_list])

                publish_date_text = re.search(
                    punishment_decision.replace(r'(', r'\(').replace(
                        r')', r'\)').replace(r'[', r'\[').replace(
                            r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                    content_text).group(1).replace('\n', '')
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    publish_date_text = table_content.find_all('tr')[1].text
                    publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                              publish_date_text)[-1]
                    real_publish_date = publish_date.split('-')[0] + '年' + str(
                        int(publish_date.split('-')[1])) + '月' + str(
                            int(publish_date.split('-')[2])) + '日'

                result_map = {
                    'announcementTitle': real_title,
                    'announcementOrg': '江西银保监局',
                    'announcementDate': real_publish_date,
                    'announcementCode': document_code,
                    'facts': truth,
                    'defenseOpinion': defense,
                    'defenseResponse': defense_response,
                    'litigant':
                    litigant[:-1] if litigant[-1] == ':' else litigant,
                    'punishmentBasement': punishment_basis,
                    'punishmentDecision': punishment_decision,
                    'type': '行政处罚决定',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({
                        'announcementTitle': real_title,
                        'oss_file_id': file_id
                }).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('江西保监局 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('江西保监局 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id},
                                          {'$set': {
                                              'parsed': True
                                          }})
                logger.info('江西保监局 数据解析 ' + ' -- 修改parsed完成')

            logger.info('删除Tmp文件')
            os.remove('./test/tmp.rar')
            shutil.rmtree('./test/tmp', ignore_errors=True)
        else:
            if db.parsed_data.find({
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url
            }).count() == 0:
                oss_file_map = {
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url,
                    'origin_url_id': each_circ_data['_id'],
                    'oss_file_type': 'html',
                    'oss_file_name': announcement_title,
                    'oss_file_content':
                    r.text.encode(r.encoding).decode('utf-8'),
                    'parsed': False
                }
                insert_response = db.parsed_data.insert_one(oss_file_map)
                file_id = insert_response.inserted_id
                oss_add_file(ali_bucket,
                             str(file_id) + '/' + announcement_title + '.html',
                             r.text.encode(r.encoding).decode('utf-8'))
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
            else:
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
                file_id = db.parsed_data.find_one({
                    'origin_url':
                    announcement_url,
                    'oss_file_origin_url':
                    announcement_url
                })['_id']

            if len(table_content.find_all(class_='MsoNormalTable')) > 0:
                for each_table in table_content.find_all(
                        class_='MsoNormalTable'):
                    parse_table(file_id, each_table, title,
                                each_circ_data['publishDate'])
            else:
                document_code_compiler = re.compile(r'(赣银?保监罚.\d{4}.\d+号)')
                if document_code_compiler.search(content_text):
                    document_code = document_code_compiler.search(
                        content_text).group(1).strip()
                    litigant_compiler = re.compile(
                        document_code.replace(r'[', r'\[').replace(
                            r']', r'\]') + r'\n([\s\S]*?)\n' +
                        r'(经查|经检查|依据.*?的有关规定|'
                        r'抽查|经抽查|.*?现场检查|'
                        r'\n?.*?于\n?.*?\n?年.*?\n?期间|'
                        r'2008年9月期间|'
                        r'你公司于\n2008\n年\n1-4\n月\n期间|'
                        r'你在担任.*?期间)')
                    litigant = litigant_compiler.search(content_text).group(
                        1).strip()
                else:
                    if document_code_compiler.search(title):
                        document_code = document_code_compiler.search(
                            title).group(1).strip()
                    else:
                        document_code = ''
                    litigant_compiler = re.compile(
                        r'^([\s\S]*?)\n' +
                        r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|2008年9月期间|'
                        r'你公司于\n2008\n年\n1-4\n月\n期间|'
                        r'你在担任.*?期间)')
                    litigant = litigant_compiler.search(content_text).group(
                        1).strip()

                truth_text_str = r'((经查)' \
                                 r'([\s\S]*?))' \
                                 r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                 r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                 r'依据|' \
                                 r'你作为.*?负有直接责任|' \
                                 r'我局决定)'
                truth_compiler = re.compile(truth_text_str)
                if truth_compiler.search(content_text):
                    truth = truth_compiler.search(content_text).group(
                        1).strip()
                else:
                    truth_text_str = litigant + r'([\s\S]*?)' \
                                                r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                                r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                                r'你作为.*?对.*?负有直接责任。|' \
                                                r'[^,。,;\n]*?依据)'
                    truth_compiler = re.compile(truth_text_str)
                    truth = truth_compiler.search(content_text).group(
                        1).strip()

                if '申辩' in content_text:
                    defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                       r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                       r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                       r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                                       r'([\s\S]*?))' \
                                       r'(因此,我局决定|' \
                                       r'我局经复核(认为|决定)|' \
                                       r'本案现已审理终结|' \
                                       r'我局经复查[^,。,;\n]*?情况|' \
                                       r'我局[^,。,;\n]*?认真复核|' \
                                       r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                       r'我局认为.*?申辩理由|' \
                                       r'依据.*?我局认为.*?的申辩理由|' \
                                       r'经研究,我局认为.*?申辩意见|' \
                                       r'经我局审核,决定|' \
                                       r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                       r'我局对陈述申辩意见进行了复核|' \
                                       r'经我局审核|' \
                                       r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                       r'经查,我局认为|' \
                                       r'依据现场检查及听证情况)'
                    defense_compiler = re.compile(defense_text_str,
                                                  re.MULTILINE)
                    defense_list = defense_compiler.findall(content_text)
                    if len(defense_list) != 0:
                        defense = defense_list[-1][0].strip()
                        defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                               + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                                  r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                                  r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                        defense_response_compiler = re.compile(
                            defense_response_str, re.MULTILINE)
                        if defense_response_compiler.search(content_text):
                            defense_response = defense_response_compiler.search(
                                content_text).group(1).strip()
                        else:
                            if '未' in defense:
                                defense_response = ''
                    else:
                        defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                           '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                        defense_compiler = re.compile(defense_text_str,
                                                      re.MULTILINE)
                        defense = defense_compiler.search(content_text).group(
                            1).strip()
                        defense_response = ''
                else:
                    defense = defense_response = ''

                punishment_decision_text_str = r'(((依据|根据)[^。;]*?第[^。;]*?条[^。;]*?(规定)?.?' \
                                               r'(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                               r'我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                               r'依据\n?.*?\n?第.*?\n?的规定,我局决定|' \
                                               r'依据《保险营销员管理规定》,给予|' \
                                               r'我局决定(作出|给予))' \
                                               r'([\s\S]*?))' \
                                               r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                               r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|当事人如对本处罚决定不服|' \
                                               r'当事人应当在收到本处罚决定书之日|[^。;\n]*?在收到本处罚决定书之日|请你在收到本处罚决定书之日|' \
                                               r'你公司须于收到本处罚决定书之日|二○○九年九月一日)'

                punishment_decision_compiler = re.compile(
                    punishment_decision_text_str)
                punishment_decision = punishment_decision_compiler.search(
                    content_text).group(1).strip()

                punishment_basis_str_list = [
                    r'[^。;\n]*?(问题|行为|事项|情况|事实)[^。;]*?违反[^。;]*?第[^。;]*?条[\s\S]*?((的|之|等)(相关)?规定)?',
                    r'协助保险营销员考试作弊\n的行为,违反了\n《保险营销员管理规定》第五十六\n的规定。\n你作为.*?对该行为负有直接责任',
                    r'中国人寿永丰县支公司应当规范保险销售从业人员的销售行为,严禁保险销售从业人员在保险销售活动中给予投保人保险合同约定以外的利益。对此,中国人寿永丰县支公司违反了《保险销售从业人员监管办法》第二十四条的规定',
                    r'袁红香违反了《中华人民共和国保险法》(2009年修订)第一百三十一条第(四)项的规定',
                    r'经查,你任.*?期间,该公司[\s\S]*?违反[\s\S]*?',
                    r'经查,你任中国人寿保险股份有限公司崇仁县支公司经理期间,该公司\n2009\n年\n1-4\n月\n开展银邮业务时存在\n'
                    r'财务数据不真实的\n行为,违反了\n《中华人民共和国保险法》\n的相关规定,你作为该支公司经理负有直接责任',
                    r'经查,你公司于\n2009\n年\n1-4\n月\n开展银邮业务时存在\n财务数据不真实\n的行为,该行为违反了\n《中华人民共和国保险法》\n的相关规定',
                    r'上述行为既不符合\n《关于保险代理(经纪)机构投保职业责任保险有关事宜的通知》(保监发〔\n2005\n〕\n27\n号)\n的有关要求,也不符合《\n保险专业代理机构监管规定》第四十条\n的有关规定'
                ]
                punishment_basis_str = '|'.join(punishment_basis_str_list)
                punishment_basis_compiler = re.compile(
                    r'[。\n;]' + '(' + punishment_basis_str + ')' +
                    '.(\n?依据|\n?根据|\n?鉴于|\n?我局决定)', re.MULTILINE)
                punishment_basis_list = punishment_basis_compiler.findall(
                    content_text)
                punishment_basis = ';'.join([
                    kk[0].replace(litigant.split('\n')[-1], '').strip()
                    for kk in punishment_basis_list
                ])

                publish_date_text = re.search(
                    punishment_decision.replace(r'(', r'\(').replace(
                        r')', r'\)').replace(r'[', r'\[').replace(
                            r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                    content_text).group(1).replace('\n', '')
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    publish_date_text = table_content.find_all('tr')[1].text
                    publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                              publish_date_text)[-1]
                    real_publish_date = publish_date.split('-')[0] + '年' + str(
                        int(publish_date.split('-')[1])) + '月' + str(
                            int(publish_date.split('-')[2])) + '日'

                result_map = {
                    'announcementTitle': title,
                    'announcementOrg': '江西银保监局',
                    'announcementDate': real_publish_date,
                    'announcementCode': document_code,
                    'facts': truth,
                    'defenseOpinion': defense,
                    'defenseResponse': defense_response,
                    'litigant':
                    litigant[:-1] if litigant[-1] == ':' else litigant,
                    'punishmentBasement': punishment_basis,
                    'punishmentDecision': punishment_decision,
                    'type': '行政处罚决定',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({
                        'announcementTitle': title,
                        'oss_file_id': file_id
                }).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('江西保监局 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('江西保监局 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id},
                                          {'$set': {
                                              'parsed': True
                                          }})
                logger.info('江西保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #19
0
def hubei_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '湖北保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('湖北保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((鄂保监罚|鄂银保监罚决字).\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            if document_code + '\n行政处罚决定书' in content_text:
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n行政处罚决定书\n([\s\S]*?)\n' +
                    r'(经查|经检查|依据.*?的有关规定|\d+年\d+月\d+日|根据我局2008年整顿|根据举报|.*?对.*?(进行了?|开展).*?((现场|投诉|举报|专项|临时)检查|检查清理))'
                )
            else:
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' +
                    r'(经查|经检查|依据.*?的有关规定|\d+年\d+月\d+日|根据我局2008年整顿|根据举报|.*?对.*?(进行了?|开展).*?((现场|投诉|举报|专项|临时)检查|检查清理))'
                )
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(announcement_title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' +
                    r'(经查|经检查|依据.*?的有关规定|2008年5月29日|2008年6月3日|根据我局2008年整顿|根据举报|'
                    r'.*?对.*?(进行了?|开展).*?(现场|投诉|举报|专项|临时)检查)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                document_code_compiler = re.compile(r'(.\d{4}.\d+号)')
                if document_code_compiler.search(announcement_title):
                    document_code = '鄂银保监罚决字' + document_code_compiler.search(
                        announcement_title).group(1).strip()
                    litigant_compiler = re.compile(
                        r'^([\s\S]*?)\n' +
                        r'(经查|经检查|依据.*?的有关规定|2008年5月29日|2008年6月3日|根据我局2008年整顿|根据举报|'
                        r'.*?对.*?(进行了?|开展).*?(现场|投诉|举报|专项|临时)检查)')
                    litigant = litigant_compiler.search(content_text).group(
                        1).strip()
                else:
                    document_code_compiler = re.compile(
                        r'((鄂保监罚|鄂银保监罚决字).\d{4}.\d+)')
                    if document_code_compiler.search(content_text):
                        document_code = document_code_compiler.search(
                            content_text).group(1).strip()
                        litigant_compiler = re.compile(
                            document_code.replace(r'[', r'\[').replace(
                                r']', r'\]') + r'\n([\s\S]*?)\n' +
                            r'(经查|经检查|依据.*?的有关规定|2008年5月29日|2008年6月3日|'
                            r'根据我局2008年整顿|根据举报|.*?对.*?(进行了?|开展).*?((现场|投诉|举报|专项|临时)检查|检查清理))'
                        )
                        litigant = litigant_compiler.search(
                            content_text).group(1).strip()
                        document_code = document_code + '号'
                    else:
                        document_code = ''
                        litigant_compiler = re.compile(
                            r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|'
                            r'.*?对.*?(进行了?|开展).*?(现场|投诉|举报|专项|临时)检查)')
                        litigant = litigant_compiler.search(
                            content_text).group(1).strip()

        litigant = litigant.replace('行政处罚决定书', '').strip()

        truth_text_str = r'((经查|现场检查,发现)' \
                         r'([\s\S]*?))' \
                         r'([^,。,;]*?(上述|以上)(违规|违法)?(事实|行为)[^。;\n]*?有.*?等证据(在案)?证明|' \
                         r'[^,。,;]*?(上述|以上)(违规|违法)?(事实|行为)[^。;\n]*?违反了.*?第.*?条.*?((之|的|等)规定)?|' \
                         r'[^,。,;\n]*?违反.*?第.*?条.*?规定|' \
                         r'以上行为违反了《保险法》第一百二十二的规定。)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'([^,。,;]*?(上述|以上)(违规|违法)?(事实|行为)[^。;\n]*?有.*?等证据(在案)?证明|' \
                                        r'[^,。,;]*?(上述|以上)(违规|违法)?(事实|行为)[^。;\n]*?违反了.*?第.*?条.*?((之|的|等)规定)?|' \
                                        r'[^,。,;\n]*?违反.*?第.*?条.*?规定|' \
                                        r'以上行为违反了《保险法》第一百二十二的规定。)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(决定|责令|给予|于.*?向.*?发出|对|拟对你)|' \
                                       r'我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'我局决定对你给予|' \
                                       r'我局对.*?陈述申辩意见不予采纳,决定作出如下处罚)' \
                                       r'([\s\S]*?))' \
                                       r'(.*?应(当)?在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|' \
                                       r'你公司如不服本处罚决定|请你.*?在接到本处罚决定书之日|如不服本处罚决定|请你公司在接到本处罚决定书之日|' \
                                       r'请.*?在接到本处罚决定书之日|你.*?必须立即采取措施对上述违法行为予以改正|你.*?在接到本处罚决定书15日内|' \
                                       r'如你对本处罚决定不服|.*?应在接到本处罚决定书)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'经查,你支公司2008年对承保的非车险业务违规批单退费,违反了《保险法》第一百二十二条之规定',
            r'上述行为违反了《保险法》一百三十一条之规定',
            r'经查,你分公司2008年将对银行工作人员的奖励费用在“手续费及佣金支出”科目列支,违反了《保险法》第一百二十二条之规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            '.(\n?依据|\n?根据|\n?鉴于|\n?我局决定对你给予)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace(r'\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '湖北银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('湖北保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('湖北保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('湖北保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #20
0
def xinjiang_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '新疆保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('新疆保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(
            r'((新保监[罚中]|新银保监罚决字).*?\d{4}.*?\d+.*?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                r'一、你在担任.*?期间|'
                r'我局在.*?现场检查过程中,发现|'
                r'近期,我局对.*?进行了查处。|'
                r'新疆中亚保险代理有限公司和新疆德昌保险代理有限公司未按规定缴存营业保证金,违反了《保险代理机构管理规定》第二十一条和第二十二条之规定)'
            )
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(
                    1).strip()
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                    r'一、你在担任.*?期间|'
                    r'我局在.*?现场检查过程中,发现|'
                    r'近期,我局对.*?进行了查处。|'
                    r'新疆中亚保险代理有限公司和新疆德昌保险代理有限公司未按规定缴存营业保证金,违反了《保险代理机构管理规定》第二十一条和第二十二条之规定)'
                )
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                document_code = ''
                litigant_compiler = re.compile(
                    r'关于对(.*?)(实施行政处罚|违规截留客户保费的行为实施行政处罚的通报)')
                litigant = litigant_compiler.search(title).group(1).strip()

        truth_text_str = r'((经查|一、(^二)|二、|三、|四、|五、)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'刘孝虎上述行为违反了《保险营销员管理规定》第三十六条第十八款之规定|' \
                         r'依据 《保险代理机构管理规定》第一百三十八条之规定及你单位实际情况|' \
                         r',违反了《保险代理机构管理规定》第二十一条和第二十二条之规定|' \
                         r',这违反了《保险经纪机构管理规定》第六十九条之规定|' \
                         r',违反了《保险代理机构管理规定》第六十三条之规定)'
        truth_compiler = re.compile(truth_text_str)
        truth_list = truth_compiler.findall(content_text)
        if len(truth_list) > 0:
            truth = '\n'.join([kk[0].strip() for kk in truth_list])
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(1).strip()
            else:
                truth_text_str = r'(各保险公司、保险中介公司、保险行业协会:)' + r'([\s\S]*?)' \
                                                             r'(依据)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(2).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'((.*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                     r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                     r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = r'([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   r'我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?我局(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'(依据|根据).*?第?.*?条.*?(规定)?.?(决定)?(给予|对你|对其))' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|[^。;\n]*?在本处罚决定书送达之日起15日|' \
                                       r'[^。;\n]*?在接到本处罚决定书之日|二、|三、|各保险公司应引以为戒,切实加强保险营销员队伍管控|' \
                                       r'各保险中介公司要进一步增强依法合规经营意识|各公司接此通知后|各保险中介公司要吸取教训,引以为戒)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision_list = punishment_decision_compiler.findall(
            content_text)
        if len(punishment_decision_list) > 0:
            punishment_decision = '\n'.join(
                [kk[0].strip() for kk in punishment_decision_list])

        punishment_basis_str_list = [
            r'([^\n。;\s]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'经查,你单位自2006年2月起未使用独立的代收保险费账户,违反了《保险代理机构管理规定》第九十一条之规定',
            r'新疆中亚保险代理有限公司和新疆德昌保险代理有限公司未按规定缴存营业保证金,违反了《保险代理机构管理规定》第二十一条和第二十二条之规定',
            r'乌鲁木齐吉尔盛保险代理有限公司未经批准,擅自任用高级管理人员,违反了《保险代理机构管理规定》第六十三条之规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;]' + '(' + punishment_basis_str + ')' +
            '.(\n?依据|\n?(我局)?根据|\n?鉴于)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision_list[-1][0] + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1].replace(' ', '')
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '新疆银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('新疆保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('新疆保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('新疆保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #21
0
ファイル: guangxi.py プロジェクト: wagaman/jgcf
def guangxi_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '广西保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('广西保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚信息主动公开事项' in title or '行政处罚主动公开事项' in title:
            if len([
                    each_link.attrs['href']
                    for each_link in table_content.find_all('a')
                    if '.xls' in each_link.attrs['href'].strip()
            ]) > 0:
                xlsx_link = [
                    urljoin(announcement_url, each_link.attrs['href'])
                    for each_link in table_content.find_all('a')
                    if '.xls' in each_link.attrs['href'].strip()
                ][0]

                response = request_site_page(xlsx_link)
                link_type = xlsx_link.split('.')[-1]
                with open('./test/tmp.' + link_type, 'wb') as f:
                    f.write(response.content)

                with open('./test/tmp.' + link_type, 'rb') as xlsx_file:
                    xlsx_content = xlsx_file.read()

                if db.parsed_data.find({
                        'origin_url': announcement_url,
                        'oss_file_origin_url': xlsx_link
                }).count() == 0:
                    oss_file_map = {
                        'origin_url': announcement_url,
                        'oss_file_origin_url': xlsx_link,
                        'origin_url_id': each_circ_data['_id'],
                        'oss_file_type': 'xlsx',
                        'oss_file_name': announcement_title,
                        'oss_file_content': xlsx_content,
                        'parsed': False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(
                        ali_bucket,
                        str(file_id) + '/' + announcement_title + '.xlsx',
                        xlsx_content)
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                    file_id = db.parsed_data.find_one({
                        'origin_url':
                        announcement_url,
                        'oss_file_origin_url':
                        xlsx_link
                    })['_id']

                excel_data = open_workbook('./test/tmp.' + link_type)
                logger.info('删除tmp文件')
                if os.path.exists('./test/tmp.xls'):
                    os.remove('./test/tmp.xls')
                if os.path.exists('./test/tmp.xlsx'):
                    os.remove('./test/tmp.xlsx')

                sheet = excel_data.sheets()[0]

                result_map_list = []
                for i in range(sheet.nrows):
                    if i < 2:
                        continue
                    document_code = sheet.cell(i, 1).value.strip()
                    if document_code == '':
                        document_code = document_code
                    real_title = '广西银保监局行政处罚决定书' + '(' + str(
                        document_code) + ')'
                    litigant = sheet.cell(i, 2).value.strip()
                    if sheet.cell(i, 6).ctype == 3:
                        publish_date = xldate_as_tuple(sheet.cell_value(i, 6),
                                                       excel_data.datemode)
                        publish_date = str(publish_date[0]) + '年' + str(
                            publish_date[1]) + '月' + str(publish_date[2]) + '日'
                    else:
                        try:
                            publish_date = str(sheet.cell(
                                i, 6).value.year) + '年' + str(
                                    sheet.cell(i, 6).value.month) + '月' + str(
                                        sheet.cell(i, 6).value.day) + '日'
                        except:
                            publish_date = publish_date
                    truth = litigant + sheet.cell(i, 3).value
                    defense = defense_response = ''
                    punishment_decision = \
                        sheet.cell(i, 4).value + ',我局对' + litigant + '作出以下处罚:' + sheet.cell(i, 5).value
                    punishment_basis = ''
                    each_map = {
                        'announcementTitle': real_title,
                        'announcementOrg': '广西银保监局',
                        'announcementDate': publish_date,
                        'announcementCode': document_code,
                        'facts': truth,
                        'defenseOpinion': defense,
                        'defenseResponse': defense_response,
                        'litigant':
                        litigant[:-1] if litigant[-1] == ':' else litigant,
                        'punishmentBasement': punishment_basis,
                        'punishmentDecision': punishment_decision,
                        'type': '行政处罚决定',
                        'oss_file_id': file_id,
                        'status': 'not checked'
                    }
                    logger.info(each_map)
                    if db.announcement.find({
                            'announcementTitle': real_title,
                            'oss_file_id': file_id,
                            'litigant': each_map['litigant']
                    }).count() == 0:
                        db.announcement.insert_one(each_map)
                        logger.info('广西保监局 数据解析 ' + ' -- 数据导入完成')
                    else:
                        logger.info('广西保监局 数据解析 ' + ' -- 数据已经存在')
                    result_map_list.append(each_map)
                if len(result_map_list) > 0:
                    logger.info('广西保监局 数据解析 ' +
                                ' -- 一共有%d条数据' % len(result_map_list))
                    db.parsed_data.update_one({'_id': file_id},
                                              {'$set': {
                                                  'parsed': True
                                              }})
                    logger.info('广西保监局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.warning('广西保监局 数据解析 ' + ' -- 无数据')

        else:
            if '.doc' in content_text:
                if len([
                        each_link.attrs['href']
                        for each_link in table_content.find_all('a')
                        if '.doc' in each_link.attrs['href'].strip()
                ]) > 0:
                    doc_link = [
                        urljoin(announcement_url, each_link.attrs['href'])
                        for each_link in table_content.find_all('a')
                        if '.doc' in each_link.attrs['href'].strip()
                    ][0]
                    link_type = doc_link.split('.')[-1]
                    response = request_site_page(doc_link)
                    if response is None:
                        logger.error('网页请求错误')
                        return

                    with open('./test/tmp.' + link_type, 'wb') as tmp_file:
                        for chunk in response.iter_content(chunk_size=1024):
                            if chunk:
                                tmp_file.write(chunk)

                    if not os.path.exists('./test/tmp.docx'):
                        shell_str = '/usr/local/bin/soffice --headless --convert-to docx ' + \
                                    './test/tmp.' + link_type + ' --outdir ./test'
                        process = subprocess.Popen(shell_str.replace(
                            r'(', r'\(').replace(r')', r'\)'),
                                                   shell=True,
                                                   stdout=subprocess.PIPE)
                        process.communicate()

                    with open('./test/tmp.docx', 'rb') as docx_file:
                        docx_content = docx_file.read()

                    if db.parsed_data.find({
                            'origin_url': announcement_url,
                            'oss_file_origin_url': doc_link
                    }).count() == 0:
                        oss_file_map = {
                            'origin_url': announcement_url,
                            'oss_file_origin_url': doc_link,
                            'origin_url_id': each_circ_data['_id'],
                            'oss_file_type': 'docx',
                            'oss_file_name': announcement_title,
                            'oss_file_content': docx_content,
                            'parsed': False
                        }
                        response = db.parsed_data.insert_one(oss_file_map)
                        file_id = response.inserted_id
                        oss_add_file(
                            ali_bucket,
                            str(file_id) + '/' + announcement_title + '.docx',
                            docx_content)
                        db.circ_data.update_one({'_id': each_circ_data['_id']},
                                                {'$set': {
                                                    'status': 'parsed'
                                                }})
                    else:
                        db.circ_data.update_one({'_id': each_circ_data['_id']},
                                                {'$set': {
                                                    'status': 'parsed'
                                                }})
                        file_id = db.parsed_data.find_one({
                            'origin_url':
                            announcement_url,
                            'oss_file_origin_url':
                            doc_link
                        })['_id']
                    document = Document('./test/tmp.docx')
                    logger.info('删除tmp文件')
                    if os.path.exists('./test/tmp.doc'):
                        os.remove('./test/tmp.doc')
                    if os.path.exists('./test/tmp.docx'):
                        os.remove('./test/tmp.docx')
                    result_map_list = []
                    tables = document.tables
                    for table in tables:
                        for row in table.rows:
                            result_map_list.append(
                                [kk.text for kk in row.cells])
                    parse_table(file_id, result_map_list, announcement_title,
                                each_circ_data['publishDate'], db, logger)
            else:
                if db.parsed_data.find({
                        'origin_url': announcement_url,
                        'oss_file_origin_url': announcement_url
                }).count() == 0:
                    oss_file_map = {
                        'origin_url':
                        announcement_url,
                        'oss_file_origin_url':
                        announcement_url,
                        'origin_url_id':
                        each_circ_data['_id'],
                        'oss_file_type':
                        'html',
                        'oss_file_name':
                        announcement_title,
                        'oss_file_content':
                        r.text.encode(r.encoding).decode('utf-8'),
                        'parsed':
                        False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(
                        ali_bucket,
                        str(file_id) + '/' + announcement_title + '.html',
                        r.text.encode(r.encoding).decode('utf-8'))
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']},
                                            {'$set': {
                                                'status': 'parsed'
                                            }})
                    file_id = db.parsed_data.find_one({
                        'origin_url':
                        announcement_url,
                        'oss_file_origin_url':
                        announcement_url
                    })['_id']

                document_code_compiler = re.compile(r'(桂银?保监罚.\d{4}.\d+号)')
                if document_code_compiler.search(content_text):
                    document_code = document_code_compiler.search(
                        content_text).group(1).strip()
                    litigant_compiler = re.compile(
                        document_code.replace(r'[', r'\[').replace(
                            r']', r'\]') + r'\n([\s\S]*?)\n' +
                        r'(经查|经检查|依据.*?的有关规定|抽查|'
                        r'经抽查|.*?(现场检查|案件调查))')
                    litigant = litigant_compiler.search(content_text).group(
                        1).strip()
                else:
                    if document_code_compiler.search(title):
                        document_code = document_code_compiler.search(
                            title).group(1).strip()
                    else:
                        document_code_compiler = re.compile(r'(.\d{4}.*?\d+号)')
                        if document_code_compiler.search(title):
                            document_code = '桂保监罚' + document_code_compiler.search(
                                title).group(1).strip()
                        else:
                            document_code = ''
                    litigant_compiler = re.compile(
                        r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                        r'.*?(现场检查|案件调查))')
                    litigant = litigant_compiler.search(content_text).group(
                        1).strip()

                truth_text_str = r'((经查)' \
                                 r'([\s\S]*?))' \
                                 r'((我局认为,)?(上述|以上).*?(事实|行为|事实).*?有.*?等证据(材料)?(在案)?证明(,|,|。)(足以认定。)?|' \
                                 r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                 r'上述违法事实有现场检查事实确认书、相关人员询问笔录、\n会计凭证复印件、营业执照复印件、劳动合同复印件、任职文件复印件等证据材料在案证明。|' \
                                 r'你单位的行为违反了《中华人民共和国保险法》第八十二条的规定|' \
                                 r'违反了《保险法》第一百零七条、第一百二十二条|' \
                                 r'(依据|根据)\n?.*?第)'
                truth_compiler = re.compile(truth_text_str)
                if truth_compiler.search(content_text):
                    truth = truth_compiler.search(content_text).group(
                        1).strip()
                else:
                    truth_text_str = litigant.replace(r'(', r'\(').replace(r')', r'\)') \
                                     + r'([\s\S]*?)' \
                                       r'((我局认为,)?(上述|以上).*?(事实|行为|事实).?有.*?等证据(在案)?证明|' \
                                       r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
                    truth_compiler = re.compile(truth_text_str)
                    truth = truth_compiler.search(content_text).group(
                        1).strip()

                if '申辩' in content_text:
                    defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                       r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                       r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                       r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                                       r'([\s\S]*?))' \
                                       r'(因此,我局决定|' \
                                       r'我局经复核(认为|决定)|' \
                                       r'本案现已审理终结|' \
                                       r'我局经复查[^,。,;\n]*?情况|' \
                                       r'我局[^,。,;\n]*?认真复核|' \
                                       r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                       r'我局认为.*?申辩理由|' \
                                       r'依据.*?我局认为.*?的申辩理由|' \
                                       r'经研究,我局认为.*?申辩意见|' \
                                       r'经我局审核,决定|' \
                                       r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                       r'我局对陈述申辩意见进行了复核|' \
                                       r'经我局审核|' \
                                       r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                       r'经查,我局认为|' \
                                       r'依据现场检查及听证情况|' \
                                       r'经查)'
                    defense_compiler = re.compile(defense_text_str,
                                                  re.MULTILINE)
                    defense_list = defense_compiler.findall(content_text)
                    if len(defense_list) != 0:
                        defense = defense_list[-1][0].strip()
                        defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                               + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                                  r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                                  r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                        defense_response_compiler = re.compile(
                            defense_response_str, re.MULTILINE)
                        if defense_response_compiler.search(content_text):
                            defense_response = defense_response_compiler.search(
                                content_text).group(1).strip()
                        else:
                            if '未' in defense:
                                defense_response = ''
                    else:
                        defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                           '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                        defense_compiler = re.compile(defense_text_str,
                                                      re.MULTILINE)
                        defense = defense_compiler.search(content_text).group(
                            1).strip()
                        defense_response = ''
                else:
                    defense = defense_response = ''

                punishment_decision_text_str = r'(((依据|根据)\n?.*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                               r'我局决定.*?作出(如下|以下)(行政)?处罚:)' \
                                               r'([\s\S]*?))' \
                                               r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                               r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|如.*?对本处罚决定不服)'

                punishment_decision_compiler = re.compile(
                    punishment_decision_text_str)
                punishment_decision = punishment_decision_compiler.search(
                    content_text).group(1).strip()

                punishment_basis_str_list = [
                    r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
                    r'中国平安财产保险股份有限公司玉林中心支公司上述行为违反了《中华人民共和国保险法》,我局依法对该公司进行了行政处罚。曾家兴是对该公司上述违法行为负有直接责任的主管人员',
                    r'经查.*?存在.*?行为, 违反了.*?第.*?条的规定。\n.*?负有直接责任'
                ]
                punishment_basis_str = '|'.join(punishment_basis_str_list)
                punishment_basis_compiler = re.compile(
                    r'[。\n;]' + '(' + punishment_basis_str + ')' +
                    '.(\n?依据|\n?根据|\n?鉴于|\n?你公司在申辩材料中称)', re.MULTILINE)
                punishment_basis_list = punishment_basis_compiler.findall(
                    content_text)
                punishment_basis = ';'.join(
                    [kk[0].strip() for kk in punishment_basis_list])

                publish_date_text = re.search(
                    punishment_decision.replace(r'(', r'\(').replace(
                        r')', r'\)').replace(r'[', r'\[').replace(
                            r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                    content_text).group(1).replace('\n', '')
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    publish_date_text = table_content.find_all('tr')[1].text
                    publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                              publish_date_text)[-1]
                    real_publish_date = publish_date.split('-')[0] + '年' + str(
                        int(publish_date.split('-')[1])) + '月' + str(
                            int(publish_date.split('-')[2])) + '日'

                result_map = {
                    'announcementTitle': title,
                    'announcementOrg': '广西银保监局',
                    'announcementDate': real_publish_date,
                    'announcementCode': document_code,
                    'facts': truth,
                    'defenseOpinion': defense,
                    'defenseResponse': defense_response,
                    'litigant':
                    litigant[:-1] if litigant[-1] == ':' else litigant,
                    'punishmentBasement': punishment_basis,
                    'punishmentDecision': punishment_decision,
                    'type': '行政处罚决定',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({
                        'announcementTitle': title,
                        'oss_file_id': file_id
                }).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('广西保监局 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('广西保监局 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id},
                                          {'$set': {
                                              'parsed': True
                                          }})
                logger.info('广西保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #22
0
def neimenggu_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '内蒙古保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('内蒙古保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((内保监罚|内银保监筹便函).*?\d{4}.*?\d+.*?号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?有关规定|抽查'
                                    r'|经抽查|一、经查|一、 经查|'
                                    r'.*?我分局检查组对.*?进行了现场检查|'
                                    r'.*?(我局|内蒙古保监局).*?对.*?(专项检查|现场检查|投诉检查|举报检查|举报核查|业务检查|'
                                    r'被举报事项进行了检查|信访核查|专项核查|延伸检查|迁址事项的核查|立案调查)|'
                                    r'.*?考生.*?代替考生.*?参加.*?考试|'
                                    r'.*?代替.*?参加.*?考试|'
                                    r'2009年5月至2010年6月,李吉庆在中国人民人寿保险股份有限公司呼和浩特分公司共投保了19份保险|'
                                    r'在2006年6月的保险中介专项检查)')
            litigant = litigant_compiler.search(content_text).group(1).replace('中国保监会内蒙古监管局行政处罚决定书', '').strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(r'^([\s\S]*?)\n' +
                                           r'(经查|经检查|依据.*?有关规定|抽查|经抽查|一、经查|'
                                           r'.*?我分局检查组对.*?进行了现场检查|一、 经查|'
                                           r'.*?(我局|内蒙古保监局).*?对.*?(专项检查|现场检查|投诉检查|举报检查|举报核查|'
                                           r'业务检查|被举报事项进行了检查|信访核查|专项核查|延伸检查|迁址事项的核查|立案调查)|'
                                           r'.*?代替.*?参加.*?考试|'
                                           r'2009年5月至2010年6月,李吉庆在中国人民人寿保险股份有限公司呼和浩特分公司共投保了19份保险|'
                                           r'在2006年6月的保险中介专项检查)')
            litigant = litigant_compiler.search(content_text).group(1).replace('中国保监会内蒙古监管局行政处罚决定书', '').strip()

        truth_text_str = '(检查发现,该公司存在以下违法违规行为:\n委托未取得合法资格的机构或个人从事保险销售活动。|' \
                         '检查发现,该公司存在以下违法违规行为:\n该公司委托未取得合法资格的机构或个人从事保险销售活动|' \
                         '检查发现,该公司存在以下违法违规行为:\n该公司截留保险费行为违反了《保险法》第一百一十六条第七项规定|' \
                         '检查发现,该公司存在以下违法违规行为:\n该公司财务数据不真实,不实列支营业费用的行为违反了《保险法》第八十六条第二款规定。)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = r'((经查|经检查|检查发现|现场检查,发现|抽查|经抽查|' \
                             r'存在下列违法行为:|核查发现,)' \
                             r'([\s\S]*?))' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|事实).*?(,|,)?有.*?等.*?证明(,|,|。)?(足以认定。)?|' \
                             r'(,|,|。|\n|\s)(依据|按照)|\n.*?辩称|上述行为,情节严重,我局决定|' \
                             r'你公司未对我局行政处罚事先告知书提出申辩意见|' \
                             r'经研究你公司申辩意见)'
            truth_compiler = re.compile(truth_text_str)
            # truth_list = truth_compiler.findall(content_text)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(1).strip()
            else:
                truth_text_str = litigant + \
                                 r'([\s\S]*?)' \
                                 r'((我局认为,)?(上述|以上).*?(事实|行为|事实).*?(,|,)?有.*?等证据(在案)?(证明)?(,|,|。)(足以认定。)?|' \
                                 r'我局已?向.*?下达了)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'[^,。,;\n]*?提交书面(陈述)?申辩材料|[^,。,;\n、]*?辩称|[^,。,;\n]*?公司申辩|你公司提出的申辩|' \
                               r'你公司辩称:印制违规计划书为代理人个人行为,且未造成明显或潜在客户利益损失)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'我局对[^,。,;\n]*?申辩意见做了认真复核|' \
                               r'经审核|经研究|经核查|经查|' \
                               r'我局对[^,。,;\n]*?申辩意见进行了研究|' \
                               r'你公司申辩理由均为任命白洁为执行董事后的情形|' \
                               r'你公司没有提供有效证据|' \
                               r'张成富购买保单为国寿呼和浩特分公司承保|' \
                               r'我局认为,你公司股权转让,既转让权利,也转让义务|' \
                               r'你公司未提供有效证据证明|采纳申辩意见|' \
                               r'我局认为|内蒙古保监局认为|经复核|对你公司的申辩意见)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') + \
                                       r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                        r'[^,。,;\n]*?申辩(意见|理由)(不予|予以|部分)采纳|因此.*?申辩.*?成立。|' \
                                                        r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                        r'其它申辩意见不予采纳。|有从轻处罚的依据|决定部分采纳你公司申辩意见。|' \
                                                        r'综上,你公司关于主管人员处罚的申辩意见不予采纳。|' \
                                                        r'已对你公司从轻处罚。|故不予采纳。|不采纳申辩意见。|' \
                                                        r'不予采纳你公司申辩意见。|采纳申辩意见|我局决定免予对该公司法定代表人的行政处罚。|' \
                                                        r'申辩理由不予认可。|申辩意见不予采纳。|我局不予采纳。|' \
                                                        r'故你公司提出的申辩意见不予采纳。|故维持原处罚决定。))'
                defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。|' \
                                   '你公司未对我局行政处罚事先告知书提出申辩意见|上述三人未向我局提交申辩意见|' \
                                   '你公司未按规定使用经批准或者备案的保险条款、保险费率的申辩意见予以采纳。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                if defense_compiler.search(content_text):
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
                else:
                    defense = ''
                    defense_response_text_str = '(你公司未按规定使用经批准或者备案的保险条款、保险费率的申辩意见予以采纳。|' \
                                                '你公司利用保险兼业代理人虚构中介业务支取手续费的申辩意见予以采纳。|' \
                                                '公司申辩意见予以采纳|步行街邮政支局没有提供可以减轻处罚的相关证据,申辩理由不予采纳。)'
                    defense_response_compiler = re.compile(defense_response_text_str, re.MULTILINE)
                    defense_response = defense_response_compiler.search(content_text).group(1).strip()
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据|按照)[^。;\n]*?第[^。;\n]*?条[^。;\n]*?(规定)?.?(我局)?' \
                                       r'(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                       r'我局决定.*?作出(如下|以下)(行政)?处罚|综上,我局作出如下处罚|' \
                                       r'依据本条规定,我局决定|上述行为,情节严重,我局决定|' \
                                       r'依据本法第[^。;\n]*?条规定,决定对你|依据本法第一百七十四规定,我局决定|' \
                                       r'依据本法第一百六十七条第一项规定,决定对|' \
                                       r'依据《保险营销员管理规定》,决定给予|' \
                                       r'上述行为违反了《中华人民共和国保险法》第一百三十一条规定,“保险代理人、保险经纪人及其从业人员在办理保险业务活动中不得有下列行为:' \
                                       r'(二)隐瞒与保险合同有关的重要情况”,依据本法第一百七十四条规定,“个人保险代理人违反本法规定的,由保险监督管理机构给予警告,' \
                                       r'可以并处二万元以下的罚款;情节严重的,处二万元以上十万元以下的罚款,并可以吊销其资格证书”,我局决定)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|[^。;\n]*?应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|[^。;\n]*?对本处罚决定不服|' \
                                       r'如不服本决定|望你公司认真吸取经验教训,切实增强依法合规经营意识)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'你的上述行为,违法了保险法该项规定',
            r'上述行为情节严重。中国银行内蒙古分行违反了《中华人民共和国保险法》第一百三十二条、第八十六条,中国银行呼和佳地支行违反了《中华人民共和国保险法》第一百三十一条第一款规定',
            r'一、未按照规定建立会计科目和会计帐簿,违反了《保险代理机构管理规定》第九十五条。\n'
            r'二、未对主营业务收入做帐务处理,部分会计凭证未附原始票据和明细清单以及会计凭证缺失,违反了《保险中介公司会计核算办法》的有关规定',
            r'一、未按照规定建立会计科目和会计帐簿,违反了《保险代理机构管理规定》第九十五条。\n'
            r'二、2006年6月以前,一直未使用《保险中介服务统一发票》,违反了《国家税务总局、中国保监会关于规范保险中介服务发票管理有关问题的通知》',
            r'一、未按照规定建立会计科目和会计帐簿,违反了《保险代理机构管理规定》第九十五条。\n'
            r'二、任免高级管理人员未及时报告,违反了《保险代理机构管理规定》第七十四条。\n三、报送的报表数据不真实,违反了《保险代理机构管理规定》第一百零七条',
            r'上述行为,违法了《中华人民共和国保险法》第一百二十五条规定',
            r'对公司未按照规定缴存保证金或者投保职业责任保险违反了《保险法》第一百二十四条行为',
            r'上述事实行为违反了《保险代理机构管理规定》、《国家税务总局、中国保监会关于规范保险中介服务发票管理有关问题的通知》',
            r'上述行为情节严重。中国银行内蒙古分行违反了《中华人民共和国保险法》第一百三十二条、第八十六条,中国银行呼和佳地支行违反了《中华人民共和国保险法》第一百三十一条第一款规定'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(r'[。\n;、]' + '(' + punishment_basis_str + ')' +
                                               r'.(\n?(应当)?依据|\n?根据|\n?鉴于|\n?按照|'
                                               r'上述行为,情节严重,我局决定|\n人寿财险内蒙古分公司在申辩材料中称|'
                                               r'\n中国人寿呼和浩特分公司在申辩材料中称|\n人保财险呼市分公司在申辩材料中称|'
                                               r'\n?二、未|\n?三、未|\n?四、未|\n?五、转让|\n?六、编制|七、不)',
                                               re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
            replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
            m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '内蒙古银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('内蒙古保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('内蒙古保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('内蒙古保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #23
0
ファイル: xizang.py プロジェクト: wagaman/jgcf
def xizang_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '西藏保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if '行政处罚实施规程' in announcement_title:
            logger.warning(announcement_url + ' ' + announcement_title +
                           ' 与监管处罚无关')
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'ignored'
                                    }})
            logger.info('西藏保监局' + ' 无关数据' + ' -- 修改status完成')
            continue

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('西藏保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'(藏银保监筹?罚.\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(
                1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') + r'\n'
                r'([\s\S]*?)\n' +
                r'(依据.*(的)?有关规定|经查[,。]|\d{4}年(\d+月)?,你公司|检查发现你公司|你公司于|'
                r'\d{4}年\d+月,你作为.*?(工作人员|营销员|经理)|经对你公司.*?检查发现,|'
                r'\d{4}年\d+月,我局检查发现你单位|我局在对.*?现场检查中发现|检查发现,你公司|'
                r'\d{4}年\d+月至\d+月(期)?间,|\d{4}年\d+月至\d+月,经对你.*现场检查发现|'
                r'\d{4}年\d+月至\d{4}年\d+月(期)?间,|抽查发现你公司|'
                r'你任.*期间,经营存在下列违法行为:|你任.*期间,该公司存在下列违法行为:|'
                r'你任.*期间,存在.*?问题|'
                r'2010年 12月,生命人寿保险股份有限公司|2009年4月,在未取得我局批准的情况下,)')
            litigant = litigant_compiler.search(content_text).group(1).strip()
        else:
            document_code = re.search(r'.(.*?保监.*?\d{4}.*?\d+号).',
                                      title).group(1).strip()
            litigant = re.search(r'^([\s\S]*?)' + '(依据.*(的)?有关规定|经查,|检查发现你公司)',
                                 content_text).group(1).strip()

        truth_text_str = r'(经查,.*?存在以下违法行为:\n|经查,|经查,.*存在下列违法违规行为:\n|' \
                         r'经抽查发现,|经查。你公司存在下列违法行为:|' \
                         r'经查,.*存在下列违法行为:\n?)' \
                         r'([\s\S]*?)' \
                         r'(上述(违法)?事实,有.*?等证据(在案)?证明(在案)?(,|,)足以认定。|上述事实,有.*等证据证明。|上述违法事实有.*?等证据在案证明,足以认定|' \
                         r'该违法事实,有.*?等证据在案证明,足以认定|' \
                         r'该公司上述行为违反了《保险法》第一百一十六条:“保险公司及其工作人员在保险业务活动中不得有下列行为:|' \
                         r'综上,决定给予你公司.*?的行政处罚|' \
                         r'(上述|以上)(违法)?(事实(行为)?|行为)(,)?违反了《中华人民共和国保险法》(2002年修正)第.*?条(的)?规定|' \
                         r'(上述|以上)(违法)?(事实(行为)?|行为)(,)?违反了《中华人民共和国保险法》第.*?条(的)?规定|' \
                         r'上述行为违反了《保险营销员管理规定》第.*?条|' \
                         r'上述行为违反了中国保监会《人身保险新型产品信息披露管理办法》第八条的规定|' \
                         r'上述事实行为违反了《保险代理机构管理规定》(保监会令\[2004\]14号)第二条的规定|' \
                         r'上述行为违反了中国保监会《保险营销员管理规定》第三十六条|' \
                         r'上述(事实(行为)?|行为)违反了《保险兼业代理管理暂行办法》第.*?条(的)?规定|' \
                         r'上述(事实)?行为(分别)?违反了《保险代理机构管理规定》第.*?条(的)?(规定)?|' \
                         r'上述(事实)?行为(分别)?违反了《保险经纪机构管理规定》第.*?条(的)?规定|' \
                         r'上述(事实(行为)?|行为)违反了(中国保监会)?《保险营销员管理规定》第.*?条(的)?规定|' \
                         r'依据《保险营销员管理规定》第.*条规定|' \
                         r'上述事实行为违反了《机动车交通事故责任强制保险条例》第.*条规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(2).strip()
        else:
            truth_text_str = r'(' + litigant + r'\n)' \
                                               r'([\s\S]*?)' \
                                               r'(上述(违法)?事实,有.*?等证据(在案)?证明(在案)?(,|,)足以认定。|上述事实,有.*等证据证明|' \
                                               r'上述违法事实有.*?等证据在案证明,足以认定。|该违法事实,有.*?等证据在案证明,足以认定|' \
                                               r'该公司上述行为违反了《保险法》第一百一十六条:“保险公司及其工作人员在保险业务活动中不得有下列行为:|' \
                                               r'综上,决定给予你公司.*?的行政处罚|' \
                                               r'(上述|以上)(违法)?(事实(行为)?|行为)(,)?违反了《中华人民共和国保险法》(2002年修正)第.*?条(的)?规定|' \
                                               r'(上述|以上)(违法)?(事实(行为)?|行为)(,)?违反了《中华人民共和国保险法》第.*?条(的)?规定|' \
                                               r'上述行为违反了《保险营销员管理规定》第.*?条|' \
                                               r'上述行为违反了中国保监会《人身保险新型产品信息披露管理办法》第八条的规定|' \
                                               r'上述事实行为违反了《保险代理机构管理规定》(保监会令\[2004\]14号)第二条的规定|' \
                                               r'上述行为违反了中国保监会《保险营销员管理规定》第三十六条|' \
                                               r'上述(事实(行为)?|行为)行为违反了《保险兼业代理管理暂行办法》第.*?条(的)?规定|' \
                                               r'上述(事实)?行为(分别)?违反了《保险代理机构管理规定》第.*?条(的)?(规定)?|' \
                                               r'上述(事实)?行为(分别)?违反了《保险经纪机构管理规定》第.*?条(的)?规定|' \
                                               r'上述(事实(行为)?|行为)违反了(中国保监会)?《保险营销员管理规定》第.*?条(的)?规定|' \
                                               r'依据《保险营销员管理规定》第.*条规定|' \
                                               r'上述事实行为违反了《机动车交通事故责任强制保险条例》第.*条规定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(2).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|当事人[^,。,;\n]*?未提出陈述申辩意见|' \
                               r'[^,。,;\n]*?向我局(报送|递交)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核认为|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0]
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                defense_response = defense_response_compiler.search(
                    content_text).group(1).strip()
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据|依照).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|' \
                                       r'对.*?作出|拟对你|对.*?做出|对.*?予以)|' \
                                       r'我局(决定)?.*?(作|做)出(如下|以下)(行政)?处罚:|' \
                                       r'我局认为:\n.*?行为|' \
                                       r'综上,我局决定|' \
                                       r'我局决定:\n.*?根据|' \
                                       r'上述事实行为违反了《保险代理机构管理规定》第二十一条、二十二条的规定,决定给予你公司责令改正、责令停止接受新业务的行政处罚。)' \
                                       r'([\s\S]*?))' \
                                       r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|' \
                                       r'你公司如不服本处罚决定|请你.*?在接到本处罚决定书之日|如不服本处罚决定|请你公司在接到本处罚决定书之日|' \
                                       r'请.*?在接到本处罚决定书之日|如对本处罚决定不服)'
        punishment_decision_compiler = re.compile(punishment_decision_text_str,
                                                  re.MULTILINE)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;:]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)(违反|属).*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            r'该公司上述行为违反了《保险法》第一百一十六条:“保险公司及其工作人员在保险业务活动中不得有下列行为:(一)欺骗投保人、被保险人或者受益人……”',
            r'经查,你任国泰人寿保险有限责任公司天津分公司总经理期间.*?违反.*?条',
            r'2009年2月至6月通过费用报销套取现金.*?违反了.*?条规定',
            r'一、货物运输预约保险业务管理失控,业务、财务基础数据不真实,违反《中华人民共和国保险法》第八十六条;\n'
            r'二、虚假批单退费、虚列车辆使用费用,违反《中华人民共和国保险法》第八十六条;\n二、委托未取得合法代理资格的保险机构从事保险营销活动,违反《保险公司中介业务违法行为处罚办法》第十七条'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'[。\n;:]' + '(' + punishment_basis_str + ')' +
            r'.(\n?依据|\n?根据|\n?鉴于|\n.*?上述违法事实|\n二、|'
            r'本案现已审理终结。|\n?我局认为|\n?决定给予你公司责令改正|\n?依照)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(
                r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').replace(
                    r'*', r'\*') + r'([\s\S]*?)$',
            content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                      publish_date_text)[-1]
            m = re.match(
                "([0-9零一二两三四五六七八九十〇○]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(
                m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                      publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(
                int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '西藏银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('天津保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('天津保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('天津保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #24
0
def beijing_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '北京保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('北京保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find({
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url
        }).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket,
                         str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']},
                                    {'$set': {
                                        'status': 'parsed'
                                    }})
            file_id = db.parsed_data.find_one({
                'origin_url':
                announcement_url,
                'oss_file_origin_url':
                announcement_url
            })['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'(京银?保监罚(字)?.\d{4}.\d+号)')
        if '行政处罚信息' in title or '行政处罚披露' in title:
            litigant = re.search(r'行政处罚(信息披露|披露|信息)(.*?)$',
                                 title).group(2).strip()
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()
                publish_date_text = re.search(r'^.*?于(.*?)作出.*?处罚决定',
                                              content_text).group(1).strip()
                if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                    publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                              publish_date_text)[-1].replace(
                                                  ' ', '')
                    m = re.match(
                        "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                        publish_date)
                    real_publish_date = get_year(m.group(1)) + str(
                        cn2dig(m.group(2))) + '月' + str(cn2dig(
                            m.group(3))) + '日'
                else:
                    publish_date_text = table_content.find_all('tr')[1].text
                    publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                              publish_date_text)[-1]
                    real_publish_date = publish_date.split('-')[0] + '年' + str(
                        int(publish_date.split('-')[1])) + '月' + str(
                            int(publish_date.split('-')[2])) + '日'
            else:
                document_code = ''
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'
        else:
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                    r'.*?现场检查|我局查实|.*?(审核|调查过程中).*?发现|'
                    r'近期.*?存在违规行为|'
                    r'.*?进行了.*?专项检查|'
                    r'.*?我局依法.*?进行(现场)?(调查|检查)|'
                    r'.*?有效期至|'
                    r'.*?我局(收到|提交).*?申请材料|'
                    r'.*?存在.*?问题|'
                    r'你们于\n2008年3月31日\n向我局提交.*?申请材料|'
                    r'我局于|'
                    r'.{4}年.*?月|'
                    r'2007\n?年1月1\n?日|'
                    r'我局对你|'
                    r'我局依法对)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(
                        1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                    r'.*?现场检查|我局查实|.*?(审核|调查过程中).*?发现|'
                    r'近期.*?存在违规行为|'
                    r'.*?进行了.*?专项检查|'
                    r'.*?我局依法.*?进行(现场)?(调查|检查)|'
                    r'.*?有效期至|'
                    r'.*?我局(收到|提交).*?申请材料|'
                    r'.*?存在.*?问题|'
                    r'你们于\n2008年3月31日\n向我局提交.*?申请材料|'
                    r'我局于|'
                    r'.{4}年.*?月|'
                    r'2007\n?年1月1\n?日|'
                    r'我局对你|'
                    r'我局依法对)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()

            punishment_decision_text_str = r'(((依据|根据)[^。;\n]*?第[^。;\n]*?条[^。;\n]*?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对你处以)|' \
                                           r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                           r'依据\n《保险公司管理规定》\n第九十九条之规定,决定给予|据此,我局作出如下行政处罚|' \
                                           r'依据《保险经纪机构管理规定》(保监会令\[2004\]15号)133条的规定,我局决定|' \
                                           r'依据《保险法》143条规定,我局决定)' \
                                           r'([\s\S]*?))' \
                                           r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如.*?不服本处罚决定|' \
                                           r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|$|' \
                                           r'我局.*?送达|.*?应在收到本处罚决定书之日)'

            punishment_decision_compiler = re.compile(
                punishment_decision_text_str)
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(1).strip()

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(
                    r')', r'\)').replace(r'[', r'\[').replace(
                        r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1].replace(
                                              ' ', '')
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'

        truth_text_str = r'((经查)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(,|,)?(依据|根据).*?第.*?条|' \
                         r'我局[\s\S]*?送达|' \
                         r'以上问题有谈话笔录等材料为证。)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?[^,。,;\n]*?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r'(,|,|。|\n)(依据|根据).*?第.*?条|' \
                                        r'以上问题有谈话笔录等材料为证。)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(1).strip()
            else:
                truth = ''

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                               r'[^,。,;\n]*?(提交|提出)了(陈述)?申辩意见|' \
                               r'我局向.*?送达.*?提出|我局向你公司送达《行政处罚事先告知书》后,你公司对处罚事实提出了异议。|' \
                               r'[^,。,;\n]*?在陈述、申辩中(认为|表示)|' \
                               r'[^,。,;\n]*?在陈述、申辩中对违法事实的认定未提出异议|' \
                               r'在规定期限内.*?提出陈述和申辩|' \
                               r'[^,。,;\n]*?在陈述、申辩中未对我局认定的违规事实提出异议|' \
                               r'你公司对编制虚假资料等行为进行了申辩。|' \
                               r'[^,。,;\n]*?在陈述和申辩中未对我局认定的违规事实提出异议|' \
                               r'[^,。,;\n]*?在陈述和申辩中认为|' \
                               r'[^,。,;\n]*?在陈述和申辩中未对我局认定的违法违规事实提出异议|' \
                               r'[^,。,;\n]*?的陈述、申辩未对我局拟做出行政处罚的事实、理由及依据提出异议)' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况|' \
                               r'我局审核后认为|' \
                               r'我局复核后|' \
                               r'经研究,我局认为|' \
                               r'经核查|' \
                               r'对此,我局认为|' \
                               r'经复查|' \
                               r'经审查|' \
                               r'经复核|' \
                               r'经审核|' \
                               r'经核查|' \
                               r'经研究)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以|不再)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                          r'但陈述意见中部分客观情况可以作为情节予以考虑。|' \
                                                          r'因此,不再采纳你的申辩意见。|' \
                                                          r'因此不再重复考虑。|不予采纳。|' \
                                                          r'因此,我局不予采纳你的陈述、申辩意见。))'
                defense_response_compiler = re.compile(defense_response_str,
                                                       re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(
                        content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '(在规定期限内.*?未行使陈述权和申辩权,也未要求举行听证。|' \
                                   '在规定期限内.*?未进行陈述和申辩,也未申请听证。|' \
                                   '在规定期限内.*?未行使陈述权和申辩权。|' \
                                   '在规定期限内.*?未行使陈述权和申辩权,也未要求举行听证。|' \
                                   '在规定期限内.*?未提出陈述和申辩,也未要求举行听证。|' \
                                   '你公司在陈述、申辩中对我局认定的违规事实表示认可,未对处罚依据提出异议。|' \
                                   '在规定期限内.*?未进行陈述和申辩。|' \
                                   '在规定期限内.*?未陈述和申辩,也未申请听证。|' \
                                   '在规定期限内.*?未陈述和申辩。|' \
                                   '你于2010年12月9日提交了陈述和申辩书,又于2010年12月27日撤销了该陈述和申辩书,放弃行使陈述权和申辩权。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(
                    1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据)[^。;\n]*?第[^。;\n]*?条[^。;\n]*?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对你处以)|' \
                                       r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                       r'依据\n《保险公司管理规定》\n第九十九条之规定,决定给予|据此,我局作出如下行政处罚|' \
                                       r'依据《保险经纪机构管理规定》(保监会令\[2004\]15号)133条的规定,我局决定|' \
                                       r'依据《保险法》143条规定,我局决定)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如.*?不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|$|' \
                                       r'我局.*?送达|.*?应在收到本处罚决定书之日)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(
            content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反([^\n。\s]*?)第([^\n。\s]*?)条([\s\S]*?)',
            r'[^\n。;]*?违反了[^\n。;]*?第[^\n。;]*?条[^\n。;]*?'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile(
            r'(。|\n|;|^)' + '(' + punishment_basis_str + ')' +
            r'.(\n?依据|\n?根据|\n?鉴于|\n?我局[\s\S]*?送达)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join(
            [kk[1].strip() for kk in punishment_basis_list])

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '北京银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle': title,
                'oss_file_id': file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('北京保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('北京保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('北京保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #25
0
ファイル: hainan.py プロジェクト: wagaman/jgcf
def hainan_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '海南保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('海南保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        document_code_compiler = re.compile(r'((琼银?保监罚(字)?|琼银保监筹).\d{4}.\d+号)')
        if document_code_compiler.search(content_text):
            document_code = document_code_compiler.search(content_text).group(1).strip()
            litigant_compiler = re.compile(
                document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|'
                                    r'抽查|经抽查|.*?现场检查|现查明|'
                                    r'你公司于2007年承保的保单号为PMHU07013849|'
                                    r'你公司海口市府城镇中山路)')
            litigant = litigant_compiler.search(content_text).group(1).strip(). \
                replace('中国保监会海南监管局行政处罚决定书', '').strip()
        else:
            if document_code_compiler.search(title):
                document_code = document_code_compiler.search(title).group(1).strip()
            else:
                document_code = ''
            litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|.*?现场检查|现查明)')
            litigant = litigant_compiler.search(content_text).group(1).strip()

        truth_text_str = r'((经查|检查发现)' \
                         r'([\s\S]*?))' \
                         r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等(证据)?(在案)?证明(,|,|。)(足以认定。)?|' \
                         r'(我局认为,|综上,)?(上述|以上|你的).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                         r'(根据|依据).*?第.*?条|依据《保险法》规定)'
        truth_compiler = re.compile(truth_text_str)
        if truth_compiler.search(content_text):
            truth = truth_compiler.search(content_text).group(1).strip()
        else:
            truth_text_str = litigant + r'([\s\S]*?)' \
                                        r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                        r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                        r'(根据|依据).*?第.*?条|依据《保险法》规定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(1).strip()

        if '申辩' in content_text:
            defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                               r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                               r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                               r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                               r'([\s\S]*?))' \
                               r'(因此,我局决定|' \
                               r'我局经复核(认为|决定)|' \
                               r'本案现已审理终结|' \
                               r'我局经复查[^,。,;\n]*?情况|' \
                               r'我局[^,。,;\n]*?认真复核|' \
                               r'经研究,对[^,。,;\n]*?予以采纳。|' \
                               r'我局认为.*?申辩理由|' \
                               r'依据.*?我局认为.*?的申辩理由|' \
                               r'经研究,我局认为.*?申辩意见|' \
                               r'经我局审核,决定|' \
                               r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                               r'我局对陈述申辩意见进行了复核|' \
                               r'经我局审核|' \
                               r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                               r'经查,我局认为|' \
                               r'依据现场检查及听证情况)'
            defense_compiler = re.compile(defense_text_str, re.MULTILINE)
            defense_list = defense_compiler.findall(content_text)
            if len(defense_list) != 0:
                defense = defense_list[-1][0].strip()
                defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                       + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                          r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                          r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                if defense_response_compiler.search(content_text):
                    defense_response = defense_response_compiler.search(content_text).group(1).strip()
                else:
                    if '未' in defense:
                        defense_response = ''
            else:
                defense_text_str = '([^。;\n]*?向.*?公告送达了《行政处罚事先告知书》.*?提出陈述申辩。|' \
                                   '我局依法于2012年5月25日对你公司送达了《行政处罚事先告知书》,你公司在规定的时间内未提出陈述和申辩意见,也未要求举行听证。)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense = defense_compiler.search(content_text).group(1).strip()
                defense_response = ''
        else:
            defense = defense_response = ''

        punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对你)|' \
                                       r'我局决定.*?作出(如下|以下)(行政)?处罚:|我局决定,依据|' \
                                       r'你的上述行为违反了《中华人民共和国保险法》第一百七十三条规定,决定|' \
                                       r'依据《保险法》规定,我局决定)' \
                                       r'([\s\S]*?))' \
                                       r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                       r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|本处罚决定自送达之日|' \
                                       r'请在接到本处罚决定书之日)'

        punishment_decision_compiler = re.compile(punishment_decision_text_str)
        punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

        punishment_basis_str_list = [
            r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?.*?\n?.*?((的|之|等)(相关)?规定)?',
            r'你公司于2007年承保的保单号为PMHU07013849、06020200010008062007000175、06020200030008062007000082等交强险业务,'
            r'没有执行统一的基础保险费率,违反了《机动车交通事故责任强制保险条例》第六条的规定',
            r'你公司自2007年开业至2008年2月底,没有按照规定开设独立的客户资金专用账户,而是将在农业银行海口市金盘工业区分理处开设的基本存款账户'
            r'(账号:21164001040002867)用于代收客户资金及与保险机构之间的资金结算,还用于支付公司税金、员工的社会保险费用等,违反了《保险经纪机构管理规定》第八十八条规定',
            r'经查,中国人民人寿保险股份有限公司海南省分公司2008年1-8月承保团体年金B款业务,保费收入62193335元,'
            r'以赠送保险方式改变了产品条款中的退保、给付条件及金额且未向我局报备,违反了《保险法》第一百零七条第二款规定。'
            r'\n你作为中国人民人寿保险股份有限公司海南省分公司副总经理,分管团险业务,对该违规行为负有直接责任'
        ]
        punishment_basis_str = '|'.join(punishment_basis_str_list)
        punishment_basis_compiler = re.compile('[。\n;]' + '(' + punishment_basis_str + ')' +
                                               '.(\n?(我局决定,|我局)?依据|\n?根据|\n?鉴于|\n?上述违法事实)', re.MULTILINE)
        punishment_basis_list = punishment_basis_compiler.findall(content_text)
        punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

        publish_date_text = re.search(
            punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
            replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
        if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
            m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
        else:
            publish_date_text = table_content.find_all('tr')[1].text
            publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
            real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                int(publish_date.split('-')[2])) + '日'

        result_map = {
            'announcementTitle': title,
            'announcementOrg': '海南银保监局',
            'announcementDate': real_publish_date,
            'announcementCode': document_code,
            'facts': truth,
            'defenseOpinion': defense,
            'defenseResponse': defense_response,
            'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
            'punishmentBasement': punishment_basis,
            'punishmentDecision': punishment_decision,
            'type': '行政处罚决定',
            'oss_file_id': file_id,
            'status': 'not checked'
        }
        logger.info(result_map)
        if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('海南保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('海南保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('海南保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #26
0
ファイル: amac_parse.py プロジェクト: wagaman/jgcf
def amac_parse():
    for each_amac_document in db.amac_data.find({'status': {'$nin': ['ignored']}}):
        announcement_url = each_amac_document['url']
        announcement_title = each_amac_document['title']
        announcement_type = each_amac_document['type']

        if '关于注销期间届满未提交专项法律意见书私募基金管理人登记的公告' in announcement_title:
            logger.warning('无关数据')
            db.amac_data.update_one({'_id': each_amac_document['_id']}, {'$set': {'status': 'ignored'}})
            logger.info('证券业协会' + ' 重复数据' + ' -- 修改status完成')
            continue

        if db.amac_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and \
                db.parsed_data.find({'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
                                     'parsed': True}).count() == 1:
            continue

        logger.info('Url to parse: ' + announcement_url)

        response = request_site_page(announcement_url)
        if response is None:
            logger.error('网页请求错误')
            continue

        while response.status_code == 404:
            response = request_site_page(announcement_url)
            if response is None:
                logger.error('网页请求错误')
                continue

        content_soup = bs(response.content, 'lxml') if response else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_amac_document['_id'],
                'oss_file_type': 'shtml',
                'oss_file_name': announcement_title,
                'oss_file_content': response.text.encode(response.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.shtml',
                         response.text.encode(response.encoding).decode('utf-8'))
            db.amac_data.update_one({'_id': each_amac_document['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.amac_data.update_one({'_id': each_amac_document['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        if announcement_type == '纪律处分':
            td_content = content_soup.find(class_='iRight')
            title = td_content.find(class_='ldT').text.strip()
            content_text = td_content.find(class_='ldContent').text.strip()
            publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', content_text)[-1]
            m = re.match("([0-9零一二两三四五六七八九十〇]+年)?([0-9一二两三四五六七八九十]+)月?"
                         "([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
            real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            defense_opinion = defense_response = announcement_code = ''

            if '纪律处分决定书' in title:
                litigant = re.search(r'当事人[::]([\s\S]*?)(根据|经查明|\n\d{4}年\d+月)', content_text).group(2).strip()
                if re.search(r'一、基本事实[\s\S]*二、', content_text):
                    truth = re.search(r'一、基本事实([\s\S]*)二、', content_text).group(1).strip().replace('\n+', '\n')
                    decision = re.sub('、(纪律)?处分决定', '',
                                      re.search(r'、(纪律)?处分决定[\s\S]*?恢复.*?资产(支持专项|管理)计划备案。',
                                                content_text).group(0)).strip()
                else:
                    if re.search(r'根据中国证监会.*的通报.*应当负有主要责任。', content_text):
                        truth = re.search(r'根据中国证监会.*的通报.*应当负有主要责任。',
                                          content_text).group(0).strip().replace('\n+', '\n')
                        if re.search(r'鉴于本次纪律处分案的事实已经.*书面确认.*[协我]会决定作出以下纪律处分:'
                                     r'[\s\S]*需要重新参加基金从业资格考试', content_text):
                            decision = re.search(r'鉴于本次纪律处分案的事实已经.*书面确认.*[协我]会决定作出以下纪律处分:'
                                                 r'[\s\S]*需要重新参加基金从业资格考试',
                                                 content_text).group(0)
                        else:
                            decision = re.search(r'鉴于本次纪律处分案的事实已经.*书面确认.*协会决定作出以下纪律处分:.*',
                                                 content_text).group(0)
                    else:
                        if re.search(r'经查明.*存在以下(违法)?违规(情形|事实):[\s\S]*上述行为违反了', content_text):
                            truth = re.sub('\n.*上述行为违反了', '',
                                           re.search(r'经查明.*存在以下(违法)?违规(情形|事实):[\s\S]*上述行为违反了',
                                                     content_text).group(0))
                            decision = re.search(r'[本我]会决定:[\s\S]*上述纪律处分记入资本市场诚信档案。',
                                                 content_text).group(0)
                        else:
                            truth = re.search(r'我会据此直接作出纪律处分。([\s\S]*)三、', content_text).group(1).strip()
                            decision = re.search(r'、纪律处分决定([\s\S]*上述纪律处分记入资本市场诚信档案。)',
                                                 content_text).group(1).strip()
                punishment_basement = re.search(r'[。,]([^。,]*?情形违反.*?负有主要责任。)', content_text).group(2).strip()
            else:
                if '纪律处分复核决定书' in title:
                    announcement_code = re.search(r'(中基协复核〔\d+〕\d+号)\s*?申请人', content_text).group(1).strip()
                    litigant = re.search(r'(申请人:[\s\S]*?)申请人不服', content_text).group(1).strip()
                    truth = re.search(r'一、纪律处分情况([\s\S]*?)二、申辩意见', content_text).group(1).strip()
                    defense_opinion = re.search(r'二、申辩意见([\s\S]*?)三、复核意见', content_text).group(1).strip()
                    defense_response = re.search(r'三、复核意见([\s\S]*?)四、复核决定', content_text).group(1).strip()
                    decision = re.search(r'四、复核决定([\s\S]*?)\n\s*?中国证券投资基金业协会', content_text).group(1).strip()
                    punishment_basement = ''
                else:
                    litigant = re.search(r'关于注销(.*)私募基金管理人登记的公告', title).group(1).strip()
                    truth = re.search(r'现将有关情况公告如下:([\s\S]*)三、', content_text).group(1).strip()
                    punishment_basement = re.search(r'[。,]([^。,]*?情形违反.*?负有主要责任。)', content_text).group(2) \
                        .strip()
                    decision = re.search(r'、处理(决定|措施)([\s\S]*)特此公告。', content_text).group(2).strip()

            result_map = {
                'announcementTitle': title,
                'announcementDate': real_publish_date,
                'announcementOrg': '基金业协会',
                'announcementCode': announcement_code,
                'litigant': litigant,
                'facts': truth,
                'punishmentDecision': decision,
                'defenseOpinion': defense_opinion,
                'defenseResponse': defense_response,
                'type': '纪律处分',
                'punishmentBasement': punishment_basement,
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('基金业协会 纪律处分 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('基金业协会 纪律处分 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('基金业协会 纪律处分 数据解析 ' + ' -- 修改parsed完成')
        elif announcement_type == '不予登记':
            # 不予登记
            title = content_soup.find(class_='ldT').text.strip()
            content_tr = content_soup.find(class_='ldContent').find('tbody').find_all('tr')
            count = 0
            for each_tr in content_tr:  # 对表格每一行进行解析
                count += 1
                if count <= 2:  # 表格第一行为表格标题,第二行为表格各列表示的内容
                    continue
                else:  # 真实数据从第三行开始
                    all_info = each_tr.find_all('td')
                    litigant = all_info[0].text.strip() + "\n机构组织机构代码:" + all_info[1].text.strip()
                    publish_date = all_info[2].text.strip()
                    truth = all_info[3].text.strip() + "\n出具法律意见书的律师事务所:" \
                            + all_info[4].text.strip() + "\n经办律师姓名:" \
                            + all_info[5].text.strip().replace('\n', '、')
                    truth = truth.replace('\xa0', '').replace('\t', '')
                    m = re.search(r'(\d+)[-/](\d+)[-/](\d+)', publish_date)
                    real_publish_date = str(m.group(1)) + '年' + str(m.group(2)) + '月' + str(m.group(3)) + '日'

                result_map = {
                    'announcementTitle': title,
                    'announcementDate': real_publish_date,
                    'announcementOrg': '基金业协会',
                    'announcementCode': '',
                    'litigant': litigant,
                    'facts': truth,
                    'punishmentDecision': '不予登记',
                    'defenseOpinion': '',
                    'defenseResponse': '',
                    'type': '不予登记',
                    'punishmentBasement': '',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({'litigant': litigant, 'announcementDate': real_publish_date}).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('基金业协会 不予登记 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('基金业协会 不予登记 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': False}})
            logger.info('基金业协会 不予登记 数据解析 ' + ' -- 修改parsed完成')
        else:
            # 黑名单
            response = request_site_page(announcement_url)
            if response is None:
                logger.error('网页请求错误')
                continue
            base_soup = bs(response.content, 'lxml') if response else bs('', 'lxml')
            content_tr = base_soup.find(class_='ldContent').find('tbody').find_all('tr')
            title = base_soup.find(class_='ldT').text.strip()

            count_tr = 0
            for each_tr in content_tr:
                count_tr += 1
                if count_tr < 2:  # 第一行为表头,第二行后面才是数据
                    continue
                else:
                    count = 0  # count用于计算表格的列数
                    all_td = each_tr.find_all('td')

                    for each_td in all_td:
                        count += 1

                    publish_date = all_td[0].text.strip()
                    announcement_code = all_td[-1].text.strip()
                    m = re.search(r'(\d+)[-/](\d+)[-/](\d+)', publish_date)
                    real_publish_date = str(m.group(1)) + '年' + str(m.group(2)) + '月' + str(m.group(3)) + '日'

                    if count == 3:  # 表格有三列,说明无当事人姓名
                        litigant = all_td[1].text.strip()
                    else:  # 表格有四列,有当事人姓名
                        litigant = all_td[1].text.strip() + ',' + all_td[2].text.strip()

                result_map = {
                    'announcementTitle': title,
                    'announcementDate': real_publish_date,
                    'announcementOrg': '基金业协会',
                    'announcementCode': announcement_code,
                    'litigant': litigant,
                    'facts': '',
                    'punishmentDecision': '',
                    'defenseOpinion': '',
                    'defenseResponse': '',
                    'type': '黑名单',
                    'punishmentBasement': '',
                    'oss_file_id': file_id,
                    'status': 'not checked'
                }
                logger.info(result_map)
                if db.announcement.find({'litigant': litigant, 'oss_file_id': file_id}).count() == 0:
                    db.announcement.insert_one(result_map)
                    logger.info('基金业协会 黑名单 数据解析 ' + ' -- 数据导入完成')
                else:
                    logger.info('基金业协会 黑名单 数据解析 ' + ' -- 数据已经存在')
                db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                logger.info('基金业协会 黑名单 数据解析 ' + ' -- 修改parsed完成')
コード例 #27
0
ファイル: shantou.py プロジェクト: wagaman/jgcf
def shantou_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '汕头保监局'}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('汕头保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚事项' in title:
            continue
        else:
            document_code_compiler = re.compile(r'(汕银?保监罚.\d{4}.\d+号)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?有关规定|抽查'
                                        r'|经抽查|一、经查|一、 经查|'
                                        r'.*?我分局检查组对.*?进行了现场检查)')
                litigant = litigant_compiler.search(content_text).group(1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?有关规定|抽查|经抽查|一、经查|'
                                                                  r'.*?我分局检查组对.*?进行了现场检查|一、 经查)')
                litigant = litigant_compiler.search(content_text).group(1).strip()

            truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:)' \
                             r'([\s\S]*?)' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等.*?证明(,|,|。)(足以认定。)?|' \
                             r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                             r'.*?的行为.*?违反了.*?第.*?条的规定|' \
                             r'上述情况违反了.*?第.*?条)'
            truth_compiler = re.compile(truth_text_str)
            if truth_compiler.search(content_text):
                truth = truth_compiler.search(content_text).group(2).strip()
            else:
                truth_text_str = litigant + r'([\s\S]*?)' \
                                            r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                            r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                                   r'[^,。,;\n]*?向我分局提出陈述和申辩|你分公司在陈述申辩中称)' \
                                   r'([\s\S]*?))' \
                                   r'(经核查|经我分局核查)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0].strip()
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                              r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|(因此)?.*?申辩理由.*?成立。|' \
                                                              r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                    defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = '(我分局于.*?向你.*?送达.*?《行政处罚事先告知书》,(截至|截止)陈述申辩期满,我分局未收到你.*?的陈述和申辩。)'
                    defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据).*?第?.*?条.*?(规定)?.?.*?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                           r'我局经复核认为|我局决定.*?作出(如下|以下)(行政)?处罚:|' \
                                           r'根据《中华人民共和国保险法》第一百六十二的规定,我局责令)' \
                                           r'([\s\S]*?))' \
                                           r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                           r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|请当事人在接到本处罚决定书之日|' \
                                           r'当事人如不服本处罚决定|自接到本处罚决定书之日起)'

            punishment_decision_compiler = re.compile(punishment_decision_text_str)
            punishment_decision = punishment_decision_compiler.search(content_text).group(1).strip()

            punishment_basis_str_list = [
                r'([^\n。;、]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(r'[。\n;、]' + '(' + punishment_basis_str + ')' +
                                                   '.(\n?(应当)?依据|\n?根据|\n?鉴于|\n?我分局于)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(content_text)
            punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
                replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
                m = re.match("([0-9零一二两三四五六七八九十〇○OOΟ]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
                real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '汕头银保监分局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('汕头保监分局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('汕头保监分局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('汕头保监分局 数据解析 ' + ' -- 修改parsed完成')
コード例 #28
0
ファイル: zhejiang.py プロジェクト: wagaman/jgcf
def zhejiang_circ(db, logger):
    for each_circ_data in db.circ_data.find({
            'origin': '浙江保监局',
            'status': {
                '$nin': ['ignored']
            }
    }):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find({
                'url': announcement_url,
                'status': 'parsed'
        }).count() == 1 and db.parsed_data.find({
                'origin_url': announcement_url,
                'parsed': True
        }).count() == 1:
            continue

        logger.info('浙江保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue

        if '.doc' in content_text and len(
                table_content.find_all('tr')[3].find_all('a')) > 0:
            doc_link = urljoin(
                announcement_url,
                table_content.find_all('tr')[3].find('a').attrs['href'])
            file_response = request_site_page(doc_link)

            with open('./test/tmp.doc', 'wb') as f:
                f.write(file_response.content)
            if not os.path.exists('./test/tmp.docx'):
                shell_str = config['soffice']['soffice_path'] + ' --headless --convert-to docx ' + \
                            './test/tmp.doc' + ' --outdir ./test/'
                process = subprocess.Popen(shell_str.replace(r'(',
                                                             r'\(').replace(
                                                                 r')', r'\)'),
                                           shell=True,
                                           stdout=subprocess.PIPE)
                process.wait()

            with open('./test/tmp.docx', 'rb') as docx_file:
                docx_content = docx_file.read()

            if db.parsed_data.find({
                    'origin_url': announcement_url,
                    'oss_file_origin_url': doc_link
            }).count() == 0:
                oss_file_map = {
                    'origin_url': announcement_url,
                    'oss_file_origin_url': doc_link,
                    'origin_url_id': each_circ_data['_id'],
                    'oss_file_type': 'docx',
                    'oss_file_name': announcement_title,
                    'oss_file_content': docx_content,
                    'parsed': False
                }
                insert_response = db.parsed_data.insert_one(oss_file_map)
                file_id = insert_response.inserted_id
                oss_add_file(ali_bucket,
                             str(file_id) + '/' + announcement_title + '.docx',
                             docx_content)
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
            else:
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
                file_id = db.parsed_data.find_one({
                    'origin_url':
                    announcement_url,
                    'oss_file_origin_url':
                    doc_link
                })['_id']

            doc = docx.Document('./test/tmp.docx')
            full_text = []
            for para in doc.paragraphs:
                full_text.append(para.text)
            content_text = '\n'.join(full_text)

            logger.info('删除tmp文件')
            os.remove('./test/tmp.doc')
            os.remove('./test/tmp.docx')

            document_code_compiler = re.compile(
                r'(([浙温]保监罚|浙银保监筹?罚决字)\n?.\d{4}.\d+(-\d+)?\n?号\n)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'([\s\S]*?)\n' +
                    r'(经查|依据.*?有关规定|.*?进行了(现场|举报)检查|在.*?专项检查活动期间|我局对.*?检查过程中发现|'
                    r'.*?一案.*?现已调查终结|阳光人寿保险股份有限公司舟山中心支公司委托未取得合法资格的机构)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                document_code_compiler = re.compile(
                    r'(([浙温]保监罚|浙银保监筹罚决字|浙银保监罚决字).\d{4}.\d+(-\d+)?号)')
                if document_code_compiler.search(announcement_title):
                    document_code = document_code_compiler.search(
                        announcement_title).group(1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' +
                    r'(经查|依据.*?有关规定|.*?进行了(现场|举报)检查|在.*?专项检查活动期间|'
                    r'我局对.*?检查过程中发现)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()

            truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|违法事实和证据|违法事实和依据|' \
                             r'违规事实和证据|违法事实和证据|存在以下违法行为:|行政处罚的事实、理由及依据。)' \
                             r'([\s\S]*?)' \
                             r'((上述|以上)(违法)?事实(,|,)?有.*?等证据(材料)?证明(,|,|。)(足以认定。)?|' \
                             r'\n.*?行政处罚依据及(行政)?处罚决定|\n.*?行政处罚依据及拟作出的行政处罚|\n.*?处罚依据及处罚决定|' \
                             r'上述事实,有.*?等材料予以证实。|' \
                             r'(对此|据此).我局(决定)?作出(如|以)下(行政)?处罚(决定)?|' \
                             r'上述行为,违反了.*?第.*?条.*?的规定|根据.*?,我局决定作出以下行政处罚:|' \
                             r'上述行为违反了.*?第.*?条的规定.*对此负有直接责任|' \
                             r'\n.*?上述(事实)?行为.*?违反了.*?第.*?条.*?(的规定)?|' \
                             r'以上行为.*?违反了.*?的规定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(2).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|[^,。,;\n]*?提出.*?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:|当事人.*?书面.*?权利|' \
                                   r'当事人提出了陈述申辩|[^,。,;\n]*?递交了.*?|' \
                                   r'[^,。,;\n]*?提出了听证要求,我局依法举行了公开听证)' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核认为|' \
                                   r'现本案已审理终结|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'我局对陈述申辩意见进行了(复核|审核)|' \
                                   r'我局将另行依法处理。|' \
                                   r'我局对此进行了复核。|' \
                                   r'并对湖州银行股份有限公司的听证申辩意见和违法事实进行了审核)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0]
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'((.*?)' + r'(本案现已审理终结。|现本案已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                         r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                         r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                         r'我局将另行依法处理。))'
                    defense_response_compiler = re.compile(
                        defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(
                            content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(我局决定作出如下处罚:|综上,我局决定出如下处罚:|行政处罚依据及行政处罚决定|我局决定作出以下行政处罚:|' \
                                           r'行政处罚依据及处罚决定|行政处罚依据及拟作出的行政处罚|处罚依据及处罚决定|我局拟作出以下行政处罚:|' \
                                           r'我局作出以下行政处罚:|根据.*?第.*?条.*?规定,决定|综上,两项合计决定|依据.*?第.*?条.*?规定,决定|' \
                                           r'依据.*?第.*?条.*?规定,我局|我局决定作出以下行政处罚:|综上,合计|根据.*?第.*?条.*?规定.我局决定|' \
                                           r'我局决定作出如下行政处罚:|我局作出以下处罚决定:|我局决定作出如下行政处罚:|决定给予你单位以下行政处罚:)' \
                                           r'([\s\S]*?)' \
                                           r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|你公司如不服本处罚决定|' \
                                           r'\n.*?处罚的履行方式和期限|\n.*?如不服本行政处罚规定|当事人应在收到本处罚决定书之日|如不服本处罚决定)'
            punishment_decision_compiler = re.compile(
                punishment_decision_text_str, re.MULTILINE)
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(2).strip()

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
                r'上述行为,违反了考试纪律', r'上述行为,违反了考场纪律',
                r'上述行为违反了《保险营销员管理规定》第二十七条的规定',
                r'上述第\n1\n项行为违反了《中华人民共和国保险法》第一百一十六条第八项的规定,第\n2\n、\n3\n项行为违反了《中华人民共和国保险法》第八十六条的规定',
                r'上述第\n1\n项行为违反了《中华人民共和国保险法》第一百一十六条第八项的规定,第\n2\n项行为违反了《中华人民共和国保险法》第八十六条的规定'
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(
                r'[。\n;]' + '(' + punishment_basis_str + ')' +
                r'.(\n*?依据|\n*?根据|\n*?鉴于|另查明,中宏人寿保险股份有限公司宁波分公司)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(
                content_text)
            punishment_basis = ';'.join(
                [kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(
                    r')', r'\)').replace(r'[', r'\[').replace(
                        r']', r'\]').replace(r'*', r'\*') + r'([\s\S]*?)$',
                content_text).group(1).replace('\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1]
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': announcement_title,
                'announcementOrg': '浙江银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
        else:
            if db.parsed_data.find({
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url
            }).count() == 0:
                oss_file_map = {
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url,
                    'origin_url_id': each_circ_data['_id'],
                    'oss_file_type': 'html',
                    'oss_file_name': announcement_title,
                    'oss_file_content':
                    r.text.encode(r.encoding).decode('utf-8'),
                    'parsed': False
                }
                insert_response = db.parsed_data.insert_one(oss_file_map)
                file_id = insert_response.inserted_id
                oss_add_file(ali_bucket,
                             str(file_id) + '/' + announcement_title + '.html',
                             r.text.encode(r.encoding).decode('utf-8'))
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
            else:
                db.circ_data.update_one({'_id': each_circ_data['_id']},
                                        {'$set': {
                                            'status': 'parsed'
                                        }})
                file_id = db.parsed_data.find_one({
                    'origin_url':
                    announcement_url,
                    'oss_file_origin_url':
                    announcement_url
                })['_id']

            title = table_content.find_all('tr')[0].text.strip()
            document_code_compiler = re.compile(
                r'(([浙温]保监罚|浙银保监筹?罚决字).?\d{4}.?\d+(-\d+)?号\n)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(
                    content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'([\s\S]*?)\n' +
                    r'(经查|依据.*?有关规定|.*?进行了(现场|举报)检查|在.*?专项检查活动期间|我局对.*?检查过程中发现|'
                    r'.*?一案.*?现已调查终结|本局于 2012 年3月 26日作出)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()
            else:
                document_code_compiler = re.compile(
                    r'(([浙温]保监罚|浙银保监筹?罚决字).?\d{4}.?\d+(-\d+)?号)')
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(
                        1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' +
                    r'(经查|依据.*?有关规定|.*?进行了(现场|举报)检查|在.*?专项检查活动期间|'
                    r'我局对.*?检查过程中发现)')
                litigant = litigant_compiler.search(content_text).group(
                    1).strip()

            litigant = litigant.replace('行政处罚决定书', '').strip()

            truth_text_str = r'(经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|违法事实和证据|违法事实和依据|' \
                             r'违规事实和证据|违法事实和证据|存在以下违法行为:|行政处罚的事实、理由及依据。|本局于 2012 年3月 26日作出)' \
                             r'([\s\S]*?)' \
                             r'((上述|以上)(违法)?事实(,|,)?有.*?等证据(材料)?证明(,|,|。)(足以认定。)?|' \
                             r'\n.*?行政处罚依据及(行政)?处罚决定|\n.*?行政处罚依据及拟作出的行政处罚|\n.*?处罚依据及处罚决定|' \
                             r'上述事实,有.*?等材料予以证实。|' \
                             r'(对此|据此).我局(决定)?作出(如|以)下(行政)?处罚(决定)?|' \
                             r'上述行为,违反了.*?第.*?条.*?的规定|根据.*?,我局决定作出以下行政处罚:|' \
                             r'上述行为违反了.*?第.*?条的规定.*对此负有直接责任|' \
                             r'\n.*?上述(事实)?行为.*?违反了.*?第.*?条.*?(的规定)?|' \
                             r'以上行为.*?违反了.*?的规定|' \
                             r'上述事实的证据材料主要有.*?等。证据充分,足以认定。|' \
                             r'上述违法事实有.*?等(证据材料|材料)。证据充分,足以认定。|' \
                             r'依据《中华人民共和国行政强制法》第五十四条的规定)'
            truth_compiler = re.compile(truth_text_str)
            truth = truth_compiler.search(content_text).group(2).strip()

            if '申辩' in content_text:
                if announcement_url in [
                        'http://zhejiang.circ.gov.cn/web/site39/tab3594/info209781.htm'
                ]:
                    defense = defense_response = ''
                else:
                    defense_text_str = r'((针对.*?行为.*?申辩意见|[^,。,;\n]*?提出.*?陈述申辩(意见)?|' \
                                       r'[^,。,;\n]*?向我局(报送|递交)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                       r'[^,。,;\n]*?在(申辩材料|陈述申辩)中称:|当事人.*?书面.*?权利|' \
                                       r'当事人提出了陈述申辩|[^,。,;\n]*?递交了.*?|' \
                                       r'[^,。,;\n]*?提出了听证要求,我局依法举行了公开听证)' \
                                       r'([\s\S]*?))' \
                                       r'(因此,我局决定|' \
                                       r'我局经复核认为|' \
                                       r'现本案已审理终结|' \
                                       r'本案现已审理终结|' \
                                       r'我局经复查[^,。,;\n]*?情况|' \
                                       r'我局[^,。,;\n]*?认真复核|' \
                                       r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                       r'我局认为.*?申辩理由|' \
                                       r'依据.*?我局认为.*?的申辩理由|' \
                                       r'经研究,我局认为.*?申辩意见|' \
                                       r'我局对陈述申辩意见进行了(复核|审核)|' \
                                       r'我局将另行依法处理。|' \
                                       r'我局对此进行了复核。|' \
                                       r'并对湖州银行股份有限公司的听证申辩意见和违法事实进行了审核)'
                    defense_compiler = re.compile(defense_text_str,
                                                  re.MULTILINE)
                    defense_list = defense_compiler.findall(content_text)
                    if len(defense_list) != 0:
                        defense = defense_list[-1][0]
                        defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                               + r'(([\s\S]*?)' + r'(本案现已审理终结。|现本案已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                                  r'对[^,。,;\n]*?申辩意见(不予|予以)采纳。|因此.*?申辩理由.*?成立。|' \
                                                                  r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?|' \
                                                                  r'我局将另行依法处理。))'
                        defense_response_compiler = re.compile(
                            defense_response_str, re.MULTILINE)
                        if defense_response_compiler.search(content_text):
                            defense_response = defense_response_compiler.search(
                                content_text).group(1).strip()
                        else:
                            if '未' in defense:
                                defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据)[^。;\n]*?第?[^。;\n]*?条' \
                                           r'[^。;\n]*?(规定)?.?(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你|对.*?予以)|' \
                                           r'我局经复核认为|我局(决定|拟)?.*?作出(如下|以下)(行政)?处罚|' \
                                           r'综上,合计拟对你公司|' \
                                           r'根据《中国保险监督管理委员会行政处罚程序规定》,决定给予|' \
                                           r'依据《中华人民共和国行政强制法》第五十四条的规定,现依法向你催告)' \
                                           r'([\s\S]*?))' \
                                           r'(当事人应当在接到本处罚决定书之日|当事人如对本处罚决定不服|本处罚决定书自送达之日起执行|你公司如不服本处罚决定|' \
                                           r'\n.*?处罚的履行方式和期限|\n.*?如不服本行政处罚规定|当事人应在收到本处罚决定书之日|如不服本处罚决定|收到本催告书后)'
            punishment_decision_compiler = re.compile(
                punishment_decision_text_str, re.MULTILINE)
            punishment_decision = punishment_decision_compiler.search(
                content_text).group(1).strip()

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)违反.*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
                r'上述行为,违反了考试纪律', r'上述行为违反了《保险营销员管理规定》第二十七条的规定',
                r'上述行为,致使富瑞得代理所提交的2005年4季度、2006年3季度等监管报表为虚假报表, 违反了《保险代理机构管理规定》第一百零七条的规定。颜坤良作为公司负责人对公司的违法行为负有直接责任',
                r'以上行为,违反了《浙江省保险代理从业人员资格考试考场纪律》的规定'
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(
                r'[。\n;]' + '(' + punishment_basis_str + ')' +
                r'.(\n*?依据|\n*?根据|\n*?鉴于|另查明,中宏人寿保险股份有限公司宁波分公司|\n?为此,我局决定作出)',
                re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(
                content_text)
            punishment_basis = ';'.join(
                [kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(r'\n(.*?)$',
                                          content_text).group(1).replace(
                                              '\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日',
                                          publish_date_text)[-1]
                m = re.match(
                    "([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                    publish_date)
                real_publish_date = get_year(m.group(1)) + str(
                    cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}',
                                          publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                        int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '浙江银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
        logger.info(result_map)
        if db.announcement.find({
                'announcementTitle':
                result_map['announcementTitle'],
                'oss_file_id':
                file_id
        }).count() == 0:
            db.announcement.insert_one(result_map)
            logger.info('浙江保监局 数据解析 ' + ' -- 数据导入完成')
        else:
            logger.info('浙江保监局 数据解析 ' + ' -- 数据已经存在')
        db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
        logger.info('浙江保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #29
0
ファイル: guizhou.py プロジェクト: wagaman/jgcf
def guizhou_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '贵州保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url,
             'parsed': True}).count() == 1:
            continue

        logger.info('贵州保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        if db.parsed_data.find(
                {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
            oss_file_map = {
                'origin_url': announcement_url,
                'oss_file_origin_url': announcement_url,
                'origin_url_id': each_circ_data['_id'],
                'oss_file_type': 'html',
                'oss_file_name': announcement_title,
                'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                'parsed': False
            }
            insert_response = db.parsed_data.insert_one(oss_file_map)
            file_id = insert_response.inserted_id
            oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                         r.text.encode(r.encoding).decode('utf-8'))
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
        else:
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                               'oss_file_origin_url': announcement_url})['_id']

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if '行政处罚事项' in title:
            sub_table_content = table_content.find_all('tr')[3].find_all('table')[0]
            result_map_list = []
            for tr in sub_table_content.find_all('tr'):
                if '行政处罚公开信息' not in tr.text and '行政处罚事项' not in tr.text and '处罚决定文号' not in tr.text and \
                        len(tr.find_all('td')) > 1 and tr.find_all('td')[0].text != tr.find_all('td')[1].text:
                    real_title = '贵州银保监局行政处罚决定书(' + tr.find_all('td')[0].text + ')'
                    real_publish_date = tr.find_all('td')[2].text.split('-')[0] + '年' + \
                                        tr.find_all('td')[2].text.split('-')[1] + '月' + \
                                        tr.find_all('td')[2].text.split('-')[2] + '日'

                    result_map = {
                        'announcementTitle': real_title,
                        'announcementOrg': '贵州银保监局',
                        'announcementDate': real_publish_date,
                        'announcementCode': tr.find_all('td')[0].text,
                        'facts': tr.find_all('td')[1].text + tr.find_all('td')[6].text,
                        'defenseOpinion': '',
                        'defenseResponse': '',
                        'litigant': tr.find_all('td')[1].text,
                        'punishmentBasement': tr.find_all('td')[1].text + '上述行为违反了' + tr.find_all('td')[4].text,
                        'punishmentDecision': '依据' + tr.find_all('td')[5].text + ',' + '我局对' + tr.find_all('td')[
                            1].text +
                                              '作出以下处罚:' + tr.find_all('td')[3].text,
                        'type': '行政处罚决定',
                        'oss_file_id': file_id,
                        'status': 'not checked'
                    }
                    logger.info(result_map)
                    if db.announcement.find({'announcementTitle': real_title, 'oss_file_id': file_id}).count() == 0:
                        db.announcement.insert_one(result_map)
                        logger.info('贵州保监局 数据解析 ' + ' -- 数据导入完成')
                    else:
                        logger.info('贵州保监局 数据解析 ' + ' -- 数据已经存在')
                    result_map_list.append(result_map)

            if len(result_map_list) > 0:
                db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                logger.info('贵州保监局 数据解析 ' + ' -- 修改parsed完成')
            else:
                logger.info('贵州保监局 数据解析 ' + ' -- 没有数据')
        else:
            document_code_compiler = re.compile(r'(黔保监罚字.\d{4}.\d+.*?号)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|'
                                        r'.*?存在.*?行为|.*进行检查|我局.*?检查时|'
                                        r'.*?经营活动|经核查|.*?进行了核查|'
                                        r'.*?担任.*?期间|'
                                        r'.*?未经我局批准,擅自|'
                                        r'你公司未经保险监管部门批准)')
                litigant = litigant_compiler.search(content_text).group(1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(1).strip()
                    litigant_compiler = re.compile(r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|抽查|经抽查|.*?存在.*?行为|'
                                                                      r'.*进行检查|我局.*?检查时|.*?担任.*?期间|你公司未经保险监管部门批准|'
                                                                      r'.*?经营活动|经核查|.*?进行了核查|.*?未经我局批准,擅自)')
                    litigant = litigant_compiler.search(content_text).group(1).strip()
                else:
                    document_code = ''
                    litigant_compiler = re.compile(r'行政处罚信息.(.*?).$')
                    litigant = litigant_compiler.search(title).group(1).strip()

            truth_text_str = r'((经查|二、|三、|经核查)' \
                             r'([\s\S]*?))' \
                             r'((我局认为,)?(上述|以上).*?(事实|行为|问题)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                             r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                             r'违反|依据|上述行为违反了)'
            truth_compiler = re.compile(truth_text_str)
            truth_list = truth_compiler.findall(content_text)
            if len(truth_list) > 0:
                truth = '\n'.join([each_truth[0] for each_truth in truth_list])
            else:
                truth_text_str = litigant.replace(r'*', r'\*') + \
                                 r'([\s\S]*?)' \
                                 r'((我局认为,)?(上述|以上).*?(事实|行为|事实)(,|,)?有.*?等证据(在案)?证明(,|,|。)(足以认定。)?|' \
                                 r'(我局认为,|综上,)?(上述|以上).*?(行为|问题|事实).*?违反.*?第.*条.*?(的规定)?|' \
                                 r'上述行为违反了|依据《中华人民共和国保险法》第一百零九条、第一百三十七条、第一百四十七条的规定|' \
                                 r'依据《保险法》第一百四十四条的规定)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'[^,。,;\n]*?向我局(报送|递交|提出)[^,。,;\n]*?|本案在审理过程中.*?提出陈述申辩|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求))' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核(认为|决定)|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'经我局审核,决定|' \
                                   r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                   r'我局对陈述申辩意见进行了复核|' \
                                   r'经我局审核|' \
                                   r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                   r'经查,我局认为|' \
                                   r'依据现场检查及听证情况|' \
                                   r'对上述陈述申辩意见,我局认为)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0]
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]') \
                                           + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                              r'对[^,。,;\n]*?申辩意见(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                              r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                    defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = r'(你公司在陈述申辩意见中未对违法事实、处罚理由及依据提出异议。|' \
                                       r'你公司在规定期限内未提出陈述申辩意见。|' \
                                       r'你机构在陈述申辩意见中未对违法事实、处罚理由及依据提出异议。|' \
                                       r'你公司及陆忠豪在规定期限内未提出陈述申辩意见。|' \
                                       r'你在规定期限内未提出陈述申辩意见。|' \
                                       r'[^,。,;\n]*?在规定期限内未提出陈述申辩意见。|' \
                                       r'你在规定期限内未要求听证,也未提出陈述申辩意见。|' \
                                       r'可在收到本告知书之日起10日内向我局提交书面的陈述书和申辩书。逾期视为放弃陈述和申辩。)'
                    defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((依据|根据|依照)[^。\n]*?第[^。\n]*?条[^。\n]*?(规定)?.?' \
                                           r'(我局)?(决定|责令|给予|于.*?向.*?发出|对.*?作出|拟对你)|' \
                                           r'我局经复核认为|我局(决定)?.*?作出(如下|以下)(行政)?(处罚)?处罚)' \
                                           r'([\s\S]*?))' \
                                           r'(请在本处罚决定书送达之日|当事人应当在接到本处罚决定书之日|如不服本处罚决定|' \
                                           r'请(在)?接到本处罚决定书之日|如不服从本处罚决定|$|当事人应当在本处罚决定书送达之日|' \
                                           r'请你在本处罚决定书送达之日|请.*?在接到本处罚决定书之日|' \
                                           r'请.*?在本处罚决定书送达之日|请在接到本处罚决定之日|如你支公司对我局认定的违法事实)'

            punishment_decision_compiler = re.compile(punishment_decision_text_str)
            punishment_decision_list = punishment_decision_compiler.findall(content_text)
            punishment_decision = '\n'.join(
                [each_punishment_decision[0] for each_punishment_decision in punishment_decision_list])

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)[^。;]*?违反[^。;]*?第.*?条.*?((的|之|等)(相关)?规定)?',
                r'华安财险贵州分公司聘任不具有任职资格的人员违反了《保险法》八十一条第一款、第二款和《任职资格规定》第四条第(三)项、第(五)项的规定',
                r'人保财险印江支公司强制投保人订立商业保险合同违反了《交强险条例》第十三条第二款',
                r'上述行为违反了《中华人民共和国保险法》第一百二十二条和第一百三十四条的规定',
                r'上述行为违反了《中华人民共和国保险法》八十六条',
                r'经查,你公司于2006年7月1日至9月30日期间,通过弄虚作假套取现金支付非法代理及相关人员手续费24.9万元,违反了《中华人民共和国保险法》第一百二十二条和第一百三十四条的规定',
                r'你支公司于2005年11月15日,未经我局批准,擅自将支公司及下辖南北大街营销服务部分别由我局批设地址镇宁县城关李家井8号、'
                r'镇宁县南北大街黄果树商城内迁至镇宁县南北大街中段中国农业发展银行镇宁县支行办公大楼二楼,违反了《保险法》第八十二条的规定'
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile('(。|\n|;|^)' + '(' + punishment_basis_str + ')' +
                                                   '.(\n?依据|\n?根据|\n?鉴于|\n?依照)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(content_text)
            punishment_basis = ';'.join([kk[1].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision.replace(r'(', r'\(').replace(r')', r'\)').replace(r'[', r'\[').replace(r']', r'\]').
                replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace('\n', '')

            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1].replace(' ', '')
                m = re.match("([0-9零一二两三四五六七八九十〇○OOΟО]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?",
                             publish_date)
                real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(
                    cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(
                    int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '贵州银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find({'announcementTitle': title, 'oss_file_id': file_id}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('贵州保监局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('贵州保监局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('贵州保监局 数据解析 ' + ' -- 修改parsed完成')
コード例 #30
0
ファイル: hunan.py プロジェクト: wagaman/jgcf
def hunan_circ(db, logger):
    for each_circ_data in db.circ_data.find({'origin': '湖南保监局', 'status': {'$nin': ['ignored']}}):
        announcement_url = each_circ_data['url']
        announcement_title = each_circ_data['title']

        if '行政处罚实施情况' in announcement_title or '行政处罚及其他监管措施实施情况通报' in announcement_title:
            logger.warning(announcement_url + ' ' + announcement_title + ' 与监管处罚无关')
            db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'ignored'}})
            logger.info('湖南保监局' + ' 无关数据' + ' -- 修改status完成')
            continue

        if db.circ_data.find(
                {'url': announcement_url, 'status': 'parsed'}).count() == 1 and db.parsed_data.find(
            {'origin_url': announcement_url, 'parsed': True}).count() == 1:
            continue

        logger.info('湖南保监局 ' + 'Url to parse: %s' % announcement_url)

        r = request_site_page(announcement_url)
        if r is None:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_soup = bs(r.content, 'lxml') if r else bs('', 'lxml')

        table_content = content_soup.find(id='tab_content')
        if not table_content:
            logger.error('网页请求错误 %s' % announcement_url)
            continue
        content_text = get_content_text(table_content.find_all('tr')[3])
        if content_text == '':
            continue
        title = table_content.find_all('tr')[0].text.strip()

        if content_text == '无':
            continue

        if '行政处罚公开信息' in title or '行政处罚事项' in title:
            if '.doc' in content_text:
                doc_link = urljoin(announcement_url, table_content.find_all('tr')[3].find('a').attrs['href'])
                response = request_site_page(doc_link)

                with open('./test/tmp.doc', 'wb') as f:
                    f.write(response.content)
                if not os.path.exists('./test/tmp.docx'):
                    shell_str = config['soffice']['soffice_path'] + ' --headless --convert-to docx ' + \
                                './test/tmp.doc' + ' --outdir ./test/'
                    process = subprocess.Popen(shell_str.replace(r'(', r'\(').replace(r')', r'\)'),
                                               shell=True, stdout=subprocess.PIPE)
                    process.wait()

                with open('./test/tmp.docx', 'rb') as docx_file:
                    docx_content = docx_file.read()

                if db.parsed_data.find(
                        {'origin_url': announcement_url, 'oss_file_origin_url': doc_link}).count() == 0:
                    oss_file_map = {
                        'origin_url': announcement_url,
                        'oss_file_origin_url': doc_link,
                        'origin_url_id': each_circ_data['_id'],
                        'oss_file_type': 'docx',
                        'oss_file_name': announcement_title,
                        'oss_file_content': docx_content,
                        'parsed': False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.docx', docx_content)
                    db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
                    file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                                       'oss_file_origin_url': doc_link})['_id']

                doc = docx.Document('./test/tmp.docx')
                result_map_list = []
                tables = doc.tables
                for table in tables:
                    for row in table.rows:
                        if len(row.cells) == 7 and row.cells[0].text != '序号':
                            real_title = '湖南银保监局行政处罚决定书(' + row.cells[2].text + ')'
                            result_map = {
                                'announcementTitle': real_title,
                                'announcementOrg': '湖南银保监局',
                                'announcementDate': '2007年' + row.cells[1].text if '2007' in row.cells[
                                    2].text else '2008年' + row.cells[1].text,
                                'announcementCode': row.cells[2].text,
                                'facts': '',
                                'defenseOpinion': '',
                                'defenseResponse': '',
                                'litigant': row.cells[3].text,
                                'punishmentBasement': row.cells[3].text + '上述行为违反了' + row.cells[3].text,
                                'punishmentDecision': '依据' + row.cells[5].text + ',' + '我局对' + row.cells[
                                    3].text + '作出以下处罚:' + row.cells[6].text,
                                'type': '行政处罚决定',
                                'oss_file_id': file_id,
                                'status': 'not checked'
                            }
                            logger.info(result_map)
                            if db.announcement.find(
                                    {'announcementTitle': result_map['announcementTitle'],
                                     'oss_file_id': file_id,
                                     'litigant': result_map['litigant']}).count() == 0:
                                db.announcement.insert_one(result_map)
                                logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
                            else:
                                logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
                            result_map_list.append(result_map)
                if len(result_map_list) > 0:
                    db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                    logger.info('湖南保监局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.warning('湖南保监局 数据解析 ' + ' -- 未解析完成')

                logger.info('删除tmp文件')
                os.remove('./test/tmp.doc')
                os.remove('./test/tmp.docx')
            else:
                if db.parsed_data.find(
                        {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
                    oss_file_map = {
                        'origin_url': announcement_url,
                        'oss_file_origin_url': announcement_url,
                        'origin_url_id': each_circ_data['_id'],
                        'oss_file_type': 'html',
                        'oss_file_name': announcement_title,
                        'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                        'parsed': False
                    }
                    insert_response = db.parsed_data.insert_one(oss_file_map)
                    file_id = insert_response.inserted_id
                    oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                                 r.text.encode(r.encoding).decode('utf-8'))
                    db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
                else:
                    db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
                    file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                                       'oss_file_origin_url': announcement_url})['_id']

                out_table_content = table_content
                table_content = table_content.find_all('tr')[3].find('table')
                result_map_list = []
                static_tr = table_content.find_all('tr')[0]
                for tr in table_content.find_all('tr'):
                    if '行政处罚公开信息' not in tr.text and '行政处罚事项' not in tr.text and '文书编号' not in tr.text and \
                            len(tr.find_all('td')) > 1 and tr.find_all('td')[0].text != tr.find_all('td')[1].text:
                        if len(tr.find_all('td')) == 7:
                            if len(tr.find_all('td')) == len(static_tr.find_all('td')):
                                real_title = '湖南银保监局行政处罚决定书(' + tr.find_all('td')[1].text + ')'
                                if '/' in tr.find_all('td')[0].text:
                                    publish_date = tr.find_all('td')[0].text.split('/')[0] + '年' + \
                                                   tr.find_all('td')[0].text.split('/')[1] + '月' + \
                                                   tr.find_all('td')[0].text.split('/')[2] + '日'
                                else:
                                    publish_date = tr.find_all('td')[0].text.split('-')[0] + '年' + \
                                                   tr.find_all('td')[0].text.split('-')[1] + '月' + \
                                                   tr.find_all('td')[0].text.split('-')[2] + '日'

                                result_map = {
                                    'announcementTitle': real_title,
                                    'announcementOrg': '湖南银保监局',
                                    'announcementDate': publish_date,
                                    'announcementCode': tr.find_all('td')[1].text,
                                    'facts': tr.find_all('td')[2].text + tr.find_all('td')[3].text,
                                    'defenseOpinion': '',
                                    'defenseResponse': '',
                                    'litigant': tr.find_all('td')[2].text,
                                    'punishmentBasement': tr.find_all('td')[2].text + '上述行为违反了' + tr.find_all('td')[
                                        4].text,
                                    'punishmentDecision': '依据' + tr.find_all('td')[5].text + ',' + '我局对' +
                                                          tr.find_all('td')[
                                                              2].text + '作出以下处罚:' + tr.find_all('td')[6].text,
                                    'type': '行政处罚决定',
                                    'oss_file_id': file_id,
                                    'status': 'not checked'
                                }
                                static_tr = tr
                                if db.announcement.find_all(
                                        {'announcementTitle': result_map['announcementTitle'],
                                         'oss_file_id': file_id,
                                         'litigant': result_map['litigant']}).count() == 0:
                                    db.announcement.insert_one(result_map)
                                    logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
                                else:
                                    logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
                                result_map_list.append(result_map)
                            else:
                                if len(static_tr.find_all('td')) - len(tr.find_all('td')) == 2:
                                    real_title = '湖南银保监局行政处罚决定书(' + static_tr.find_all('td')[1].text + ')'
                                    if '/' in static_tr.find_all('td')[0].text:
                                        publish_date = static_tr.find_all('td')[0].text.split('/')[0] + '年' + \
                                                       static_tr.find_all('td')[0].text.split('/')[1] + '月' + \
                                                       static_tr.find_all('td')[0].text.split('/')[2] + '日'
                                    else:
                                        publish_date = static_tr.find_all('td')[0].text.split('-')[0] + '年' + \
                                                       static_tr.find_all('td')[0].text.split('-')[1] + '月' + \
                                                       static_tr.find_all('td')[0].text.split('-')[2] + '日'
                                    result_map = {
                                        'announcementTitle': real_title,
                                        'announcementOrg': '湖南银保监局',
                                        'announcementDate': publish_date,
                                        'announcementCode': static_tr.find_all('td')[1].text,
                                        'facts': tr.find_all('td')[0].text + tr.find_all('td')[1].text,
                                        'litigant': tr.find_all('td')[0].text,
                                        'punishmentBasement': tr.find_all('td')[0].text + '上述行为违反了' + tr.find_all('td')[
                                            2].text,
                                        'punishmentDecision': '依据' + tr.find_all('td')[3].text + ',' + '我局对' +
                                                              tr.find_all('td')[
                                                                  0].text + '作出以下处罚:' + tr.find_all('td')[4].text,
                                        'type': '行政处罚决定',
                                        'oss_file_id': file_id,
                                        'status': 'not checked',
                                        'defenseOpinion': '',
                                        'defenseResponse': ''
                                    }
                                    if db.announcement.find_all(
                                            {'announcementTitle': result_map['announcementTitle'],
                                             'oss_file_id': file_id,
                                             'litigant': result_map['litigant']}).count() == 0:
                                        db.announcement.insert_one(result_map)
                                        logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
                                    else:
                                        logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
                                    result_map_list.append(result_map)
                                else:
                                    real_title = '湖南银保监局行政处罚决定书(' + static_tr.find_all('td')[1].text + ')'
                                    if '/' in static_tr.find_all('td')[0].text:
                                        publish_date = static_tr.find_all('td')[0].text.split('/')[0] + '年' + \
                                                       static_tr.find_all('td')[0].text.split('/')[1] + '月' + \
                                                       static_tr.find_all('td')[0].text.split('/')[2] + '日'
                                    else:
                                        publish_date = static_tr.find_all('td')[0].text.split('-')[0] + '年' + \
                                                       static_tr.find_all('td')[0].text.split('-')[1] + '月' + \
                                                       static_tr.find_all('td')[0].text.split('-')[2] + '日'
                                    result_map = {
                                        'announcementTitle': real_title,
                                        'announcementOrg': '湖南银保监局',
                                        'announcementDate': publish_date,
                                        'announcementCode': static_tr.find_all('td')[1].text,
                                        'facts': static_tr.find_all('td')[2].text + tr.find_all('td')[0].text,
                                        'litigant': static_tr.find_all('td')[2].text,
                                        'punishmentBasement': static_tr.find_all('td')[2].text + '上述行为违反了' +
                                                              tr.find_all('td')[
                                                                  1].text,
                                        'punishmentDecision': '依据' + tr.find_all('td')[2].text + ',' + '我局对' +
                                                              static_tr.find_all('td')[2].text +
                                                              '作出以下处罚:' + tr.find_all('td')[3].text,
                                        'type': '行政处罚决定',
                                        'oss_file_id': file_id,
                                        'status': 'not checked',
                                        'defenseOpinion': '',
                                        'defenseResponse': ''
                                    }
                                    if db.announcement.find_all(
                                            {'announcementTitle': result_map['announcementTitle'],
                                             'oss_file_id': file_id,
                                             'litigant': result_map['litigant']}).count() == 0:
                                        db.announcement.insert_one(result_map)
                                        logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
                                    else:
                                        logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
                                    result_map_list.append(result_map)
                        else:
                            if len(tr.find_all('td')) == len(static_tr.find_all('td')):
                                real_title = '湖南银保监局行政处罚决定书(' + tr.find_all('td')[0].text + ')'
                                publish_date_text = out_table_content.find_all('tr')[1].text
                                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                                real_publish_date = publish_date.split('-')[0] + '年' + str(
                                    int(publish_date.split('-')[1])) + '月' + str(
                                    int(publish_date.split('-')[2])) + '日'
                                result_map = {
                                    'announcementTitle': real_title,
                                    'announcementOrg': '湖南银保监局',
                                    'announcementDate': real_publish_date,
                                    'announcementCode': tr.find_all('td')[0].text,
                                    'facts': tr.find_all('td')[1].text + tr.find_all('td')[2].text,
                                    'litigant': tr.find_all('td')[1].text,
                                    'punishmentBasement': tr.find_all('td')[1].text + '上述行为违反了' + tr.find_all('td')[
                                        3].text,
                                    'punishmentDecision': '依据' + tr.find_all('td')[4].text + ',' + '我局对' +
                                                          tr.find_all('td')[
                                                              1].text + '作出以下处罚:' + tr.find_all('td')[5].text,
                                    'type': '行政处罚决定',
                                    'oss_file_id': file_id,
                                    'status': 'not checked',
                                    'defenseOpinion': '',
                                    'defenseResponse': ''
                                }
                                static_tr = tr
                                if db.announcement.find_all(
                                        {'announcementTitle': result_map['announcementTitle'],
                                         'oss_file_id': file_id,
                                         'litigant': result_map['litigant']}).count() == 0:
                                    db.announcement.insert_one(result_map)
                                    logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
                                else:
                                    logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
                                result_map_list.append(result_map)
                    else:
                        static_tr = tr
                if len(result_map_list) > 0:
                    db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
                    logger.info('湖南保监局 数据解析 ' + ' -- 修改parsed完成')
                else:
                    logger.warning('湖南保监局 数据解析 ' + ' -- 无数据')
        else:
            if db.parsed_data.find(
                    {'origin_url': announcement_url, 'oss_file_origin_url': announcement_url}).count() == 0:
                oss_file_map = {
                    'origin_url': announcement_url,
                    'oss_file_origin_url': announcement_url,
                    'origin_url_id': each_circ_data['_id'],
                    'oss_file_type': 'html',
                    'oss_file_name': announcement_title,
                    'oss_file_content': r.text.encode(r.encoding).decode('utf-8'),
                    'parsed': False
                }
                insert_response = db.parsed_data.insert_one(oss_file_map)
                file_id = insert_response.inserted_id
                oss_add_file(ali_bucket, str(file_id) + '/' + announcement_title + '.html',
                             r.text.encode(r.encoding).decode('utf-8'))
                db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
            else:
                db.circ_data.update_one({'_id': each_circ_data['_id']}, {'$set': {'status': 'parsed'}})
                file_id = db.parsed_data.find_one({'origin_url': announcement_url,
                                                   'oss_file_origin_url': announcement_url})['_id']

            document_code_compiler = re.compile(r'((湘保监罚|湘银保监罚决字).\d{4}.\d+号)')
            if document_code_compiler.search(content_text):
                document_code = document_code_compiler.search(content_text).group(1).strip()
                litigant_compiler = re.compile(
                    document_code.replace(r'[', r'\[').replace(r']', r'\]') +
                    r'\n([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|'
                                        r'一、|.*?(财务|记账)凭证(显示)?|'
                                        r'2016年1月1日至12月31日期间|'
                                        r'英大泰和财产保险股份有限公司|'
                                        r'你公司2016年通过“业务及管理费—差旅费”科目报销费用|'
                                        r'你公司2015年11月至2016年5月期间通过“间接理赔费—差旅费”报销费用|'
                                        r'你公司PDAA2015431100000228|'
                                        r'2015年1月至6月期间|'
                                        r'国华人寿保险股份有限公司(以下简称“国华人寿”)湖南分公司|'
                                        r'你公司2015年9月19\*号会计凭证列支|'
                                        r'.*?向我局递交了|'
                                        r'你公司80511201643110200|'
                                        r'中国平安财产保险股份有限公司|'
                                        r'.*?经查|'
                                        r'.*?进行现场检查|'
                                        r'2016年1月18日,湖南凤凰保险代理有限公司)')
                litigant = litigant_compiler.search(content_text).group(1).strip()
            else:
                if document_code_compiler.search(title):
                    document_code = document_code_compiler.search(title).group(1).strip()
                else:
                    document_code = ''
                litigant_compiler = re.compile(
                    r'^([\s\S]*?)\n' + r'(经查|经检查|依据.*?的有关规定|一|.*?(财务|记账)凭证(显示)?|2016年1月1日至12月31日期间|'
                                       r'英大泰和财产保险股份有限公司|你公司2016年通过“业务及管理费—差旅费”科目报销费用|'
                                       r'你公司2015年11月至2016年5月期间通过“间接理赔费—差旅费”报销费用|'
                                       r'你公司PDAA2015431100000228|2015年1月至6月期间|'
                                       r'国华人寿保险股份有限公司(以下简称“国华人寿”)湖南分公司|你公司2015年9月19\*号会计凭证列支|'
                                       r'.*?向我局递交了|'
                                       r'你公司80511201643110200|中国平安财产保险股份有限公司|'
                                       r'.*?经查|.*?进行现场检查|2016年1月18日,湖南凤凰保险代理有限公司)')
                litigant = litigant_compiler.search(content_text).group(1).strip()

            truth_text_str = r'((经查,|经查,|经检查,|经查实,|检查发现,|现场检查,发现|抽查,|经抽查,|经查.*?存在以下问题:|经查:|' \
                             r'一、|二、|三、)' \
                             r'([\s\S]*?))' \
                             r'(证明上述(违法)?事实的主要证据有|[^,。,;\n]*?上述行为.*?违反了.*?第.*?条(的)?规定|' \
                             r'你营业部通过改变车辆使用性质承保交强险和商业车险的行为违反了《中华人民共和国保险法》第一百零七条规定|' \
                             r'你公司的上述行为,违反了《中华人民共和国保险法》第一百零六条和第一百零七条的规定|' \
                             r'(上述|以上)事实(,)?有[\s\S]*?证据(证明)?(,足以认定)?。)'
            truth_compiler = re.compile(truth_text_str)
            truth_list = truth_compiler.findall(content_text)
            if len(truth_list) > 0:
                truth = '\n'.join([kk[0].strip() for kk in truth_list])
            else:
                truth_text_str = litigant.replace(r'*', r'\*') + r'([\s\S]*?)(证明上述(违法)?事实的主要证据有)'
                truth_compiler = re.compile(truth_text_str)
                truth = truth_compiler.search(content_text).group(1).strip()

            if '申辩' in content_text:
                defense_text_str = r'((针对.*?行为.*?申辩意见|(当事人)?[^,。,;\n]*?(未)?提出(了)?陈述申辩(意见)?|' \
                                   r'在法定陈述申辩期内,当事人放弃陈述申辩。|' \
                                   r'本案在审理过程中.*?提出陈述申辩|' \
                                   r'在规定期限内,当事人放弃陈述申辩且未提出听证申请。|' \
                                   r'[^,。,;\n]*?在(申辩材料|陈述申辩|陈述申辩意见|申辩意见)中称|[^,。,;\n]*?在听证阶段提出|' \
                                   r'[^,。,;\n]*?在法定期限内(未)?提出(了)?(听证要求|陈述申辩|陈述申辩及听证要求)|' \
                                   r'你[^,。,;\n]*?在规定时限内(提出书面陈述申辩|申辩称|陈述申辩称)|' \
                                   r'你[^,。,;\n]*?在规定时间内向我局提出陈述申辩|' \
                                   r'你[^,。,;\n]*?在规定时间内未向我局提出听证,但向我局提出陈述申辩|' \
                                   r'你[^。;\n]*?辩称)' \
                                   r'([\s\S]*?))' \
                                   r'(因此,我局决定|' \
                                   r'我局经复核(认为|决定)|' \
                                   r'本案现已审理终结|' \
                                   r'我局经复查[^,。,;\n]*?情况|' \
                                   r'我局[^,。,;\n]*?认真复核|' \
                                   r'经研究,对[^,。,;\n]*?予以采纳。|' \
                                   r'我局认为.*?申辩理由|' \
                                   r'依据.*?我局认为.*?的申辩理由|' \
                                   r'经研究,我局认为.*?申辩意见|' \
                                   r'经我局审核,决定|' \
                                   r'我局认为,上述违法行为事实清楚、证据确凿、法律法规适当|' \
                                   r'我局对陈述申辩意见进行了复核|' \
                                   r'经我局审核|' \
                                   r'针对[^,。,;\n]*?的(陈述)?申辩意见,我局进行了核实|' \
                                   r'经查,我局认为|' \
                                   r'依据现场检查及听证情况|' \
                                   r'我局经研究认为|我局认为:在你签字审批的《呈批件(签报)》中|' \
                                   r'我局经复核,认为|' \
                                   r'我局经研究|' \
                                   r'我局认为)'
                defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                defense_list = defense_compiler.findall(content_text)
                if len(defense_list) != 0:
                    defense = defense_list[-1][0]
                    defense_response_str = defense.replace(r'[', r'\[').replace(r']', r'\]').replace(r'(', r'\(') \
                                               .replace(r')', r'\)') \
                                           + r'(([\s\S]*?)' + r'(本案现已审理终结。|不符合.*?情形。|根据.*?依法可从轻或者减轻行政处罚。|' \
                                                              r'对[^,。,;\n]*?申辩(意见|理由)?(不予|予以)采纳|因此.*?申辩理由.*?成立。|' \
                                                              r'我局认为.*?申辩(理由|意见).*?符合.*?第.*?条.*?的条件.(予以采纳。)?))'
                    defense_response_compiler = re.compile(defense_response_str, re.MULTILINE)
                    if defense_response_compiler.search(content_text):
                        defense_response = defense_response_compiler.search(content_text).group(1).strip()
                    else:
                        if '未' in defense:
                            defense_response = ''
                else:
                    defense_text_str = r'(\n?你[^,。,;\n]*?在规定(期限|时间|时限)内未(向我局)?(提出|提起)(听证申请和)?(陈述|申述)申辩(和听证要求|意见)?。\n?|' \
                                       r'你[^,。,;\n]*?在规定时限内未申请听证,也未提出陈述申辩。|你公司在规定期限内未提出陈述申辩,也未申请听证。|' \
                                       r'你公司在规定时限内未提出听证申请及陈述申辩。|你公司在规定时限内未提出听证和陈述申辩。|' \
                                       r'你在规定时限内未申请听证,在规定时限内提出了陈述申辩。|你[^,。,;\n]*?主动书面放弃陈述申辩(及听证)?权利|' \
                                       r'你在规定时间内未向我局提出\n陈述申辩。|你公司在规定时限内未向我局提出听证、陈述申辩。|' \
                                       r'你[^,。,;\n]*?在规定时间内未提出陈述、申辩。)'
                    defense_compiler = re.compile(defense_text_str, re.MULTILINE)
                    defense = defense_compiler.search(content_text).group(1).strip()
                    defense_response = ''
            else:
                defense = defense_response = ''

            punishment_decision_text_str = r'(((我局认为)?[^。;\n]*?行为.*?((分别)?违反|构成)了?|' \
                                           r'综上,我局决定作出如下处罚)' \
                                           r'([\s\S]*?))' \
                                           r'(\n二、|\n三、|' \
                                           r'\n?你[^,。,;\n]*?在规定(期限|时间|时限)内未?(向我局)?(提出|提起)(听证申请和)?(陈述|申述)申辩(和听证要求|意见)?|' \
                                           r'你[^,。,;\n]*?在规定时限内未申请听证,也未提出陈述申辩。|你公司在规定期限内未提出陈述申辩,也未申请听证。|' \
                                           r'你公司在规定时限内未提出听证申请及陈述申辩。|你公司在规定时限内未提出听证和陈述申辩。|' \
                                           r'你在规定时限内未申请听证,在规定时限内提出了陈述申辩|你[^,。,;\n]*?在规定时限内(提出书面陈述申辩|申辩称)|' \
                                           r'你[^,。,;\n]*?主动书面放弃陈述申辩(及听证)?权利|你[^,。,;\n]*?在规定时限内未申请听证,但(提出)?陈述申辩称|' \
                                           r'你在规定时限内陈述申辩称|你在规定时间内向我局提出陈述申辩|你公司在规定时间内辩称|' \
                                           r'你[^,。,;\n]*?在规定时间内未向我局提出听证,但向我局提出陈述申辩|' \
                                           r'你在规定时间内未向我局提出\n陈述申辩。|你公司在规定时限内未向我局提出听证、陈述申辩。|' \
                                           r'你[^,。,;\n]*?在规定时限内申述申辩称|你[^,。,;\n]*?在规定时间内未提出陈述、申辩。|' \
                                           r'你[^,。,;\n]*?辩称|你[^,。,;\n]*?应在本处罚决定书送达之日|[^,。,;\n]*?如不服本处罚决定|' \
                                           r'[^,。,;\n]*?如对本处罚决定不服|' \
                                           r'\n当事人应当在接到本处罚决定书之日)'
            punishment_decision_compiler = re.compile(punishment_decision_text_str, re.MULTILINE)

            punishment_decision_list = punishment_decision_compiler.findall(content_text)
            if len(punishment_decision_list) > 0:
                punishment_decision = '\n'.join([kk[0].strip() for kk in punishment_decision_list])

            punishment_basis_str_list = [
                r'([^\n。;]*?)(问题|行为|事项|情况|事实)([^\n。;\s]*?)(违反|构成).*?\n?.*?第.*?条?\n?.*?((的|之|等)(相关)?规定)?',
            ]
            punishment_basis_str = '|'.join(punishment_basis_str_list)
            punishment_basis_compiler = re.compile(r'[。\n;]' + '(' + punishment_basis_str + ')' +
                                                   r'.(\n?依据|\n?根据|\n?鉴于)', re.MULTILINE)
            punishment_basis_list = punishment_basis_compiler.findall(content_text)
            punishment_basis = ';'.join([kk[0].strip() for kk in punishment_basis_list])

            publish_date_text = re.search(
                punishment_decision_list[-1][0].replace(r'(', r'\(').replace(r')', r'\)').
                replace(r'[', r'\[').replace(r']', r'\]').
                replace(r'*', r'\*') + r'([\s\S]*?)$', content_text).group(1).replace(r'\n', '')
            if re.search(r'.{4}年.{1,2}月.{1,3}日', publish_date_text):
                publish_date = re.findall('.{4}年.{1,2}月.{1,3}日', publish_date_text)[-1]
                m = re.match("([0-9零一二两三四五六七八九十〇○OO]+年)?([0-9一二两三四五六七八九十]+)月?([0-9一二两三四五六七八九十]+)[号日]?", publish_date)
                real_publish_date = get_year(m.group(1)) + str(cn2dig(m.group(2))) + '月' + str(cn2dig(m.group(3))) + '日'
            else:
                publish_date_text = table_content.find_all('tr')[1].text
                publish_date = re.findall(r'\d{4}-\d{1,2}-\d{1,2}', publish_date_text)[-1]
                real_publish_date = publish_date.split('-')[0] + '年' + str(int(publish_date.split('-')[1])) + '月' + str(
                    int(publish_date.split('-')[2])) + '日'

            result_map = {
                'announcementTitle': title,
                'announcementOrg': '湖南银保监局',
                'announcementDate': real_publish_date,
                'announcementCode': document_code,
                'facts': truth,
                'defenseOpinion': defense,
                'defenseResponse': defense_response,
                'litigant': litigant[:-1] if litigant[-1] == ':' or litigant[-1] == ':' else litigant,
                'punishmentBasement': punishment_basis,
                'punishmentDecision': punishment_decision,
                'type': '行政处罚决定',
                'oss_file_id': file_id,
                'status': 'not checked'
            }
            logger.info(result_map)
            if db.announcement.find(
                    {'announcementTitle': result_map['announcementTitle'],
                     'oss_file_id': file_id,
                     'litigant': result_map['litigant']}).count() == 0:
                db.announcement.insert_one(result_map)
                logger.info('湖南保监局 数据解析 ' + ' -- 数据导入完成')
            else:
                logger.info('湖南保监局 数据解析 ' + ' -- 数据已经存在')
            db.parsed_data.update_one({'_id': file_id}, {'$set': {'parsed': True}})
            logger.info('湖南保监局 数据解析 ' + ' -- 修改parsed完成')