Esempio n. 1
0
def guess():
        guessed_name = request.args.get('guessed_name').strip()
        if guessed_name:
                guessed_user, fans = None, False
                try:
                  guessed_user = g.api.get_user(id = guessed_name)
                except:
                    return render_template('guess.html', error=u"纳尼!查无此人)^O^( 你们真的认识吗")
                try:
                    fans = g.api.exists_friendship(user_a = guessed_user.id, user_b = g.weibo.id).friends
                except:
                    return render_template('guess.html', error=u"获取好友关系失败,请稍候再试")
        else:
            return render_template('guess.html', error=u"微博昵称不能为空")

        if guessed_user:
            constellation_id, rate, error = worker.guess(id=guessed_user.id)
            if rate <= 30:
                constellation_id, rate, error = worker.guess(id=guessed_user.id)            
            constellation = constellations[constellation_id][1]

            if error:
                return render_template('guess.html', error=error)

            Guess.set(guesser_id=g.user.id, guessed_id=guessed_user.id, constellation_id=constellation_id, rate=rate)
            Weibo.set(weibo=guessed_user)
            guessed_weibo = Weibo.get(id=guessed_user.id)[0]
            message = weibo_txt(fans=fans, screen_name=guessed_weibo.screen_name, constellation=constellation, rate=rate)
            rate = str(rate) + "%"
            return render_template('guess.html',constellation=constellation, rate=rate, message=message, error=None, guessed_weibo=guessed_weibo)
        else:
            return render_template('guess.html', error=u'无法获取该用户的微博信息')
Esempio n. 2
0
    def before_request():
        db_check(db)
        if 'id' in session:
            g.user = User.get(id=session['id'])[0]
            g.weibo = Weibo.get(id=session['id'])[0]
        else:
            g.user = None
            g.weibo = None

        g.api = None
Esempio n. 3
0
    def before_request():
        db_check(db) 
        if 'id' in session:
            g.user = User.get(id=session['id'])[0]
            g.weibo = Weibo.get(id=session['id'])[0]
        else:
            g.user = None
            g.weibo = None 

        g.api = None
Esempio n. 4
0
def guess():
    guessed_name = request.args.get('guessed_name').strip()
    if guessed_name:
        guessed_user, fans = None, False
        try:
            guessed_user = g.api.get_user(id=guessed_name)
        except:
            return render_template('guess.html', error=u"纳尼!查无此人)^O^( 你们真的认识吗")
        try:
            fans = g.api.exists_friendship(user_a=guessed_user.id,
                                           user_b=g.weibo.id).friends
        except:
            return render_template('guess.html', error=u"获取好友关系失败,请稍候再试")
    else:
        return render_template('guess.html', error=u"微博昵称不能为空")

    if guessed_user:
        constellation_id, rate, error = worker.guess(id=guessed_user.id)
        if rate <= 30:
            constellation_id, rate, error = worker.guess(id=guessed_user.id)
        constellation = constellations[constellation_id][1]

        if error:
            return render_template('guess.html', error=error)

        Guess.set(guesser_id=g.user.id,
                  guessed_id=guessed_user.id,
                  constellation_id=constellation_id,
                  rate=rate)
        Weibo.set(weibo=guessed_user)
        guessed_weibo = Weibo.get(id=guessed_user.id)[0]
        message = weibo_txt(fans=fans,
                            screen_name=guessed_weibo.screen_name,
                            constellation=constellation,
                            rate=rate)
        rate = str(rate) + "%"
        return render_template('guess.html',
                               constellation=constellation,
                               rate=rate,
                               message=message,
                               error=None,
                               guessed_weibo=guessed_weibo)
    else:
        return render_template('guess.html', error=u'无法获取该用户的微博信息')