from prettytable import PrettyTable
import get_tweets_by_search
import get_most_retweeted

def make_table(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key, val in tweets:
        table.add_row([key, val])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table



def make_table_from_dictionary(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key in tweets:
        table.add_row([key, tweets[key]])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table


tweets = get_tweets_by_search.search('Trump', 100)
popular = get_most_retweeted.most_retweeted(tweets, 10)
print make_table(popular)
from prettytable import PrettyTable
import get_tweets_by_search
import get_most_retweeted


def make_table(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key, val in tweets:
        table.add_row([key, val])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table


def make_table_from_dictionary(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key in tweets:
        table.add_row([key, tweets[key]])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table


tweets = get_tweets_by_search.search('Trump', 100)
popular = get_most_retweeted.most_retweeted(tweets, 10)
print make_table(popular)
from prettytable import PrettyTable
import get_tweets_by_search
import get_most_retweeted

def make_table(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key, val in tweets:
        table.add_row([key, val])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table



tweets = get_tweets_by_search.search('Euro', 10)
popular = get_most_retweeted.most_retweeted(tweets, 1000)
print make_table(popular)
        counter = Counter(data)

        [table.add_row(entry) for entry in counter.most_common()[:10]]
        table.align[label], table.align['Count'] = 'l', 'r'

        print table


def get_lexical_diversity(items):
    return 1.0 * len(set(items)) / len(items)


def get_average_words(tweets):
    total_words = sum([len(tweet.split()) for tweet in tweets])
    return 1.0 * total_words / len(tweets)


tweets = search('Dublin', 100)
texts = get_tweet_texts(tweets)
words = get_words(texts)
screen_names = get_screen_names(tweets)
hashtags = get_hashtags(tweets)

# print "Averate words: %s" % get_average_words(texts)
# print "Word Diversity: %s" % get_lexical_diversity(words)
# print "Screen Name Diversity: %s" % get_lexical_diversity(screen_names)
# print "HashTag Diversity: %s" % get_lexical_diversity(hashtags)

table_stuff(texts, screen_names, hashtags)

from operator import itemgetter
from get_tweets_by_search import search
from get_in_table import make_table


def most_retweeted(tweets, min_retweets):
    pop_tweets = [
        status for status in tweets
        if status._json['retweet_count'] > min_retweets
    ]

    # pop_tweets_dict = { tweet._json['text'].encode('utf-8'): tweet._json['retweet_count'] for tweet in pop_tweets}
    #
    # return sorted(pop_tweets_dict, key=itemgetter(1), reverse=True)[:5]

    tweets_tup = tuple([(tweet._json['text'].encode('utf-8'),
                         tweet._json['retweet_count'])
                        for tweet in pop_tweets])

    pop_tweets_set = set(tweets_tup)

    return sorted(pop_tweets_set, key=itemgetter(1), reverse=True)[:5]


tweets = search('Dublin', 150)

pop = most_retweeted(tweets, 10)
print make_table(pop)
Beispiel #6
0
from prettytable import PrettyTable
import get_tweets_by_search
import get_most_retweeted


def make_table(tweets):
    table = PrettyTable(field_names=['Text', 'Retweet Count'])
    for key, val in tweets:
        table.add_row([key, val])
        table.max_width['Text'] = 50
        table.align['Text'], table.align['Retweet Count'] = 'l', 'r'
    return table


tweets = get_tweets_by_search.search('Euro', 10)
popular = get_most_retweeted.most_retweeted(tweets, 1000)
print make_table(popular)
from operator import itemgetter
from get_tweets_by_search import search
from get_in_table import make_table

def most_retweeted(tweets, min_retweets):
    pop_tweets = [status
                  for status in tweets
                  if status._json['retweet_count'] > min_retweets]

    # pop_tweets_dict = { tweet._json['text'].encode('utf-8'): tweet._json['retweet_count'] for tweet in pop_tweets}
    #
    # return sorted(pop_tweets_dict, key=itemgetter(1), reverse=True)[:5]



    tweets_tup = tuple([(tweet._json['text'].encode('utf-8'), tweet._json['retweet_count'])
                        for tweet in pop_tweets])

    pop_tweets_set = set(tweets_tup)

    return sorted(pop_tweets_set, key=itemgetter(1), reverse=True)[:5]

tweets = search('Dublin', 150)

pop = most_retweeted(tweets, 10)
print make_table(pop)