当前位置: 首页>>代码示例>>Python>>正文


Python DBManager.session_add_expunge方法代码示例

本文整理汇总了Python中pajbot.managers.db.DBManager.session_add_expunge方法的典型用法代码示例。如果您正苦于以下问题:Python DBManager.session_add_expunge方法的具体用法?Python DBManager.session_add_expunge怎么用?Python DBManager.session_add_expunge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pajbot.managers.db.DBManager的用法示例。


在下文中一共展示了DBManager.session_add_expunge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: refresh_video_url_stage2

# 需要导入模块: from pajbot.managers.db import DBManager [as 别名]
# 或者: from pajbot.managers.db.DBManager import session_add_expunge [as 别名]
    def refresh_video_url_stage2(self, data):
        if self.online is False:
            return

        if self.current_stream_chunk is None or self.current_stream is None:
            return

        log.info('Attempting to fetch video url for broadcast {0}'.format(self.current_stream_chunk.broadcast_id))
        stream_chunk = self.current_stream_chunk if self.current_stream_chunk.video_url is None else None
        video_url, video_preview_image_url, video_recorded_at = self.fetch_video_url_stage2(data)
        if video_url is not None:
            log.info('Successfully fetched a video url: {0}'.format(video_url))
            if self.current_stream_chunk is None or self.current_stream_chunk.video_url is None:
                with DBManager.create_session_scope(expire_on_commit=False) as db_session:
                    self.current_stream_chunk.video_url = video_url
                    self.current_stream_chunk.video_preview_image_url = video_preview_image_url

                    db_session.add(self.current_stream_chunk)

                    db_session.commit()

                    db_session.expunge_all()
                log.info('Successfully commited video url data.')
            elif self.current_stream_chunk.video_url != video_url:
                # End current stream chunk
                self.current_stream_chunk.chunk_end = datetime.datetime.now()
                DBManager.session_add_expunge(self.current_stream_chunk)

                with DBManager.create_session_scope(expire_on_commit=False) as db_session:
                    stream_chunk = StreamChunk(self.current_stream, self.current_stream_chunk.broadcast_id, video_recorded_at)
                    self.current_stream_chunk = stream_chunk
                    self.current_stream_chunk.video_url = video_url
                    self.current_stream_chunk.video_preview_image_url = video_preview_image_url

                    db_session.add(self.current_stream_chunk)

                    db_session.commit()

                    db_session.expunge_all()
                log.info('Successfully commited video url data in a new chunk.')
        else:
            log.info('Not video for broadcast found')
开发者ID:Neclord9,项目名称:pajbot,代码行数:44,代码来源:stream.py

示例2: create_stream_chunk

# 需要导入模块: from pajbot.managers.db import DBManager [as 别名]
# 或者: from pajbot.managers.db.DBManager import session_add_expunge [as 别名]
    def create_stream_chunk(self, status):
        if self.current_stream_chunk is not None:
            # There's already a stream chunk started!
            self.current_stream_chunk.chunk_end = datetime.datetime.now()
            DBManager.session_add_expunge(self.current_stream_chunk)

        stream_chunk = None

        with DBManager.create_session_scope(expire_on_commit=False) as db_session:
            stream_chunk = db_session.query(StreamChunk).filter_by(broadcast_id=status['broadcast_id']).one_or_none()
            if stream_chunk is None:
                log.info('Creating stream chunk, from create_stream_chunk')
                stream_chunk = StreamChunk(self.current_stream, status['broadcast_id'], status['created_at'])
                self.current_stream_chunk = stream_chunk
                db_session.add(stream_chunk)
                db_session.commit()
            else:
                log.info('We already have a stream chunk!')
                self.current_stream_chunk = stream_chunk
                stream_chunk = None
            db_session.expunge_all()

        if stream_chunk:
            self.current_stream.stream_chunks.append(stream_chunk)
开发者ID:Neclord9,项目名称:pajbot,代码行数:26,代码来源:stream.py

示例3: add_banphrase

# 需要导入模块: from pajbot.managers.db import DBManager [as 别名]
# 或者: from pajbot.managers.db.DBManager import session_add_expunge [as 别名]
    def add_banphrase(self, **options):
        """Method for creating and editing banphrases.
        Usage: !add banphrase BANPHRASE [options]
        Multiple options available:
        --length LENGTH
        --perma/--no-perma
        --notify/--no-notify
        """

        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            options, phrase = bot.banphrase_manager.parse_banphrase_arguments(message)

            if options is False:
                bot.whisper(source.username, 'Invalid banphrase')
                return False

            options['added_by'] = source.id
            options['edited_by'] = source.id

            banphrase, new_banphrase = bot.banphrase_manager.create_banphrase(phrase, **options)

            if new_banphrase is True:
                bot.whisper(source.username, 'Added your banphrase (ID: {banphrase.id})'.format(banphrase=banphrase))
                AdminLogManager.post('Banphrase added', source, phrase)
                return True

            banphrase.set(**options)
            banphrase.data.set(edited_by=options['edited_by'])
            DBManager.session_add_expunge(banphrase)
            bot.banphrase_manager.commit()
            bot.whisper(source.username, 'Updated your banphrase (ID: {banphrase.id}) with ({what})'.format(banphrase=banphrase, what=', '.join([key for key in options if key != 'added_by'])))
            AdminLogManager.post('Banphrase edited', source, phrase)
开发者ID:Neclord9,项目名称:pajbot,代码行数:38,代码来源:banphrase.py

示例4: edit_command

# 需要导入模块: from pajbot.managers.db import DBManager [as 别名]
# 或者: from pajbot.managers.db.DBManager import session_add_expunge [as 别名]
 def edit_command(self, command_to_edit, **options):
     command_to_edit.set(**options)
     command_to_edit.data.set(**options)
     DBManager.session_add_expunge(command_to_edit)
     self.commit()
开发者ID:jardg,项目名称:pajbot,代码行数:7,代码来源:command.py


注:本文中的pajbot.managers.db.DBManager.session_add_expunge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。