Example #1
0
    def _unit_login(self, params=None):
        err_msg = None
        if params:
            # 非开始或者开始就提供了参数
            try:
                self._check_login_params(params)
                id_num = params.get("证件号")
                username=params.get("姓名")
                account_pass = params.get("密码")
                vc = params.get("vc")

                # self._do_login(id_num, username,account_pass, vc)

                self.result_key = id_num
                self.result_meta['证件号'] =id_num
                self.result_meta['姓名'] = username
                self.result_meta['密码']=account_pass

                raise TaskNotImplementedError('查询服务维护中')

            except (AssertionError, InvalidParamsError) as e:
                err_msg = str(e)

        raise AskForParamsError([
            dict(key='证件号', name='证件号', cls='input',value=params.get('证件号', '')),
            dict(key='姓名', name='姓名', cls='input', value=params.get('姓名', '')),
            dict(key='密码', name='密码', cls='input:password',value=params.get('密码', '')),
            dict(key='vc', name='验证码', cls='data:image', query={'t': 'vc'}),
        ], err_msg)
Example #2
0
    def _unit_login(self, params: dict):
        err_msg = None
        if params:
            try:
                self._check_login_params(params)
                self.result_key = params.get('用户名')
                # 保存到meta
                self.result_meta['证件号码'] = params.get('证件号码')
                self.result_meta['个人账号'] = params.get('个人账号')

                raise TaskNotImplementedError('查询服务维护中')
            except (AssertionError, InvalidParamsError) as e:
                err_msg = str(e)

        raise AskForParamsError([
            dict(key='证件号码',
                 name='证件号码',
                 cls='input',
                 placeholder='证件号码(以单位申报为准)',
                 value=params.get('证件号码', '')),
            dict(key='个人账号',
                 name='个人账号',
                 cls='input',
                 placeholder='对帐簿或原存折帐号后8位',
                 value=params.get('个人账号', '')),
        ], err_msg)
Example #3
0
    def _unit_login(self, params: dict):
        err_msg = None
        if params:
            try:
                self._check_login_params(params)
                self.result_key = params.get('身份证号')
                # 保存到meta
                self.result_meta['身份证号'] = params.get('身份证号')
                self.result_meta['密码'] = params.get('密码')

                raise TaskNotImplementedError('查询服务维护中')
            except (AssertionError, InvalidParamsError) as e:
                err_msg = str(e)

        raise AskForParamsError([
            dict(key='身份证号',
                 name='身份证号',
                 cls='input',
                 placeholder='身份证号',
                 value=params.get('身份证号', '')),
            dict(key='密码',
                 name='密码',
                 cls='input:password',
                 value=params.get('密码', '')),
        ], err_msg)
Example #4
0
    def _unit_login(self, params: dict):
        err_msg = None
        if params:
            try:
                self._check_login_params(params)

                id_num = params.get("社保号")
                account_pass = params.get("密码")
                vc = params.get("vc")

                data = {
                    'id0000': id_num,
                    'userpwd': account_pass,
                    'validateCode': vc,
                    'date': str(time.time() * 1000)[0:13]
                }

                if (account_pass == "123456"):
                    raise TaskNotImplementedError("请先到官网修改密码后再来查询!")

                resp = self.s.post(
                    "https://app.xmhrss.gov.cn/login_dowith.xhtml",
                    data=data,
                    verify=False)
                res = json.loads(resp.text)

                if res['result'] == False:
                    raise InvalidParamsError(res['msg'])
                elif res['result'] == True:

                    # 保存到meta
                    self.result_key = id_num
                    self.result_meta['社保号'] = id_num
                    self.result_meta['密码'] = account_pass

                    return
            except (AssertionError, InvalidParamsError) as e:
                err_msg = str(e)

        raise AskForParamsError([
            dict(key='社保号',
                 name='社保号',
                 cls='input',
                 placeholder='请输入社保号',
                 value=params.get('社保号', '')),
            dict(key='密码',
                 name='密码',
                 cls='input:password',
                 value=params.get('密码', '')),
            dict(key='vc', name='验证码', cls='data:image', query={'t': 'vc'}),
        ], err_msg)
Example #5
0
    def _unit_login(self, params=None):
        err_msg = None
        if not self.is_start or params:
            # 非开始或者开始就提供了参数
            try:
                self._check_login_params(params)

                # id_num = params.get("身份证号")
                # account_pass = params.get("密码")
                # #vc = params.get("vc")
                #
                # data={
                #     'username': id_num,
                #     'password': account_pass,
                #     'loginType': 4,
                #     'vertcode':'',
                #     'bsr':'chrome / 61.0.3163.79',
                #     'vertype': 1
                # }
                # resp=self.s.post(LOGIN_URL,data)
                # if 'html' not in resp.text:
                #     raise InvalidParamsError("登录失败,用户名或密码错误!")
                # else:
                #     # 保存到meta
                #     self.result_key = id_num
                #     self.result_meta['身份证号'] = id_num
                #     self.result_meta['密码'] = account_pass
                #     return

                raise TaskNotImplementedError('查询服务维护中')

            except (AssertionError, InvalidParamsError) as e:
                err_msg = str(e)

        raise AskForParamsError(
            [
                dict(key='身份证号',
                     name='身份证号',
                     cls='input',
                     placeholder='身份证号/手机号码/个人账号',
                     value=params.get('身份证号', '')),
                dict(key='密码',
                     name='密码',
                     cls='input:password',
                     value=params.get('密码', '')),
                #dict(key='vc', name='验证码', cls='data:image', query={'t': 'vc'}),
            ],
            err_msg)
Example #6
0
    def _unit_fetch(self):
        try:
            # TODO: 执行任务,如果没有登录,则raise PermissionError
            s = json.loads(self.s.get(User_BaseInfo).text)  # 个人信息导航
            s2 = s[0]['url']
            res = self.s.get("http://gzlss.hrssgz.gov.cn/gzlss_web" +
                             s2)  # 个人基础信息

            if (len(
                    BeautifulSoup(res.text, 'html.parser').findAll(
                        'table', {'class': 'comitTable'})) <= 0):
                raise TaskNotAvailableError("网络异常,请重新登录")
                return

            redata = BeautifulSoup(res.text, 'html.parser').findAll(
                'table', {'class': 'comitTable'})[0]  # 姓名等信息
            redata2 = BeautifulSoup(res.text, 'html.parser').findAll(
                'table', {'class': 'comitTable'})[1]  # 民族等信息

            # 社保明细
            userNum = BeautifulSoup(
                self.s.get(Search_URL).text,
                'html.parser').find('select', {
                    'id': 'aac001'
                }).text.replace('\n', '')  # 员工编号
            sixian = BeautifulSoup(
                self.s.get(Sixian_URL + userNum).text,
                'html.parser').find('table').findAll(
                    "tr", {'class': 'table_white_data'})

            # 医疗保险明细
            permedicalTotal = 0.0
            HmoneyCount = 0
            paraURL = "&startStr=199001&endStr=" + time.strftime(
                '%Y%m', time.localtime()) + ""  # 医疗保险地址参数
            yiliao = BeautifulSoup(
                self.s.get(Yiliao_URL + userNum + paraURL).text, 'html.parser')
            a = yiliao.find('table', {
                'id': 'tableDataList'
            }).find('script').text
            if "请明天再查" in a:
                raise TaskNotAvailableError("您今天的缴费历史查询已经达到5次,请明天再查。")
            elif "找不到相关数据" in a:
                raise TaskNotAvailableError("抱歉,找不到相关数据。")
            elif "非法操作" in a:
                raise TaskNotAvailableError("非法操作,无法查询。")

            self.result_data['medical_care'] = {"data": {}}
            dataBaseH = self.result_data['medical_care']["data"]
            modelH = {}

            si_status = ""
            sidata = yiliao.find('table', {'id': 'tableDataList'})
            if 'alert' not in sidata.text:
                if len(sidata.findAll("tr")) > 1:
                    si_status = self._to_replace(
                        sidata.findAll("tr")[1].findAll("td")[10].text)[
                            0:2]  # 缴存状态
                    si_com = self._to_replace(
                        sidata.findAll("tr")[2].findAll("td")[3].text)  # 缴费单位
                    yiliaoData = sidata.findAll("tr", {'temp': '职工社会医疗保险'})

                    for a in range(len(yiliaoData)):
                        td = yiliaoData[a].findAll("td")
                        permedicalTotal += float(
                            re.findall(r"\d+\.?\d*", td[7].text)[0])

                        yearH = self._to_replace(td[1].text)[0:4]
                        monthH = self._to_replace(td[1].text)[4:6]
                        rangNum = int(self._to_replace(td[3].text))
                        HmoneyCount += rangNum
                        for a1 in range(-1, rangNum - 1):
                            nowtime = datetime.date(
                                int(yearH) + (int(monthH) + a1) // 12,
                                (int(monthH) + a1) % 12 + 1,
                                1).strftime('%Y%m')
                            modelH = {
                                '缴费单位':
                                si_com,
                                '缴费类型':
                                si_status,
                                '缴费时间':
                                nowtime,
                                '缴费基数':
                                self._to_replace(td[9].text),
                                '政府资助':
                                re.findall(r"\d+\.?\d*", td[8].text)[0],
                                '公司缴费':
                                float(re.findall(r"\d+\.?\d*",
                                                 td[6].text)[0]) / rangNum,
                                '个人缴费':
                                float(re.findall(r"\d+\.?\d*", td[7].text)[0])
                                / rangNum
                            }
                            dataBaseH.setdefault(nowtime[0:4], {})
                            dataBaseH[nowtime[0:4]].setdefault(
                                nowtime[4:6], [])
                            dataBaseH[nowtime[0:4]][nowtime[4:6]].append(
                                modelH)
                else:
                    raise TaskNotImplementedError("未查询到数据!")
            else:
                errormsg2 = sidata.text.split('(')[1].split(')')[0]
                raise TaskNotImplementedError(errormsg2)

            # 养老保险明细
            self.result_data['old_age'] = {"data": {}}
            dataBaseE = self.result_data['old_age']["data"]
            modelE = {}
            peroldTotal = 0.0
            for b in range(len(sixian) - 3):
                td2 = sixian[b].findAll("td")
                if (td2[5].text.strip() != ''):
                    peroldTotal += float(td2[5].text)

                    yearE = td2[0].text[0:4]
                    monthE = td2[0].text[4:6]
                    rangNumE = int(td2[2].text)
                    for b1 in range(-1, rangNumE - 1):
                        nowtime2 = datetime.date(
                            int(yearE) + (int(monthE) + b1) // 12,
                            (int(monthE) + b1) % 12 + 1, 1).strftime('%Y%m')
                        modelE = {
                            '缴费单位': td2[11].text,
                            '缴费类型': td2[12].text,
                            '缴费时间': nowtime2,
                            '缴费基数': td2[3].text,
                            '公司缴费': float(td2[4].text) / rangNumE,
                            '个人缴费': float(td2[5].text) / rangNumE
                        }
                        dataBaseE.setdefault(nowtime2[0:4], {})
                        dataBaseE[nowtime2[0:4]].setdefault(nowtime2[4:6], [])
                        dataBaseE[nowtime2[0:4]][nowtime2[4:6]].append(modelE)

            # 失业保险明细
            self.result_data['unemployment'] = {"data": {}}
            dataBaseI = self.result_data['unemployment']["data"]
            modelI = {}
            for c in range(len(sixian) - 3):
                td3 = sixian[c].findAll("td")
                if (td3[0].text.strip() != ""):
                    yearI = td3[0].text[0:4]
                    monthI = td3[0].text[4:6]
                    rangNumI = int(td3[2].text)
                    for c1 in range(-1, rangNumI - 1):
                        nowtime3 = datetime.date(
                            int(yearI) + (int(monthI) + c1) // 12,
                            (int(monthI) + c1) % 12 + 1, 1).strftime('%Y%m')
                        modelI = {
                            '缴费单位': td3[11].text,
                            '缴费类型': td3[12].text,
                            '缴费时间': nowtime3,
                            '缴费基数': td3[3].text,
                            '公司缴费': float(td3[6].text) / rangNumI,
                            '个人缴费': float(td3[7].text) / rangNumI
                        }
                        dataBaseI.setdefault(nowtime3[0:4], {})
                        dataBaseI[nowtime3[0:4]].setdefault(nowtime3[4:6], [])
                        dataBaseI[nowtime3[0:4]][nowtime3[4:6]].append(modelI)

            # 工伤保险明细
            self.result_data['injuries'] = {"data": {}}
            dataBaseC = self.result_data['injuries']["data"]
            modelC = {}
            for d in range(len(sixian) - 3):
                td4 = sixian[d].findAll("td")
                if (td4[0].text.strip() != ""):
                    yearC = td4[0].text[0:4]
                    monthC = td4[0].text[4:6]
                    rangNumC = int(td4[2].text)
                    for d1 in range(-1, rangNumC - 1):
                        nowtime4 = datetime.date(
                            int(yearC) + (int(monthC) + d1) // 12,
                            (int(monthC) + d1) % 12 + 1, 1).strftime('%Y%m')
                        modelC = {
                            '缴费单位': td4[11].text,
                            '缴费类型': td4[12].text,
                            '缴费时间': nowtime4,
                            '缴费基数': td4[3].text,
                            '公司缴费': float(td4[8].text) / rangNumC,
                            '个人缴费': ''
                        }
                        dataBaseC.setdefault(nowtime4[0:4], {})
                        dataBaseC[nowtime4[0:4]].setdefault(nowtime4[4:6], [])
                        dataBaseC[nowtime4[0:4]][nowtime4[4:6]].append(modelC)

            # 生育保险明细
            self.result_data['maternity'] = {"data": {}}
            dataBaseB = self.result_data['maternity']["data"]
            modelB = {}
            for f in range(len(sixian) - 3):
                td5 = sixian[f].findAll("td")
                if (td5[0].text.strip() != ""):
                    yearB = td5[0].text[0:4]
                    monthB = td5[0].text[4:6]
                    rangNumB = int(td5[2].text)
                    for f1 in range(-1, rangNumB - 1):
                        nowtime5 = datetime.date(
                            int(yearB) + (int(monthB) + f1) // 12,
                            (int(monthB) + f1) % 12 + 1, 1).strftime('%Y%m')
                        modelB = {
                            '缴费单位': td5[11].text,
                            '缴费类型': td5[12].text,
                            '缴费时间': nowtime5,
                            '缴费基数': td5[3].text,
                            '公司缴费': float(td5[9].text) / rangNumB,
                            '个人缴费': ''
                        }
                        dataBaseB.setdefault(nowtime5[0:4], {})
                        dataBaseB[nowtime5[0:4]].setdefault(nowtime5[4:6], [])
                        dataBaseB[nowtime5[0:4]][nowtime5[4:6]].append(modelB)

            # 大病保险明细
            dabingData = sidata.findAll("tr", {'temp': '重大疾病医疗补助'})
            self.result_data['serious_illness'] = {"data": {}}
            dataBaseQ = self.result_data['serious_illness']["data"]
            modelQ = {}

            if (len(dabingData) > 0):
                for q in range(len(dabingData)):
                    td6 = dabingData[q].findAll("td")
                    if (td6[0].text.strip() != ""):
                        yearQ = self._to_replace(td[1].text)[0:4]
                        monthQ = self._to_replace(td[1].text)[4:6]
                        rangNumQ = int(self._to_replace(td[3].text))

                        for a1 in range(-1, rangNumQ - 1):
                            nowtime6 = datetime.date(
                                int(yearQ) + (int(monthQ) + a1) // 12,
                                (int(monthQ) + a1) % 12 + 1,
                                1).strftime('%Y%m')
                            modelQ = {
                                '缴费单位':
                                si_com,
                                '缴费类型':
                                si_status,
                                '缴费时间':
                                nowtime6,
                                '缴费基数':
                                self._to_replace(td6[9].text),
                                '政府资助':
                                re.findall(r"\d+\.?\d*", td6[8].text)[0],
                                '公司缴费':
                                float(
                                    re.findall(r"\d+\.?\d*", td6[6].text)[0]) /
                                rangNum,
                                '个人缴费':
                                float(
                                    re.findall(r"\d+\.?\d*", td6[7].text)[0]) /
                                rangNum
                            }
                            dataBaseQ.setdefault(nowtime6[0:4], {})
                            dataBaseQ[nowtime6[0:4]].setdefault(
                                nowtime6[4:6], [])
                            dataBaseQ[nowtime6[0:4]][nowtime6[4:6]].append(
                                modelQ)

            sixiantype = ""
            if (len(sixian) >= 4):
                sixiantype = sixian[len(sixian) - 4].findAll("td")[12].text
            social_status = {
                '医疗': si_status,
                '养老': sixiantype,
                '失业': sixiantype,
                '工伤': sixiantype,
                '生育': sixiantype
            }

            # 缴费时长
            EmoneyCount = sixian[len(sixian) - 3].findAll("td")[1].text
            EmoneyCount2 = sixian[len(sixian) - 3].findAll("td")[2].text
            EmoneyCount3 = sixian[len(sixian) - 3].findAll("td")[3].text
            EmoneyCount4 = sixian[len(sixian) - 3].findAll("td")[4].text
            rescount = [EmoneyCount, EmoneyCount2, EmoneyCount3, EmoneyCount4]
            moneyCount = max(rescount)

            # 个人基本信息
            self.result_data['baseInfo'] = {
                '姓名': redata.find('input', {'id': 'aac003ss'})['value'],
                '身份证号': redata.find('input', {'id': 'aac002ss'})['value'],
                '更新时间': time.strftime("%Y-%m-%d", time.localtime()),
                '城市名称': '广州市',
                '城市编号': '440100',
                '缴费时长': moneyCount,
                '最近缴费时间': sixian[len(sixian) - 4].findAll("td")[1].text,
                '开始缴费时间': sixian[0].findAll("td")[0].text,
                '个人养老累计缴费': peroldTotal,
                '个人医疗累计缴费': permedicalTotal,
                '五险状态': social_status,
                '账户状态': social_status['养老'],
                '个人编号': redata.find('input', {'id': 'aac001'})['value'],
                # '性别': redata.find('input', {'id': 'aac004ss'})['value'],
                # '民族': redata2.find('select', {'id': 'aac005'}).find(selected="selected").text.replace('\r', '').replace('\n', '').replace('\t', ''),
                # '户口性质': redata.find('input', {'id': 'aac009ss'})['value'],
                # '出生日期': redata.find('input', {'id': 'aac006ss'})['value'],
                # '单位名称': redata.find('input', {'id': 'aab069ss'})['value'],
                # '地址': redata2.find('input', {'id': 'bab306'})['value'],
                # '电子邮箱': redata2.find('input', {'id': 'bbc019'})['value']
            }

            # identity信息
            self.result_identity.update({
                "task_name":
                "广州",
                "target_name":
                redata.find('input', {'id': 'aac003ss'})['value'],
                "target_id":
                self.result_meta['账号'],
                "status":
                social_status['养老']
            })

            # 暂时不用代码
            # siresp=self.s.get("http://gzlss.hrssgz.gov.cn/gzlss_web"+s[1]['url'])  # 四险导航
            # sdata=BeautifulSoup(siresp.text,'html.parser')   # 四险find信息
            # hs = json.loads(self.s.get(Medical_URL).text)  # 医疗保险信息
            # medDetailURL=hs[0]['url']         # 医疗
            # hresp=self.s.get("http://gzlss.hrssgz.gov.cn/gzlss_web"+medDetailURL)
            # hdata = BeautifulSoup(hresp.text, 'html.parser')  # 医疗find信息

            return
        except PermissionError as e:
            raise PreconditionNotSatisfiedError(e)
Example #7
0
    def _unit_fetch(self):
        try:
            # TODO: 执行任务,如果没有登录,则raise PermissionError
            # 个人信息
            res = self.s.get(
                "https://gr.cdhrss.gov.cn:442/cdwsjb/personal/personalHomeAction!query.do"
            )
            if (res.status_code != 200):
                raise TaskNotImplementedError("网络错误,请稍后再试!")
            else:
                s = json.loads(res.text)["fieldData"]
                # 社保明细
                startTime = "199001"
                endTime = time.strftime("%Y%m", time.localtime())  # 查询结束时间
                # 社保缴费明细-----养老
                self.result['data']["old_age"] = {"data": {}}
                basedataE = self.result['data']["old_age"]["data"]
                modelE = {}
                peroldTotal = 0.0
                detailEI = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=110")
                if 'lists' in json.loads(detailEI.text):
                    sEI = json.loads(
                        detailEI.text)['lists']['dg_payment']['list']
                    for a in range(len(sEI)):
                        years = str(sEI[a]['aae002'])[0:4]
                        months = str(sEI[a]['aae002'])[4:6]
                        basedataE.setdefault(years, {})
                        basedataE[years].setdefault(months, [])

                        modelE = {
                            '缴费单位': sEI[a]['aab004'],
                            '缴费时间': sEI[a]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sEI[a]['yac004'],
                            '公司缴费': sEI[a]['dwjfje'],
                            '个人缴费': sEI[a]['grjfje']
                            #'缴费合计': sEI[a]['jfjezh']
                        }
                        peroldTotal += float(sEI[a]['grjfje'])
                        basedataE[years][months].append(modelE)
                else:
                    sEI = {}

                self.result['data']["medical_care"] = {"data": {}}
                basedataH = self.result['data']["medical_care"]["data"]
                modelH = {}
                permedicalTotal = 0.0
                # 社保明细-----医疗
                detailHI = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=310")
                if 'lists' in json.loads(detailHI.text):
                    sHI = json.loads(
                        detailHI.text)['lists']['dg_payment']['list']
                    for b in range(len(sHI)):
                        yearH = str(sHI[b]['aae002'])[0:4]
                        monthH = str(sHI[b]['aae002'])[4:6]
                        basedataH.setdefault(yearH, {})
                        basedataH[yearH].setdefault(monthH, [])

                        modelH = {
                            '缴费单位': sHI[b]['aab004'],
                            '缴费时间': sHI[b]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sHI[b]['yac004'],
                            '公司缴费': sHI[b]['dwjfje'],
                            '个人缴费': sHI[b]['hrzhje'],
                            #'缴费合计': sHI[b]['jfjezh']
                        }
                        permedicalTotal += float(sHI[b]['hrzhje'])
                        basedataH[yearH][monthH].append(modelH)
                else:
                    sHI = {}

                self.result['data']["unemployment"] = {"data": {}}
                basedataI = self.result['data']["unemployment"]["data"]
                modelI = {}
                # 社保明细-----失业
                detailII = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=210")
                if 'lists' in json.loads(detailII.text):
                    sII = json.loads(
                        detailII.text)['lists']['dg_payment']['list']
                    for d in range(len(sII)):
                        yearI = str(sII[d]['aae002'])[0:4]
                        monthI = str(sII[d]['aae002'])[4:6]
                        basedataI.setdefault(yearI, {})
                        basedataI[yearI].setdefault(monthI, [])

                        modelI = {
                            '缴费单位': sII[d]['aab004'],
                            '缴费时间': sII[d]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sII[d]['yac004'],
                            '公司缴费': sII[d]['dwjfje'],
                            '个人缴费': sII[d]['grjfje'],
                            #'缴费合计': sII[d]['jfjezh']
                        }
                        basedataI[yearI][monthI].append(modelI)
                else:
                    sII = {}

                self.result['data']["injuries"] = {"data": {}}
                basedataC = self.result['data']["injuries"]["data"]
                modelC = {}
                # 社保明细-----工伤
                detailCI = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=410")
                if 'lists' in json.loads(detailCI.text):
                    sCI = json.loads(
                        detailCI.text)['lists']['dg_payment']['list']
                    for c in range(len(sCI)):
                        yearC = str(sCI[c]['aae002'])[0:4]
                        monthC = str(sCI[c]['aae002'])[4:6]
                        basedataC.setdefault(yearC, {})
                        basedataC[yearC].setdefault(monthC, [])

                        modelC = {
                            '缴费单位': sCI[c]['aab004'],
                            '缴费时间': sCI[c]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sCI[c]['yac004'],
                            '公司缴费': sCI[c]['dwjfje'],
                            '个人缴费': '',
                            #'缴费合计': sCI[c]['jfjezh']
                        }
                        basedataC[yearC][monthC].append(modelC)
                else:
                    sCI = {}

                self.result['data']["maternity"] = {"data": {}}
                basedataB = self.result['data']["maternity"]["data"]
                modelB = {}
                # 社保明细-----生育
                detailBI = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=510")
                if 'lists' in json.loads(detailBI.text):
                    sBI = json.loads(
                        detailBI.text)['lists']['dg_payment']['list']
                    for f in range(len(sBI)):
                        yearB = str(sBI[f]['aae002'])[0:4]
                        monthB = str(sBI[f]['aae002'])[4:6]
                        basedataB.setdefault(yearB, {})
                        basedataB[yearB].setdefault(monthB, [])

                        modelB = {
                            '缴费单位': sBI[f]['aab004'],
                            '缴费时间': sBI[f]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sBI[f]['yac004'],
                            '公司缴费': sBI[f]['dwjfje'],
                            '个人缴费': '',
                            #'缴费合计': sBI[f]['jfjezh']
                        }
                        basedataB[yearB][monthB].append(modelB)
                else:
                    sBI = {}

                # 大病缴费明细
                self.result['data']["serious_illness"] = {"data": {}}
                basedataS = self.result['data']["serious_illness"]["data"]
                modelS = {}
                detailSI = self.s.get(
                    Detail_URL + "?dto['aae041']=" + startTime +
                    "&dto['aae042']=" + endTime +
                    "&dto['aae140_md5list']=&dto['aae140']=330")
                if 'lists' in json.loads(detailSI.text):
                    sSI = json.loads(
                        detailSI.text)['lists']['dg_payment']['list']
                    for q in range(len(sSI)):
                        yearQ = str(sSI[q]['aae002'])[0:4]
                        monthQ = str(sSI[q]['aae002'])[4:6]
                        basedataS.setdefault(yearQ, {})
                        basedataS[yearQ].setdefault(monthQ, [])

                        modelS = {
                            '缴费单位': sSI[q]['aab004'],
                            '缴费时间': sSI[q]['aae002'],
                            '缴费类型': '',
                            '缴费基数': sSI[q]['yac004'],
                            '公司缴费': sSI[q]['dwjfje'],
                            '个人缴费': ''
                        }
                        basedataS[yearQ][monthQ].append(modelS)

                # 六险状态
                stype = self.s.get(
                    "https://gr.cdhrss.gov.cn:442/cdwsjb/personal/query/queryCZInsuranceInfoAction.do"
                )
                stypes = BeautifulSoup(stype.text, 'html.parser').find(
                    'div', {'id': 'SeInfo'})
                stype2 = json.loads(
                    stypes.text.split('data')[40].split(';')[0].replace(
                        '=', ''))['list']
                yanglao = "0"
                yiliao = "0"
                shiye = "0"
                gongshang = "0"
                shengyu = "0"
                dabing = "0"
                for lx in range(len(stype2)):
                    if (stype2[lx]['aae140'] == "110"):
                        yanglao = stype2[lx]['aac031']
                    elif (stype2[lx]['aae140'] == "310"):
                        yiliao = stype2[lx]['aac031']
                    elif (stype2[lx]['aae140'] == "210"):
                        shiye = stype2[lx]['aac031']
                    elif (stype2[lx]['aae140'] == "410"):
                        gongshang = stype2[lx]['aac031']
                    elif (stype2[lx]['aae140'] == "510"):
                        shengyu = stype2[lx]['aac031']
                    elif (stype2[lx]['aae140'] == "330"):
                        dabing = stype2[lx]['aac031']

                social_Type = {
                    '养老': self._convert_type(yanglao),
                    '医疗': self._convert_type(yiliao),
                    '大病': self._convert_type(dabing),
                    '失业': self._convert_type(shiye),
                    '工伤': self._convert_type(gongshang),
                    '生育': self._convert_type(shengyu)
                }

                # 个人基本信息
                if (s['aac031'] == "参保缴费"):
                    status = "正常"
                else:
                    status = "异常"

                mcount = [
                    len(sEI) - 1,
                    len(sHI) - 1,
                    len(sII) - 1,
                    len(sCI) - 1,
                    len(sBI) - 1
                ]  # 缴费时长
                moneyCount = max(mcount)

                recentTime = ""
                startTime = ""
                if (len(sEI) > 0):
                    recentTime = sEI[0]['aae002']
                    startTime = sEI[len(sEI) - 1]['aae002']

                self.result_data['baseInfo'] = {
                    '姓名': s['aac003'],
                    '身份证号': s['aac002'],
                    '更新时间': time.strftime("%Y-%m-%d", time.localtime()),
                    '城市名称': '成都',
                    '城市编号': '510100',
                    '缴费时长': moneyCount,
                    '最近缴费时间': recentTime,
                    '开始缴费时间': startTime,
                    '个人养老累计缴费': peroldTotal,
                    '个人医疗累计缴费': permedicalTotal,
                    '五险状态': social_Type,
                    '账户状态': status,
                    '个人编号': s['aac001'],
                }

                self.result['identity'] = {
                    "task_name": "成都",
                    "target_name": s['aac003'],
                    "target_id": self.result['meta']["用户名"],
                    "status": status
                }

                #return
        except InvalidConditionError as e:
            raise PreconditionNotSatisfiedError(e)
Example #8
0
    def _unit_fetch(self):
        try:
            # TODO: 执行任务,如果没有登录,则raise PermissionError
            # 个人信息
            yanglao = ""
            yiliao = ""
            shiye = ""
            gongshang = ""
            shengyu = ""
            self.result_data['baseInfo'] = {}
            resp = self.s.get(MAIN_URL)
            soup = BeautifulSoup(resp.content, 'html.parser')
            data = soup.find('table', {'class': 'tab3'}).findAll('tr')

            # 社保明细
            startTime = "199001"
            endTime = time.strftime("%Y%m", time.localtime())  # 查询结束时间

            # 社保缴费明细-----养老
            self.result['data']["old_age"] = {"data": {}}
            basedataE = self.result['data']["old_age"]["data"]
            modelE = {}
            peroldTotal = 0.0
            detailEI = self.s.get(Detail_URL + "?xzdm00=2&zmlx00=&qsnyue=" +
                                  startTime + "&jznyue=" + endTime + "")
            sEI = BeautifulSoup(detailEI.content,
                                'html.parser').find('table', {
                                    'class': 'tab5'
                                }).findAll("tr")
            yanglao = sEI[len(sEI) - 1].findAll('td')[2].text

            for b in range(len(sEI)):
                td2 = sEI[b].findAll('td')
                if len(td2) > 1:
                    urlE = "https://app.xmhrss.gov.cn/UCenter/" + sEI[b].find(
                        'a')['href']
                    dateE = BeautifulSoup(
                        self.s.get(urlE).content, 'html.parser').findAll("td")
                    years = re.sub('\s', '', dateE[14].text)[0:4]
                    months = re.sub('\s', '', dateE[14].text)[4:6]
                    basedataE.setdefault(years, {})
                    basedataE[years].setdefault(months, [])

                    modelE = {
                        '缴费时间':
                        re.sub('\s', '', dateE[14].text),
                        '缴费类型':
                        re.sub('\s', '', dateE[10].text),
                        '缴费基数':
                        re.sub('\s', '', dateE[34].text),
                        '公司缴费':
                        dateE[28].text.replace('\t', '').replace('\r',
                                                                 '').replace(
                                                                     '\n', ''),
                        '个人缴费':
                        re.sub('\s', '', dateE[32].text),
                        '缴费单位':
                        re.sub('\s', '', dateE[4].text),
                        '单位划入帐户':
                        float(re.sub('\s', '', dateE[38].text)),
                        '个人划入帐户':
                        float(re.sub('\s', '', dateE[40].text))
                    }

                    if ("已缴费" in re.sub('\s', '', dateE[0].text)
                            and re.sub('\s', '', dateE[32].text) != ''):
                        peroldTotal += float(re.sub('\s', '', dateE[32].text))
                    basedataE[years][months].append(modelE)
                else:
                    raise TaskNotImplementedError("未查询到数据!")

            self.result['data']["medical_care"] = {"data": {}}
            basedataH = self.result['data']["medical_care"]["data"]
            modelH = {}
            permedicalTotal = 0.0
            # 社保明细-----医疗
            detailHI = self.s.get(Detail_URL + "?xzdm00=1&zmlx00=&qsnyue=" +
                                  startTime + "&jznyue=" + endTime + "")
            sHI = BeautifulSoup(detailHI.content,
                                'html.parser').find('table', {
                                    'class': 'tab5'
                                }).findAll("tr")
            yiliao = sHI[len(sHI) - 1].findAll('td')[2].text

            for a in range(len(sHI)):
                td = sHI[a].findAll('td')
                urlH = "https://app.xmhrss.gov.cn/UCenter/" + sHI[a].find(
                    'a')['href']
                dateH = BeautifulSoup(self.s.get(urlH).content,
                                      'html.parser').findAll("td")
                yearH = re.sub('\s', '', dateH[14].text)[0:4]
                monthH = re.sub('\s', '', dateH[14].text)[4:6]
                basedataH.setdefault(yearH, {})
                basedataH[yearH].setdefault(monthH, [])

                modelH = {
                    '缴费时间': re.sub('\s', '', dateH[14].text),
                    '缴费类型': re.sub('\s', '', dateH[10].text),
                    '缴费基数': re.sub('\s', '', dateH[34].text),
                    '公司缴费': float(re.sub('\s', '', dateH[28].text)),
                    '个人缴费': float(re.sub('\s', '', dateH[32].text)),
                    '缴费单位': re.sub('\s', '', dateH[4].text),
                    '单位划入帐户': float(re.sub('\s', '', dateH[38].text)),
                    '个人划入帐户': float(re.sub('\s', '', dateH[40].text))
                }

                if ("已缴费" in re.sub('\s', '', dateH[0].text)):
                    totalmed = float(re.sub('\s', '', dateH[38].text)) + float(
                        re.sub('\s', '', dateH[40].text))
                    permedicalTotal += totalmed

                basedataH[yearH][monthH].append(modelH)

            self.result['data']["unemployment"] = {"data": {}}
            basedataI = self.result['data']["unemployment"]["data"]
            modelI = {}
            # 社保明细-----失业
            detailII = self.s.get(Detail_URL + "?xzdm00=4&zmlx00=&qsnyue=" +
                                  startTime + "&jznyue=" + endTime + "")
            sII = BeautifulSoup(detailII.content,
                                'html.parser').find('table', {
                                    'class': 'tab5'
                                }).findAll("tr")
            if '无查询数据' not in sII[0].text:
                shiye = sII[len(sII) - 1].findAll('td')[2].text

                for c in range(len(sII)):
                    td3 = sII[c].findAll('td')
                    urlI = "https://app.xmhrss.gov.cn/UCenter/" + sII[c].find(
                        'a')['href']
                    dateI = BeautifulSoup(
                        self.s.get(urlI).content, 'html.parser').findAll("td")
                    yearI = re.sub('\s', '', dateI[14].text)[0:4]
                    monthI = re.sub('\s', '', dateI[14].text)[4:6]
                    basedataI.setdefault(yearI, {})
                    basedataI[yearI].setdefault(monthI, [])

                    modelI = {
                        '缴费时间': re.sub('\s', '', dateI[14].text),
                        '缴费类型': re.sub('\s', '', dateI[10].text),
                        '缴费基数': re.sub('\s', '', dateI[34].text),
                        '公司缴费': float(re.sub('\s', '', dateI[28].text)),
                        '个人缴费': float(re.sub('\s', '', dateI[32].text)),
                        '缴费单位': re.sub('\s', '', dateI[4].text),
                        '单位划入帐户': float(re.sub('\s', '', dateI[38].text)),
                        '个人划入帐户': float(re.sub('\s', '', dateI[40].text))
                    }

                    basedataI[yearI][monthI].append(modelI)

            self.result['data']["injuries"] = {"data": {}}
            basedataC = self.result['data']["injuries"]["data"]
            modelC = {}
            # 社保明细-----工伤
            detailCI = self.s.get(Detail_URL + "?xzdm00=3&zmlx00=&qsnyue=" +
                                  startTime + "&jznyue=" + endTime + "")
            sCI = BeautifulSoup(detailCI.content,
                                'html.parser').find('table', {
                                    'class': 'tab5'
                                }).findAll("tr")
            if '无查询数据' not in sCI[0].text:
                gongshang = sCI[len(sCI) - 1].findAll('td')[2].text

                for d in range(len(sCI)):
                    td4 = sCI[d].findAll('td')
                    urlC = "https://app.xmhrss.gov.cn/UCenter/" + sCI[d].find(
                        'a')['href']
                    dateC = BeautifulSoup(
                        self.s.get(urlC).content, 'html.parser').findAll("td")
                    yearC = re.sub('\s', '', dateC[14].text)[0:4]
                    monthC = re.sub('\s', '', dateC[14].text)[4:6]
                    basedataC.setdefault(yearC, {})
                    basedataC[yearC].setdefault(monthC, [])

                    modelC = {
                        '缴费时间': re.sub('\s', '', dateC[14].text),
                        '缴费类型': re.sub('\s', '', dateC[10].text),
                        '缴费基数': re.sub('\s', '', dateC[34].text),
                        '公司缴费': float(re.sub('\s', '', dateC[28].text)),
                        '个人缴费': "",
                        '缴费单位': re.sub('\s', '', dateC[4].text),
                        '单位划入帐户': float(re.sub('\s', '', dateC[38].text)),
                        '个人划入帐户': float(re.sub('\s', '', dateC[40].text))
                    }

                    basedataC[yearC][monthC].append(modelC)

            self.result['data']["maternity"] = {"data": {}}
            basedataB = self.result['data']["maternity"]["data"]
            modelB = {}
            # 社保明细-----生育
            detailBI = self.s.get(Detail_URL + "?xzdm00=5&zmlx00=&qsnyue=" +
                                  startTime + "&jznyue=" + endTime + "")
            sBI = BeautifulSoup(detailBI.content,
                                'html.parser').find('table', {
                                    'class': 'tab5'
                                }).findAll("tr")
            if '无查询数据' not in sBI[0].text:
                shengyu = sBI[len(sBI) - 1].findAll('td')[2].text

                for f in range(len(sBI)):
                    td5 = sBI[f].findAll('td')
                    urlB = "https://app.xmhrss.gov.cn/UCenter/" + sBI[f].find(
                        'a')['href']
                    dateB = BeautifulSoup(
                        self.s.get(urlB).content, 'html.parser').findAll("td")
                    yearB = re.sub('\s', '', dateB[14].text)[0:4]
                    monthB = re.sub('\s', '', dateB[14].text)[4:6]
                    basedataB.setdefault(yearB, {})
                    basedataB[yearB].setdefault(monthB, [])

                    modelB = {
                        '缴费时间':
                        re.sub('\s', '', dateB[14].text),
                        '缴费类型':
                        re.sub('\s', '', dateB[10].text),
                        '缴费基数':
                        re.sub('\s', '', dateB[34].text),
                        '公司缴费':
                        float(dateB[28].text.replace('\t', '').replace(
                            '\r', '').replace('\n', '')),
                        '个人缴费':
                        "",
                        '缴费单位':
                        re.sub('\s', '', dateB[4].text),
                        '单位划入帐户':
                        float(re.sub('\s', '', dateB[38].text)),
                        '个人划入帐户':
                        float(re.sub('\s', '', dateB[40].text))
                    }

                    basedataB[yearB][monthB].append(modelB)

            # 大病明细
            self.result['data']["serious_illness"] = {"data": {}}

            # 五险状态
            social_type = {
                '养老': re.sub('\s', '', yanglao),
                '医疗': re.sub('\s', '', yiliao),
                '失业': re.sub('\s', '', shiye),
                '工伤': re.sub('\s', '', gongshang),
                '生育': re.sub('\s', '', shengyu)
            }

            #  个人基本信息
            # 缴费时长
            moneyCount = [len(sEI), len(sHI), len(sII), len(sCI), len(sBI)]

            self.result_data['baseInfo'] = {
                '姓名':
                data[0].findAll('td')[1].text,
                '身份证号':
                data[1].findAll('td')[1].text,
                '更新时间':
                time.strftime("%Y-%m-%d", time.localtime()),
                '城市名称':
                '厦门',
                '城市编号':
                '350200',
                '缴费时长':
                max(moneyCount),
                '最近缴费时间':
                re.sub('\s', '', sEI[len(sEI) - 1].findAll("td")[3].text),
                '开始缴费时间':
                re.sub('\s', '', sEI[0].findAll("td")[3].text),
                '个人养老累计缴费':
                peroldTotal,
                '个人医疗累计缴费':
                permedicalTotal,
                '五险状态':
                social_type,
                '账户状态':
                self._convert_type(data[3].findAll('td')[1].text.replace(
                    '\r', '').replace('\n', '').replace('\t', '').strip()),
                '人员状态':
                data[8].findAll('td')[1].text,
                '社会保障卡卡号':
                data[2].findAll('td')[1].text,
            }

            self.result['identity'] = {
                "task_name":
                "厦门",
                "target_name":
                data[0].findAll('td')[1].text,
                "target_id":
                self.result_meta['社保号'],
                "status":
                self._convert_type(data[3].findAll('td')[1].text.replace(
                    '\r', '').replace('\n', '').replace('\t', '').strip())
            }

            return
        except InvalidConditionError as e:
            raise PreconditionNotSatisfiedError(e)