コード例 #1
0
class ResumeBlackListService:
    def __init__(self):
        self.repository = HeadHunterRepository()

    def getBlackListIdsByResumeId(self, resumeId):
        response = self.repository.get_black_list_companies_by_resume_id(resumeId)
        return set(map(lambda x: x.get('id'), response))

    def setBlackListCompaniesByResumeId(self, resumeId, blackListSet: Set[str]) -> None:
        data = {
            'items': list(map(lambda x: {'id': x}, blackListSet))
        }
        self.repository.set_black_list_companies_by_resume_id(resumeId, data)
コード例 #2
0
class ResumeCheckViewsHandler:
    AGENCY_TYPE = 'agency'
    repo = HeadHunterRepository()
    resume_black_list_service = ResumeBlackListService()

    def handle(self, resume_id: str):
        result = []
        got_employers_ids = []  # Control of duplicates
        employers = self.repo.get_views_history_by_resume_id(resume_id)

        for employer in employers.get('items'):
            employer_id = employer.get('employer').get('id')

            if employer_id in got_employers_ids:
                continue

            employer_data = self.repo.get_employer_by_id(employer_id)

            if employer_data and employer_data.get(
                    'type') == ResumeCheckViewsHandler.AGENCY_TYPE:
                result.append(employer_id)

            got_employers_ids.append(employer_id)

        self.__set_black_list(resume_id, result)

    def __set_black_list(self, resume_id: str, ids: List):
        data = self.resume_black_list_service.getBlackListIdsByResumeId(
            resume_id)
        if ids:
            for i in ids:
                if i not in data:
                    data.add(i)
            self.resume_black_list_service.setBlackListCompaniesByResumeId(
                resume_id, data)
コード例 #3
0
class ResumeUpdateDescriptionHandler:
    def __init__(self):
        self.hh_repository = HeadHunterRepository()

    def handle(self, resume: ResumeEntity) -> None:
        content = f"""{DESCRIPTION}
        
Информация от бота, который управляет этим резюме:
{self.get_date_latest_bot_work_message(datetime.now())}
{self.get_similar_vacancies_message(resume.get_similar_vacancies_count())}
{self.get_total_views_message(resume.get_total_views())}
{self.get_blocked_companies_message(resume)}
        """
        self.hh_repository.set_resume_description_by_id(
            resume.get_id(), content)

    @staticmethod
    def get_similar_vacancies_message(count_vacancies: int) -> str:
        return f'Подходящих вакансий: {count_vacancies}'

    @staticmethod
    def get_date_latest_bot_work_message(updated_date: datetime) -> str:
        return f'Дата последней работы бота: {updated_date.strftime("%d %B %Y %H:%M:%S")}'

    def get_blocked_companies_message(self, resume: ResumeEntity) -> str:
        black_list_companies_text = ''
        if resume.get_access_type() == resume.ACCESS_TYPE_BLACKLIST:
            count = self.hh_repository.get_black_list_companies_count_by_resume_id(
                resume.get_id())
            black_list_companies_text = f'Количество заблокированных компаний: {count}'

        return black_list_companies_text

    @staticmethod
    def get_total_views_message(total_views: int) -> str:
        return f'Всего просмотров этого резюме: {total_views}'
コード例 #4
0
class ResumeService:
    repository = None

    def __init__(self):
        self.repository = HeadHunterRepository()

    def get_resumes(self) -> List[ResumeEntity]:
        result = []
        resumes = self.repository.get_resumes()
        for resume in resumes:
            result.append(ResumeEntity.createFromResponse(resume))

        return result

    def get_published_resumes(self) -> List[ResumeEntity]:
        return list(
            filter(
                lambda resume: resume.get_access_type() != resume.
                ACCESS_TYPE_NO_ONE, self.get_resumes()))
コード例 #5
0
 def __init__(self):
     self.repository = HeadHunterRepository()