コード例 #1
0
    def save_bangumi(data: WebsiteBangumi) -> None:
        """save bangumi to database"""
        b, obj_created = Bangumi.get_or_create(keyword=data.keyword,
                                               defaults=data.dict())
        if not obj_created:
            should_save = False
            if data.cover and b.cover != data.cover:
                b.cover = data.cover
                should_save = True

            if data.update_time != "Unknown" and data.update_time != b.update_time:
                b.update_time = data.update_time
                should_save = True

            subtitle_group = Bangumi(
                subtitle_group=data.subtitle_group).subtitle_group

            if b.status != STATUS_UPDATING or b.subtitle_group != subtitle_group:
                b.status = STATUS_UPDATING
                b.subtitle_group = subtitle_group
                should_save = True

            if should_save:
                b.save()

        for subtitle_group in data.subtitle_group:
            (Subtitle.insert({
                Subtitle.id: str(subtitle_group.id),
                Subtitle.name: str(subtitle_group.name),
            }).on_conflict_replace()).execute()
コード例 #2
0
ファイル: base.py プロジェクト: zhkrb/BGmi
    def fetch(self, save=False, group_by_weekday=True):
        bangumi_result, subtitle_group_result = self.fetch_bangumi_calendar_and_subtitle_group(
        )
        Bangumi.delete_all()
        if subtitle_group_result:
            for subtitle_group in subtitle_group_result:
                (Subtitle.insert({
                    Subtitle.id:
                    text_type(subtitle_group['id']),
                    Subtitle.name:
                    text_type(subtitle_group['name'])
                }).on_conflict_replace()).execute()
        if not bangumi_result:
            print('no result return None')
            return []

        for bangumi in bangumi_result:
            bangumi['cover'] = self.cover_url + bangumi['cover']

        if save:
            for bangumi in bangumi_result:
                self.save_data(bangumi)
        if group_by_weekday:
            result_group_by_weekday = defaultdict(list)
            for bangumi in bangumi_result:
                result_group_by_weekday[bangumi['update_time'].lower()].append(
                    bangumi)
            bangumi_result = result_group_by_weekday
        return bangumi_result
コード例 #3
0
ファイル: base.py プロジェクト: moeoverflow/BGmi
    def fetch(self, save=False, group_by_weekday=True):
        (
            bangumi_result,
            subtitle_group_result,
        ) = self.fetch_bangumi_calendar_and_subtitle_group()
        Bangumi.delete_all()
        if subtitle_group_result:
            for subtitle_group in subtitle_group_result:
                (Subtitle.insert({
                    Subtitle.id: str(subtitle_group["id"]),
                    Subtitle.name: str(subtitle_group["name"]),
                }).on_conflict_replace()).execute()
        if not bangumi_result:
            print("no result return None")
            return []

        for bangumi in bangumi_result:
            bangumi["cover"] = self.cover_url + bangumi["cover"]

        if save:
            for bangumi in bangumi_result:
                self.save_data(bangumi)

        if group_by_weekday:
            result_group_by_weekday = defaultdict(list)
            for bangumi in bangumi_result:
                result_group_by_weekday[bangumi["update_time"].lower()].append(
                    bangumi)
            bangumi_result = result_group_by_weekday
        return bangumi_result