def oauthreturn(): code = request.args.get('code', '') if code: client = Client(app.config['API_KEY'], app.config['API_SECRET'], app.config['REDIRECT_URI']) client.set_code(code) uid = client.token['uid'] profile = client.get('users/show', access_token=client.access_token, uid=uid) wuser = Wuser.query.filter_by(uid=uid).first() if wuser: login_user(wuser.user) else: user = User() wuser = Wuser(uid=uid) wuser.user = user db.session.add(user) login_user(user) wuser.update_access_token(client.token['access_token']) wuser.update_profile(profile) db.session.add(wuser) db.session.commit() return render_template("weibo/profile.html", wuser=wuser)
def read_comment_list(): weibo_user = Weibo.query.get(1) token = {'uid': weibo_user.uid, 'access_token': weibo_user.access_token} client = Client(app.config['API_KEY'], app.config['API_SECRET'], app.config['REDIRECT_URI'], token=token) comment_list = client.get('comments/mentions') for c in comment_list['comments']: comment = c.query.filter_by(cid=c['idstr']).first() if comment is None: comment = Comment(cid=c['idstr'], created_at=c['']) status = Status.query.filter_by(sid=c['status']['idstr']).first() if status is None: s = c['status'] status = Status(sid=s['distr'], created_at=s['created_at'], text=s['text'], thumbnail_pic=['thumbnail_pic'], ) return jsonify(comment_list)