def hero_grade_sendTweet(): tweet = session.get('grade_tweet') api = sinaAPI(session['token'].key, session['token'].secret) if tweet != None: f = current_app.config['LOCAL_PATH']+'static/pic1/%s.jpg' % random.randint(1,200) api.sendTweetImage(tweet,f) #api.sendTweet(tweet) session.pop('grade_tweet',None) return ''
def hero_msg(hid): user = session['user'] if request.method=='POST': content = request.form['content'] floor = Msg.query.filter(Msg.hid==hid).count()+1; db.session.add(Msg(user.uid, hid,floor, content)) db.session.commit() if(request.form['send_sina']=='true'): hero = Hero.query.filter(Hero.id == hid).first() tweet = "@"+user.screen.encode('utf8') tweet += " 对DOTA英雄 "+hero.namecn.encode('utf8')+" 评论:" tweet += content.encode('utf8') tweet += " http://dotabook.info" api = sinaAPI(session['token'].key, session['token'].secret) #api.sendTweet(tweet) f = current_app.config['LOCAL_PATH']+'static/pic1/%s.jpg' % random.randint(1,200) api.sendTweetImage(tweet,f) page = int(request.args.get('p','1')) count = 10 msgs_page = Msg.query.filter(Msg.hid==hid).order_by(Msg.id.desc()).paginate(page,count) objs = [] for msg in msgs_page.items: obj = {'hid':msg.hid,'mid':msg.id,'content':msg.content.encode('utf8'),'floor':msg.floor,'date':mydate.toString2(msg.create_date).encode('utf8')} obj['uid'] = msg.uid sina_user = Sina_User.query.filter(Sina_User.uid==msg.uid).first() obj['screen'] = sina_user.screen.encode('utf8') obj['profile_image'] = sina_user.profile_image_url ops = Msg_Operate.query.filter(Msg_Operate.mid==msg.id).all() ms_count = {'up':0,'down':0,'repost':0,'comment':0} for op in ops: if op.action=='up':ms_count['up']+=1 elif op.action=='down':ms_count['down']+=1 elif op.action=='repost':ms_count['repost']+=1 elif op.action=='comment':ms_count['comment']+=1 obj['count']=ms_count objs.append(obj) return jsonify(msgs=objs,count=count,total=msgs_page.total, page=page)
def hero_msg_repost(mid): if request.method == 'POST': user = session['user'] hid = request.form['hid'] content = request.form['content'] floor = Msg.query.filter(Msg.hid==hid).count()+1; msg = Msg(user.uid, hid, floor, request.form['content']) db.session.add(msg) db.session.commit() db.session.add(Msg_Operate(user.uid,mid,'repost',msg.id)) db.session.commit() hero = Hero.query.filter(Hero.id == hid).first() tweet = "@"+user.screen.encode('utf8') tweet += " 对DOTA英雄 "+hero.namecn.encode('utf8')+" 评论:" tweet += content.encode('utf8') tweet += " http://dotabook.info" api = sinaAPI(session['token'].key, session['token'].secret) api.sendTweet(tweet) size = Msg_Operate.query.filter(Msg_Operate.mid==mid).filter(Msg_Operate.action=='repost').count() return jsonify(mid=mid,size=size)
def user_id_json(uid): api = sinaAPI(session['token'].key, session['token'].secret) user = api.getUser_byId(uid) return jsonify(user=user.json())