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


Python DBManager.create_session方法代码示例

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


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

示例1: create_stream_chunk

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def create_stream_chunk(self, status):

        if self.current_stream_chunk is not None:
            # There's already a stream chunk started!
            session = DBManager.create_session(expire_on_commit=False)
            self.current_stream_chunk.chunk_end = datetime.datetime.now()
            session.add(self.current_stream_chunk)
            session.commit()
            session.close()
            self.current_stream_chunk = None

        session = DBManager.create_session(expire_on_commit=False)
        stream_chunk = 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
            session.add(stream_chunk)
            session.commit()
        else:
            log.info('We already have a stream chunk!')
            self.current_stream_chunk = stream_chunk
        session.expunge_all()
        session.close()

        self.current_stream.stream_chunks.append(stream_chunk)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:28,代码来源:stream.py

示例2: decks_warrior

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def decks_warrior():
    session = DBManager.create_session()
    decks = session.query(Deck).filter_by(deck_class='warrior').order_by(Deck.last_used.desc(), Deck.first_used.desc()).all()
    session.close()
    return render_template('decks/by_class.html',
            decks=decks,
            deck_class='Warrior')
开发者ID:savageboy74,项目名称:tyggbot,代码行数:9,代码来源:app.py

示例3: create_highlight

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def create_highlight(self, **options):
        """
        Returns an error message (string) if something went wrong, otherwise returns True
        """
        if self.online is False or self.current_stream_chunk is None:
            return 'The stream is not online'

        if self.current_stream_chunk.video_url is None:
            return 'No video URL fetched for this chunk yet, try in 5 minutes'

        try:
            highlight = StreamChunkHighlight(self.current_stream_chunk, **options)

            session = DBManager.create_session(expire_on_commit=False)
            session.add(highlight)
            session.add(self.current_stream_chunk)
            session.commit()
            session.close()

            x = inspect(self.current_stream_chunk)
            log.info('{0.transient} - {0.pending} - {0.persistent} - {0.detached}'.format(x))
            x = inspect(highlight)
            log.info('{0.transient} - {0.pending} - {0.persistent} - {0.detached}'.format(x))
            x = inspect(self.current_stream)
            log.info('{0.transient} - {0.pending} - {0.persistent} - {0.detached}'.format(x))

            log.info(self.current_stream.id)
            log.info(highlight.id)
            log.info(self.current_stream_chunk.id)
        except:
            log.exception('uncaught exception in create_highlight')
            return 'Unknown reason, ask pajlada'

        return True
开发者ID:savageboy74,项目名称:tyggbot,代码行数:36,代码来源:stream.py

示例4: get_user

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def get_user(username):
    session = DBManager.create_session()
    user = session.query(User).filter_by(username=username).one_or_none()
    if user is None:
        return make_response(jsonify({'error': 'Not found'}), 404)

    rank = session.query(func.Count(User.id)).filter(User.points > user.points).one()
    rank = rank[0] + 1
    session.close()
    if user:
        accessible_data = {
                'id': user.id,
                'username': user.username,
                'username_raw': user.username_raw,
                'points': user.points,
                'rank': rank,
                'level': user.level,
                'last_seen': user.last_seen,
                'last_active': user.last_active,
                'subscriber': user.subscriber,
                'num_lines': user.num_lines,
                'minutes_in_chat_online': user.minutes_in_chat_online,
                'minutes_in_chat_offline': user.minutes_in_chat_offline,
                'banned': user.banned,
                'ignored': user.ignored,
                }
        return jsonify(accessible_data)

    return make_response(jsonify({'error': 'Not found'}), 404)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:31,代码来源:api.py

示例5: __init__

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def __init__(self, bot):
        self.bot = bot

        self.current_stream_chunk = None  # should this even exist?

        self.num_offlines = 0
        self.first_offline = None

        self.bot.execute_every(self.STATUS_CHECK_INTERVAL, self.refresh_stream_status)
        self.bot.execute_every(self.VIDEO_URL_CHECK_INTERVAL, self.refresh_video_url)

        """
        This will load the latest stream so we can post an accurate
        "time since last online" figure.
        """
        session = DBManager.create_session(expire_on_commit=False)
        self.current_stream = session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start.desc()).first()
        self.last_stream = session.query(Stream).filter_by(ended=True).order_by(Stream.stream_end.desc()).first()
        # if self.current_stream and len(self.current_stream.stream_chunks) > 0:
        if self.current_stream:
            # sorted_chunks = sorted(self.current_stream.stream_chunks, key=lambda x: x.chunk_start, reverse=True)
            # self.current_stream_chunk = sorted_chunks[0]
            self.current_stream_chunk = session.query(StreamChunk).filter_by(stream_id=self.current_stream.id).order_by(StreamChunk.chunk_start.desc()).first()
            log.info('Set current stream chunk here to {0}'.format(self.current_stream_chunk))
        session.expunge_all()
        session.close()
开发者ID:savageboy74,项目名称:tyggbot,代码行数:28,代码来源:stream.py

示例6: __init__

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def __init__(self, bot):
        self.db_session = DBManager.create_session()
        self.messages = []
        self.bot = bot
        self.minute = 0
        self.iterator = 0

        self.bot.execute_every(60, self.tick)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:10,代码来源:motd.py

示例7: points

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def points():
    session = DBManager.create_session()
    top_30_users = []
    for user in session.query(User).order_by(User.points.desc())[:30]:
        top_30_users.append(user)
    session.close()
    return render_template('points.html',
            top_30_users=top_30_users)
开发者ID:Phaqui,项目名称:tyggbot,代码行数:10,代码来源:app.py

示例8: decks

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def decks():
    session = DBManager.create_session()
    top_decks = []
    for deck in session.query(Deck).order_by(Deck.last_used.desc(), Deck.first_used.desc())[:25]:
        top_decks.append(deck)
    session.close()
    return render_template('decks/all.html',
            top_decks=top_decks,
            deck_class=None)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:11,代码来源:app.py

示例9: __init__

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def __init__(self, bot):
        UserDict.__init__(self)
        self.bot = bot
        self.streamer = bot.streamer
        self.db_session = DBManager.create_session()
        self.custom_data = []
        self.bttv_emote_manager = BTTVEmoteManager(self)

        self.bot.execute_every(60 * 60 * 2, self.bot.action_queue.add, (self.bttv_emote_manager.update_emotes, ))
开发者ID:ChunHungLiu,项目名称:tyggbot,代码行数:11,代码来源:emote.py

示例10: highlights

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def highlights():
    session = DBManager.create_session()
    streams = session.query(Stream).order_by(Stream.stream_start.desc()).all()
    for stream in streams:
        stream.stream_chunks = sorted(stream.stream_chunks, key=lambda x: x.chunk_start, reverse=True)
        for stream_chunk in stream.stream_chunks:
            stream_chunk.highlights = sorted(stream_chunk.highlights, key=lambda x: x.created_at, reverse=True)
    session.close()
    return render_template('highlights.html',
            streams=streams)
开发者ID:Phaqui,项目名称:tyggbot,代码行数:12,代码来源:app.py

示例11: remove_highlight

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def remove_highlight(self, id):
        """
        Returns True if a highlight was removed, otherwise return False
        """

        session = DBManager.create_session()
        num_rows = session.query(StreamChunkHighlight).filter(StreamChunkHighlight.id == id).delete()
        session.commit()
        session.close()

        return (num_rows == 1)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:13,代码来源:stream.py

示例12: __init__

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def __init__(self, reactor, bot, target, message_limit, time_interval, num_of_conns=30):
        self.db_session = DBManager.create_session()
        self.reactor = reactor
        self.bot = bot
        self.message_limit = message_limit
        self.time_interval = time_interval
        self.num_of_conns = num_of_conns
        self.whisper_thread = None

        self.connlist = []
        self.whispers = Queue()

        self.maintenance_lock = False
开发者ID:savageboy74,项目名称:tyggbot,代码行数:15,代码来源:whisperconnection.py

示例13: stats

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def stats():
    top_5_commands = sorted(bot_commands_list, key=lambda c: c.num_uses, reverse=True)[:5]

    if 'linefarming' in modules:
        session = DBManager.create_session()
        top_5_line_farmers = session.query(User).order_by(User.num_lines.desc())[:5]
        session.close()
    else:
        top_5_line_farmers = []

    return render_template('stats.html',
            top_5_commands=top_5_commands,
            top_5_line_farmers=top_5_line_farmers)
开发者ID:Phaqui,项目名称:tyggbot,代码行数:15,代码来源:app.py

示例14: highlight_id

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
def highlight_id(date, highlight_id, highlight_title=None):
    session = DBManager.create_session()
    highlight = session.query(StreamChunkHighlight).filter_by(id=highlight_id).first()
    if highlight is None:
        session.close()
        return render_template('highlight_404.html'), 404
    else:
        stream_chunk = highlight.stream_chunk
        stream = stream_chunk.stream
        session.close()
    return render_template('highlight.html',
            highlight=highlight,
            stream_chunk=stream_chunk,
            stream=stream)
开发者ID:Phaqui,项目名称:tyggbot,代码行数:16,代码来源:app.py

示例15: update_highlight

# 需要导入模块: from tyggbot.models.db import DBManager [as 别名]
# 或者: from tyggbot.models.db.DBManager import create_session [as 别名]
    def update_highlight(self, id, **options):
        """
        Returns True if a highlight was modified, otherwise return False
        """

        if 'offset' in options:
            options['highlight_offset'] = options.pop('offset')

        session = DBManager.create_session()
        num_rows = session.query(StreamChunkHighlight).filter(StreamChunkHighlight.id == id).update(options)
        session.commit()
        session.close()

        return (num_rows == 1)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:16,代码来源:stream.py


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