示例#1
0
def link(request, link):
    users = UserTweet.toCrawl()
    tweets = [Tweet.objects.filter(retweets__gt=0, links__long_link__in=[link], username=user, created_at__gte=user.last_date_to_crawl) for user in users]
    tweets = reduce(lambda x, y: x | y, tweets)
    tweets = list(set(tweets))
    tweets = sorted(tweets, key=lambda tweet: (tweet.retweets, tweet.created_at), reverse=True)
    response = {'response': zip([link] * len(tweets), tweets)}
    return render_to_response('link.html', response)
示例#2
0
def user_mentions(request, username=None):
    username = UserTweet(pk=username)
    users = UserTweet.toCrawl()
        
    tweets = [Tweet.objects.filter(retweets__gt=0, user_mentions__in=[username], username=user, created_at__gt=user.last_date_to_crawl) for user in users]
    tweets = reduce(lambda x, y: x | y, tweets)
    tweets = list(set(tweets))
    tweets = sorted(tweets, key=lambda tweet: (tweet.retweets, tweet.created_at), reverse=True) 
    response = {'response': zip([username] * len(tweets), tweets)}
    return render_to_response('user_mentions.html', response)
示例#3
0
def hashtags(request):
    users = UserTweet.toCrawl()
    tweets = [Tweet.objects.filter(retweets__gt=0, hashtags__isnull=False, username=user, created_at__gte=user.last_date_to_crawl) for user in users]
    tweets = reduce(lambda x, y: x | y, tweets)
    tweets = list(set(tweets))
    
    d = {}
    for tweet in tweets:
        hashtags = tweet.all_hashtags()
        for hashtag in hashtags:
            if hashtag in d:
                d[hashtag].append(tweet)
            else:
                d[hashtag] = [tweet]
    
    for hashtag, tweets in d.iteritems():
        retweets = sum(tweet.retweets for tweet in tweets)
        tweet = min(tweets, key=lambda tweet: tweet.created_at)
        d[hashtag] = {'tweet': tweet, 'retweets': retweets} 
    
    response = {'response': sorted(d.items(), key=lambda tweet: (tweet[1]['retweets'], tweet[1]['tweet'].created_at), reverse=True)}
    return render_to_response('hashtags.html', response)
示例#4
0
def home(request):
    """Show all the tweets that have at least one link in the tweet"""
    users = UserTweet.toCrawl()
    tweets = [Tweet.objects.filter(retweets__gt=0, links__isnull=False, username=user, created_at__gte=user.last_date_to_crawl) for user in users]
    tweets = reduce(lambda x, y: x | y, tweets)
    tweets = list(set(tweets))
    
    d = {}
    for tweet in tweets:
        links = tweet.all_long_links()
        for link in links:
            if link in d:
                d[link].append(tweet)
            else:
                d[link] = [tweet]
    
    for link, tweets in d.iteritems():
        retweets = sum(tweet.retweets for tweet in tweets)
        tweet = min(tweets, key=lambda tweet: tweet.created_at)
        d[link] = {'tweet': tweet, 'retweets': retweets}
    response = {'response': sorted(d.items(), key=lambda x: (x[1]['retweets'], x[1]['tweet'].created_at), reverse=True)}
    return render_to_response('home.html', response)