Пример #1
0
    async def async_init(self):
        language_qq = session.query(Language_DB).\
            filter(Language_DB.key.in_(self._languages))
        language_q = session.query(Language_DB.key).\
            filter(Language_DB.key.in_(self._languages)).all()
        language_q = list(map(itemgetter(0), language_q))
        for language_key in self._languages:
            if language_key not in language_q:
                api = API()
                await api.get_languages()
                for language in api.data.objects:
                    if language.key == language_key:
                        session.add(Language_DB(language))
                        session.commit()
                        break
        self.languages = language_qq.all()

        organization_qq = session.query(Organization_DB).\
            filter(Organization_DB.id.in_(self._organizations))
        organization_q = session.query(Organization_DB.id).\
            filter(Organization_DB.id.in_(self._organizations)).all()
        organization_q = list(map(itemgetter(0), organization_q))
        for organization_id in self._organizations:
            if organization_id not in organization_q:
                api = API()
                await api.get_organizations()
                for organization in api.data.objects:
                    if organization.id == organization_id:
                        session.add(Organization_DB(organization))
                        session.commit()
                        break
        self.organizations = organization_qq.all()
Пример #2
0
    async def async_init(self):
        organization_qq = session.query(Organization_DB).filter(
            Organization_DB.id.in_(self._organizations))
        organization_q = session.query(Organization_DB.id).filter(
            Organization_DB.id.in_(self._organizations)).all()
        organization_q = list(map(itemgetter(0), organization_q))
        for organization_id in self._organizations:
            if organization_id not in organization_q:
                api = API()
                await api.get_organizations()
                for organization in api.data.objects:
                    if organization.id not in organization_q and organization.id in self._organizations:
                        session.add(Organization_DB(organization))
                        session.commit()
                break
        self.organizations = organization_qq.all()

        # perhaps I should check if it's the general or detailed version
        self._problem_codes = list(map(itemgetter("code"), self._problems))
        problem_qq = session.query(Problem_DB).filter(
            Problem_DB.code.in_(self._problem_codes))
        problem_q = session.query(Problem_DB.code).filter(
            Problem_DB.code.in_(self._problem_codes)).all()
        problem_q = list(map(itemgetter(0), problem_q))
        for problem_dict in self._problems:
            problem_code = problem_dict["code"]
            try:
                if problem_code not in problem_q:
                    api = API()
                    await api.get_problem(problem_code)
                    session.add(Problem_DB(api.data.object))
                    session.commit()
            except ObjectNotFound:
                pass
        self.problems = problem_qq.all()
Пример #3
0
    async def async_init(self):
        problem_qq = session.query(Problem_DB).filter(
            Problem_DB.code.in_(self._solved_problems))
        problem_q = session.query(Problem_DB.code).filter(
            Problem_DB.code.in_(self._solved_problems)).all()
        problem_q = list(map(itemgetter(0), problem_q))
        for problem_code in self._solved_problems:
            try:
                if problem_code not in problem_q:
                    api = API()
                    await api.get_problem(problem_code)
                    session.add(Problem_DB(api.data.object))
                    session.commit()
            except ObjectNotFound:
                pass
        self.solved_problems = problem_qq.all()

        organization_qq = session.query(Organization_DB).filter(
            Organization_DB.id.in_(self._organizations))
        organization_q = session.query(Organization_DB.id).filter(
            Organization_DB.id.in_(self._organizations)).all()
        organization_q = list(map(itemgetter(0), organization_q))
        for organization_id in self._organizations:
            if organization_id not in organization_q:
                api = API()
                await api.get_organizations()
                for organization in api.data.objects:
                    if organization.id not in organization_q and organization.id in self._organizations:
                        session.add(Organization_DB(organization))
                        session.commit()
                break
        self.organizations = organization_qq.all()

        for contest in self._contests:
            if contest["rating"]:
                self.max_rating = max(self.max_rating or 0, contest["rating"])

        self._contest_keys = list(map(itemgetter("key"), self._contests))

        contest_qq = session.query(Contest_DB).filter(
            Contest_DB.key.in_(self._contest_keys))
        contest_q = session.query(Contest_DB.key).filter(
            Contest_DB.key.in_(self._contest_keys)).all()
        contest_q = list(map(itemgetter(0), contest_q))
        for contest_key in self._contest_keys:
            try:
                if contest_key not in contest_q:
                    api = API()
                    await api.get_contest(contest_key)
                    # This causes db errors, and in the case the above doesn't catch it.
                    # This will be a last ditch effort
                    if session.query(Contest_DB).filter(
                            Contest_DB.key == contest_key).count():
                        continue
                    session.add(Contest_DB(api.data.object))
                    session.commit()
            except ObjectNotFound:
                pass
        self.contests = contest_qq.all()
Пример #4
0
    async def async_init(self):
        problem_qq = session.query(Problem_DB).\
            filter(Problem_DB.code.in_(self._solved_problems))
        problem_q = session.query(Problem_DB.code).\
            filter(Problem_DB.code.in_(self._solved_problems)).all()
        problem_q = list(map(itemgetter(0), problem_q))
        for problem_code in self._solved_problems:
            try:
                if problem_code not in problem_q:
                    api = API()
                    await api.get_problem(problem_code)
                    session.add(Problem_DB(api.data.object))
                    session.commit()
            except ObjectNotFound:
                pass
        self.solved_problems = problem_qq.all()

        organization_qq = session.query(Organization_DB).\
            filter(Organization_DB.id.in_(self._organizations))
        organization_q = session.query(Organization_DB.id).\
            filter(Organization_DB.id.in_(self._organizations)).all()
        organization_q = list(map(itemgetter(0), organization_q))
        for organization_id in self._organizations:
            if organization_id not in organization_q:
                api = API()
                await api.get_organizations()
                for organization in api.data.objects:
                    if (organization.id not in organization_q
                            and organization.id in self._organizations):
                        session.add(Organization_DB(organization))
                        session.commit()
                break
        self.organizations = organization_qq.all()

        def get_key(contest):
            return contest["key"]

        self._contest_keys = list(map(get_key, self._contests))

        contest_qq = session.query(Contest_DB).\
            filter(Contest_DB.key.in_(self._contest_keys))
        contest_q = session.query(Contest_DB.key).\
            filter(Contest_DB.key.in_(self._contest_keys)).all()
        contest_q = list(map(itemgetter(0), contest_q))
        for contest_key in self._contest_keys:
            try:
                if contest_key not in contest_q:
                    api = API()
                    await api.get_contest(contest_key)
                    session.add(Contest_DB(api.data.object))
                    session.commit()
            except ObjectNotFound:
                pass
        self.contests = contest_qq.all()