Пример #1
0
    def find_my_projects(cls, account, type):
        """Find projects for a user, based on hers/his needs: to practice or
        to learn. Save the data in the database.
        """
        connection = Github(login_or_token=account.github_token)

        # Find user Skills
        repos = connection.get_user().get_repos()
        cls.find_account_skills(account, repos)

        # Search for projects based on what skills he wants to practice
        wanted_skills = cls.get_account_wanted_skills(account, type)
        # If the user doesn't have any skills and she/he wants to practice,
        # return none, let him start a project on his own / learn.
        if len(wanted_skills) == 0 and type == ProjectTypes.PRACTICE:
            return

        # We need the names for the GH query.
        wanted_languages = [skill.name.lower() for skill in wanted_skills]

        # Set query to find an active project
        stars = '%d..%d' % (MIN_STARS, MAX_STARS)
        forks = '%d..%d' % (MIN_FORKS, MAX_FORKS)
        pushed = '>%s' % get_last_month()
        qualifiers = {'stars': stars, 'forks': forks, 'pushed': pushed}

        # Search GH API for projects per each language.
        repos = []
        for wanted_language in wanted_languages:
            query = 'language:%s' % wanted_language

            repos_per_lang = connection.search_repositories(
                query=query, sort='stars', order='desc', **qualifiers)

            repos.extend(repos_per_lang.get_page(0)[:MAX_PROJECTS])

        # Save the projects which are a match for the user.
        cls.find_account_projects(account, repos, type)