Пример #1
0
 def bump(self, resume_id: str) -> None:
     try:
         requests.post(
             f"{self.config.getApiUrl()}resumes/{resume_id}/publish",
             headers=self.config.getAuthHeader())
         logger.info(f'Bumped resume: {resume_id}')
     except Exception as e:
         logger.error(e)
Пример #2
0
    def set_black_list_companies_by_resume_id(self, resumeId,
                                              data: dict) -> bool:
        try:
            requests.post(self.config.getResumeBlackListEndpoint(resumeId),
                          json=data,
                          headers=self.config.getAuthHeader())
            logger.info(f'Updated black_list for: {resumeId}')
        except Exception as e:
            logger.error(e)
            return False

        return True
Пример #3
0
    def handleRefreshToken(self, refresh_token: str) -> None:
        try:
            response = requests.post(self.config.getOauthTokenEndpoint(), {
                'grant_type': 'refresh_token',
                'refresh_token': refresh_token,
            })
            result = json.loads(response.text)

            if 'access_token' in result:
                logger.info('Refresh access_token')
                self.config.setAccessToken(AccessTokenEntity(result))
        except Exception as e:
            logger.error(e)
Пример #4
0
    def get_views_history_by_resume_id(self, resume_id: str):
        while True:
            try:
                response = requests.get(
                    self.config.get_resume_views_history(resume_id),
                    headers=self.config.getAuthHeader())

                if response.ok:
                    logger.info(
                        f'Got views_history for resume_id: {resume_id}')
                    return response.json()

            except Exception as e:
                logger.error(e)

            time.sleep(10)
Пример #5
0
    def get_resumes(self):
        try:
            response = requests.get(self.config.getMyResumesEndpoint(),
                                    headers=self.config.getAuthHeader())
        except Exception as e:
            logger.error(e, exc_info=True)
            return []

        response_dict = json.loads(response.text)

        if 'items' not in response_dict:
            logger.error(response_dict, exc_info=True)
            return []

        logger.info('Got resumes')

        return response_dict['items']
Пример #6
0
    def get_black_list_companies_by_resume_id(self, resume_id):
        try:
            response = requests.get(
                self.config.getResumeBlackListEndpoint(resume_id),
                headers=self.config.getAuthHeader())
        except Exception as e:
            logger.error(e, exc_info=True)
            return []

        response_dict = json.loads(response.text)

        if 'items' not in response_dict:
            logger.error(response_dict)
            return []

        logger.info(f'Got black_list companies for resumeId: {resume_id}')

        return response_dict['items']
Пример #7
0
    def set_resume_description_by_id(self, resume_id: str, description: str):
        try:
            logger.info(f'Try to update resume description {resume_id}')
            url = self.config.get_resume_id_endpoint(resume_id)

            response = requests.put(url,
                                    json={'skills': description},
                                    headers=self.config.getAuthHeader())

            if response.status_code == 204 and response.ok:
                logger.info(f'Successful update resume {resume_id}')
                return response.status_code

            logger.error(
                f'Resume {resume_id} not found. This is weird! {response.status_code} ({url})'
            )
            return response.status_code
        except Exception as e:
            logger.error(e, exc_info=True)
Пример #8
0
    def get_employer_by_id(self, employer_id: str):
        while True:
            try:
                logger.info(f'Try to get info about employer_id {employer_id}')
                url = self.config.get_employer_by_id(employer_id)
                response = requests.get(url,
                                        headers=self.config.getAuthHeader())

                if response.status_code == 200 and response.ok:
                    logger.info(f'Got employer_id {employer_id}')
                    return response.json()

                logger.warn(
                    f'Employer {employer_id} not found. This is weird! {response.status_code} ({url})'
                )
                return {}
            except Exception as e:
                logger.error(e, exc_info=True)

            time.sleep(10)
Пример #9
0
    def get_black_list_companies_count_by_resume_id(self,
                                                    resume_id: str) -> int:
        try:
            response = requests.get(
                self.config.getResumeBlackListEndpoint(resume_id),
                headers=self.config.getAuthHeader())
        except Exception as e:
            logger.error(e, exc_info=True)
            return 0

        response_dict = json.loads(response.text)

        if 'found' not in response_dict:
            logger.error(response_dict)
            return 0

        logger.info(
            f'Got {response_dict.get("found")} black_listed companies for resumeId: {resume_id}'
        )

        return response_dict.get('found')
Пример #10
0
    def handle(self) -> Union[bool, str]:
        try:
            response = requests.post(self.config.getOauthTokenEndpoint(),
                                     {
                                         'grant_type': 'client_credentials',
                                         'client_id': self.config.getAppId(),
                                         'client_secret': self.config.getAppSecret(),
                                     }
                                     )
        except Exception as e:
            logger.error(e)
            return False

        responseDict = json.loads(response.text)

        if 'error' in responseDict:
            logger.error(responseDict.get('error'))
            return False

        if 'access_token' in responseDict:
            self.config.setAccessToken(AccessTokenEntity(responseDict))

        return True