Пример #1
0
 def resume_import(self, importid):
     # 历史记录初始化
     imp = ImpHistory.new(self.bind.company_id, self.bind.site_id, importid)
     imp.save()
     # 缓存记录初始化
     key = Conf.RESUME_IMPORT_HKEY % self.taskid
     ResumeRedisCli.hmset(
         key,
         {
             'total': 0,
             'grab': 0,
             'success': 0,
             'ignore': 0,
             'failure': 0,
             'finish': 0,
             'siteid': self.bind.site_id,  # 来源招聘平台
             'importid': importid,  # 来源id,用於追溯
             'companyid': self.bind.company_id,
             'imphistoryid': imp.history_id  # 后续存储imp_history_resume时使用
         })
     # 设置数据过期时间
     ResumeRedisCli.expire(key, 60 * 60 * 24)
Пример #2
0
def ParseLocalResume(companyid, taskid, importid):
    row = ImpLocalFile.queryByImportId(importid)
    if row:
        sitename = SiteConfig.getSiteNameById(row.from_site_id)
        logger.info(u'开始解析<{}>的本地简历'.format(sitename))
        row.proc_status = 10
        imp = ImpHistory.new(row.company_id, row.from_site_id, row.import_id,
                             row.input_type)
        if row.input_type == 1:
            imp.src_memo = row.user_file_name
        if not imp.save():
            return
        # 异常信息提示
        log_msg = u''
        try:
            if row.input_type == 1:
                log_msg = u'简历文件<{}>解析'.format(row.user_file_name)
                # 数据库存储类型为hex编码,此处进行解码
                content = base64.b64encode(row.file_content)
                ext = os.path.splitext(row.user_file_name)[-1]
                ret = _doResumeParseByFile(content, ext)
            else:
                log_msg = u'简历文本解析'
                content = row.input_content
                ret = _doResumeParseByString(content)
            if ret:
                js = json.loads(ret)
                if js['Type'] > 0 and js['Name']:
                    js['companyid'] = row.company_id
                    js['siteid'] = row.from_site_id
                    if js['WebSiteResumeID']:
                        js['websiteresumeid'] = js['WebSiteResumeID']
                    else:
                        js['websiteresumeid'] = 'Local{0}'.format(
                            row.import_id)
                    js['jobid'] = ''
                    js['source'] = 0
                    js['apply_job_id'] = row.apply_job_id
                    js['apply_time'] = datetime2str(datetime.today())
                    (res, message, new) = AssembelResumeByJson(js)
                    if res:
                        row.resume_code = message
                        row.proc_status = 20
                        # 保存简历历史详细记录
                        if ImpHistoryResume.newAndSave(imp.history_id,
                                                       row.company_id,
                                                       message):
                            # 保存简历历史记录
                            imp.succ_num = 1
                            imp.proc_status = 1
                            message = u'{}成功'.format(log_msg)
                            logger.info(message)
                        else:
                            message = u'数据存储失败'
                            logger.error('{}失败,{}'.format(log_msg, message))
                            imp.fail_num = 1
                            imp.proc_status = 2
                            imp.fail_reason = message
                    else:
                        logger.error('{}失败,{}'.format(log_msg, message))
                        imp.fail_num = 1
                        imp.proc_status = 2
                        imp.fail_reason = message
                else:
                    message = u'简历内容为空'
                    logger.error('{}失败,{}'.format(log_msg, message))
                    imp.fail_num = 1
                    imp.proc_status = 2
                    imp.fail_reason = message
            else:
                message = u'解析结果为空'
                logger.error('{}失败,{}'.format(log_msg, message))
                imp.fail_num = 1
                imp.proc_status = 2
                imp.fail_reason = message
        except BaseException as e:
            message = u'{}异常,原因:{}'.format(log_msg, e)
            logger.error(message)
            imp.fail_num = 1
            imp.proc_status = 2
            imp.fail_reason = u'内部服务错误!'
        # 历史结果存储
        row.save()
        imp.end_time = datetime.today()
        imp.save()
Пример #3
0
def pull_email(emailconf, companyid, taskid, importid, syncid):
    pop, error_message = pop3(emailconf.pop3_host, emailconf.pop3_port,
                              emailconf.email_user, emailconf.email_password,
                              emailconf.is_ssl == 'T')
    if pop:
        try:
            try:
                typ, uidls, octets = pop.uidl()
            except error_proto as e:
                logger.error(u'[-] 获取邮箱<{}>状态失败,原因:{0}'.format(
                    emailconf.email_user, e))
                return
            if len(uidls) > 0:
                msgs = []
                setkey = MAIL_SET_KEY % emailconf.email_user
                # 过滤已下载邮件
                for item in uidls:
                    mid, uidl = item.split()
                    if not MailRedisCli.sismember(setkey, uidl):
                        msgs.append((mid, uidl))
                if len(msgs) > 0:
                    logger.info(u'[+] 邮箱<{}>待下载 {} 封未读邮件...'.format(
                        emailconf.email_user, len(msgs)))
                    imp = ImpHistory.new(emailconf.company_id, 0,
                                         emailconf.import_id, 3)
                    imp.src_memo = emailconf.email_user
                    if imp.save():
                        key = Conf.RESUME_IMPORT_HKEY % taskid
                        ResumeRedisCli.hmset(
                            key,
                            {
                                'total': 0,
                                'grab': 0,
                                'success': 0,
                                'ignore': 0,
                                'failure': 0,
                                'finish': 0,
                                'siteid': emailconf.email_user,  # 邮箱地址
                                'importid': importid,  # 来源id,用於追溯
                                'companyid': companyid,
                                'imphistoryid':
                                imp.history_id,  # 后续存储imp_history_resume时使用
                                'syncid': syncid
                            })
                        for mid, uidl in msgs:
                            download_email(pop, emailconf, mid, uidl, taskid)
                        ResumeRedisCli.hincrby(
                            Conf.RESUME_IMPORT_HKEY % taskid, 'finish')
                        dtc. async (
                            'zpb.service.stateservice.CheckEmailImportStat',
                            taskid)
                        logger.info(u'[+] 邮箱<{}>已下载 {} 封未读邮件!'.format(
                            emailconf.email_user, len(msgs)))
                else:
                    logger.info(u'[+] 邮箱<{}>没有未读邮件!'.format(
                        emailconf.email_user))
            else:
                logger.info(u'[-] 邮箱<{}>没有任何邮件!'.format(emailconf.email_user))
        finally:
            pop.quit()
    elif error_message:
        emailconf.is_valid = 'F'
        emailconf.import_memo = error_message
        emailconf.save()