Пример #1
0
    def execute(self):
        while True:
            try:
                expired = self.accessToken.isTokenExpired()
                break
            except Exception as e:
                logger.info('Access key is not found')
            time.sleep(10)

        if expired:
            logger.info('Access token expired. Try to get new')
            self.accessToken.handleRefreshToken(self.config.getAccessToken().getRefreshToken())

        resumes = self.resumeService.get_published_resumes()

        # Resumes read
        for resume in resumes:
            # Who watched our resume
            self.resume_check_views_handler.handle(resume.get_id())

            # Bump if it is possibly
            self.resume_bump_handler.handle(resume)

            # Collect black list
            self.resume_collect_black_list_handler.handle(resume)

        # Resumes write
        for resume in resumes:
            self.resume_update_black_list_handler.handle(resume)

        # Update resume description
        for resume in resumes:
            self.resume_update_description_handler.handle(resume)
Пример #2
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)
Пример #3
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
Пример #4
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)
Пример #5
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)
Пример #6
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']
Пример #7
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']
Пример #8
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)
Пример #9
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)
Пример #10
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')
Пример #11
0
import time
import locale

from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())

from classes.refresher import Refresher
from classes.utils.logger import logger

locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')

if __name__ == "__main__":
    logger.info('Server was started')

    while True:
        client = Refresher()
        client.execute()
        logger.info('Wait next iteration')
        time.sleep(60 * 5)