示例#1
0
  def get(self):
    screenname = self.request.get('screenname')
    print(screenname)
    profile = Profile.get_by_key_name(screenname, parent = None)
    tc = tlib.TwitterCrawler() 
    tc.re_init(profile.access_token, profile.access_token_secret, profile.twitter_user_name)
    tu = tc.get_twitter_user_with_friends()
    user_tweets = []
    # NB
    target_docs = [tweet['text'].encode('utf-8') for tweet in tu.mytweets]
    result = algorithm.get_probability(target_docs)
    # NB finished

    profile.user_average = result[1]
    for tweet in result[0]:
      # d = json.loads(tweet)
      user_tweets.append([tweet[1], tweet[2]])

    userinfo = tu.userinfo
    profile.full_name = userinfo['name']
    image_url = userinfo['profile_image_url_https']
    profile.image_url_normal = image_url
    profile.user_tweet_count = len(user_tweets)
    profile.save()
    image_url = image_url.replace("normal", "bigger")
    template_values = {"user_name": profile.full_name, "user_sn": profile.twitter_user_name, "tweets": user_tweets,
     "href": '\"/friendpage?screenname='+screenname+'"', "image_url": image_url, 'user_avg': result[1], 'user_tweet_count': len(user_tweets), 
     'friend_count': len(tu.friends)}
    template = jinja_environment.get_template("profile.html")
    self.response.out.write(template.render(template_values))
示例#2
0
  def get(self):
    info = self.request.get('screenname').split(',')
    screenname = info[0]
    friendname = info[1]

    profile = Profile.get_by_key_name(screenname, parent = None)

    user_name = profile.full_name
    user_sn = profile.twitter_user_name
    user_avg = profile.user_average
    user_img_url = profile.image_url_normal

    tc = tlib.TwitterCrawler()
    tc.re_init(profile.access_token, profile.access_token_secret, friendname)
    user = tc.get_twitter_user_with_friends()
    target_docs = [tweet['text'].encode('utf-8') for tweet in user.mytweets]
    result = algorithm.get_probability(target_docs)
    user_tweets = []
    for tweet in result[0]:
      user_tweets.append([tweet[1].decode('utf-8'), tweet[2]])

    userinfo = user.userinfo

    friend_img_url = userinfo['profile_image_url_https'].replace('normal','bigger')
    friend_name = userinfo['name']
    friend_sn = friendname
    friend_avg = result[1]
    difference = math.fabs(profile.user_average - result[1])
    template_values = {'user_tweet_count': profile.user_tweet_count, "user_avg": profile.user_average, "user_name": user_name,
    "user_sn": user_sn, "user_url": user_img_url , "difference" : difference, "friend_avg": friend_avg, "friend_name": friend_name, "friend_url": friend_img_url, "friend_sn": friend_sn,
    "friend_tweets": user_tweets, 'friend_tweet_count': len(user_tweets), "href": '\"/friendpage?screenname='+screenname+'\"'}
    template = jinja_environment.get_template("friendprofile.html")
    self.response.out.write(template.render(template_values))