bot.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:heydjbot 作者: mongonauta 项目源码 文件源码
def train(bot, update):
    user = update.message.from_user
    logger.info('show_song_to_clasify %s' % user)

    resp = requests.get(
        url='{}/user_info/{}/'.format(API_SERVER, user.id)
    )

    if not resp.json():
        update.message.reply_text(
            'Sorry {}, but I can\'t do that. Please, use "connect" command'.format(user['first_name'])
        )

    else:
        resp = requests.get(
            url='{}/train/{}/'.format(API_SERVER, user.id)
        )

        song = resp.json()['song'] if 'song' in resp.json() else None
        if song:
            bot.song_cache = song
            update.message.reply_text(
                u"""
                    Choose one activity for this song:\n\n
                    Title: {}\n
                    Artist: {}\n
                    Album: {}\n
                """.format(song[1], song[4], song[2]),
                reply_markup=ReplyKeyboardMarkup(ACTIVITY_KEYBOARD, one_time_keyboard=True, resize_keyboard=True)
            )

        else:
            update.message.reply_text("Server error. %s" % resp.json())

    return SAVE_SONG
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号