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


Python db.DBManager类代码示例

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


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

示例1: create_stream_chunk

    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,代码行数:26,代码来源:stream.py

示例2: __init__

    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,代码行数:26,代码来源:stream.py

示例3: decks_warrior

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,代码行数:7,代码来源:app.py

示例4: create_highlight

    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,代码行数:34,代码来源:stream.py

示例5: pleblist_next

def pleblist_next():
    if not request.method == 'POST':
        return make_response(jsonify({'error': 'Invalid request method'}), 405)
    if 'song_id' not in request.form:
        return make_response(jsonify({'error': 'Missing data song_id'}), 400)
    if 'password' not in request.form:
        return make_response(jsonify({'error': 'Missing data password'}), 400)
    salted_password = generate_password_hash(config['web']['pleblist_password'], config['web']['pleblist_password_salt'])
    try:
        user_password = base64.b64decode(request.form['password'])
    except binascii.Error:
        return make_response(jsonify({'error': 'Invalid data password'}), 400)
    if not user_password == salted_password:
        return make_response(jsonify({'error': 'Invalid password'}), 401)

    with DBManager.create_session_scope() as session:
        try:
            current_song = session.query(PleblistSong).filter(PleblistSong.id == int(request.form['song_id'])).order_by(PleblistSong.date_added.asc()).first()
        except ValueError:
            return make_response(jsonify({'error': 'Invalid data song_id'}), 400)

        if current_song is None:
            return make_response(jsonify({'error': 'No song active in the pleblist'}), 404)

        current_song.date_played = datetime.datetime.now()
        session.commit()

        # TODO: Add more data.
        # Was this song forcefully skipped? Or did it end naturally.

        return jsonify({'message': 'Success!'})
开发者ID:savageboy74,项目名称:tyggbot,代码行数:31,代码来源:api.py

示例6: get_user

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,代码行数:29,代码来源:api.py

示例7: pleblist_add

def pleblist_add():
    if not request.method == 'POST':
        return make_response(jsonify({'error': 'Invalid request method'}), 405)
    if 'youtube_id' not in request.form:
        return make_response(jsonify({'error': 'Missing data youtube_id'}), 400)
    if 'password' not in request.form:
        return make_response(jsonify({'error': 'Missing data password'}), 400)
    salted_password = generate_password_hash(config['web']['pleblist_password'], config['web']['pleblist_password_salt'])
    try:
        user_password = base64.b64decode(request.form['password'])
    except binascii.Error:
        return make_response(jsonify({'error': 'Invalid data password'}), 400)
    if not user_password == salted_password:
        return make_response(jsonify({'error': 'Invalid password'}), 401)

    with DBManager.create_session_scope() as session:
        youtube_id = request.form['youtube_id']
        current_stream = session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start).first()
        if current_stream is None:
            return make_response(jsonify({'error': 'Stream offline'}), 400)

        song_requested = PleblistSong(current_stream.id, youtube_id)
        session.add(song_requested)
        song_info = session.query(PleblistSongInfo).filter_by(pleblist_song_youtube_id=youtube_id).first()
        if song_info is None and song_requested.song_info is None:
            PleblistManager.init(config['youtube']['developer_key'])
            song_info = PleblistManager.create_pleblist_song_info(song_requested.youtube_id)
            if song_info is not False:
                session.add(song_info)
                session.commit()

        return jsonify({'success': True})
开发者ID:savageboy74,项目名称:tyggbot,代码行数:32,代码来源:api.py

示例8: __init__

    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,代码行数:8,代码来源:motd.py

示例9: points

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,代码行数:8,代码来源:app.py

示例10: decks

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,代码行数:9,代码来源:app.py

示例11: pleblist_blacklist

def pleblist_blacklist():
    with DBManager.create_session_scope() as session:
        current_stream = session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start).first()
        if current_stream is None:
            return make_response(jsonify({'error': 'Stream offline'}), 400)

        # TODO: implement this

        return make_response(jsonify({'error': 'NOT IMPLEMENTED'}), 400)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:9,代码来源:api.py

示例12: __init__

    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,代码行数:9,代码来源:emote.py

示例13: pleblist_list_by_stream

def pleblist_list_by_stream(stream_id):
    with DBManager.create_session_scope() as session:
        songs = session.query(PleblistSong).filter_by(stream_id=stream_id).all()

        payload = {
                '_total': len(songs),
                'songs': [song.jsonify() for song in songs],
                }

        return jsonify(payload)
开发者ID:savageboy74,项目名称:tyggbot,代码行数:10,代码来源:api.py

示例14: highlights

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,代码行数:10,代码来源:app.py

示例15: pleblist_history_redirect

def pleblist_history_redirect():
    with DBManager.create_session_scope() as session:
        current_stream = session.query(Stream).filter_by(ended=False).order_by(Stream.stream_start.desc()).first()
        if current_stream is not None:
            return redirect('/pleblist/history/{}/'.format(current_stream.id), 303)

        last_stream = session.query(Stream).filter_by(ended=True).order_by(Stream.stream_start.desc()).first()
        if last_stream is not None:
            return redirect('/pleblist/history/{}/'.format(last_stream.id), 303)

        return render_template('pleblist_history_no_stream.html'), 404
开发者ID:savageboy74,项目名称:tyggbot,代码行数:11,代码来源:app.py


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