def wish_read(message, session): token = get_token(message, session) if (None == token): return "输入'豆瓣'完成授权后回到微信" client_wechat.auth_with_token(token) if get_state(session) == 'booklist' or get_state(session) == 'wishread': bookid = session.get(message.content, 0) if 0 == bookid: return "输入有误,请重新输入" else: try: client_wechat.book.collection(bookid) except: return "你收藏过这本书啦!" else: return "设置想读成功!" set_state(session, 'wishread') elif get_state(session) == 'dnlist': dnstr = message.content tedstr = ted_kv.get(to_binary(TED_POPULAR)) retstr = '' if None != tedstr: speaker_list = json.loads(tedstr) dnid = int(dnstr) if dnid >= len(speaker_list): return '输入有误,请重新输入' # change id to keyward message.content = speaker_list[dnid]
def speaker(message, session): tedstr = ted_kv.get(to_binary(TED_POPULAR)) retstr = '' if None != tedstr: speaker_list = json.loads(tedstr) if 0 == len(speaker_list): return '大牛列表暂时为空' for index in range(len(speaker_list)): retstr += '[' + str(index) + ']. ' + speaker_list[index] + '\n' retstr += u'\n输入序号可以查询大牛著作' set_state(session, 'dnlist') return retstr return "大牛列表暂时还拉不到哦"