當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。