# https://dev.twitter.com/web/embedded-tweets
embed_tweet = Template("""
<blockquote class="twitter-tweet" lang="en"><p>
<a href="https://twitter.com/{{screen_name}}/status/{{tweet_id}}">X</a>
</p></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
""")


d_str = ""
r_str = ""

for member in get_ca_tweeters():
    screen_name = member['twitter_id'].lower()
    profile = get_profile(screen_name)
    word_tweets = get_tweets_with_word(screen_name, the_word)
    # if there is at least one tweet with the word
    if len(word_tweets) > 0:
        tweet = word_tweets[0]

        t = embed_tweet.render(screen_name = screen_name, tweet_id = tweet['id'])
        if member['party'] == 'D':
            d_str += t
        else:
            r_str += t



# Now add the d_str and r_str strings, which contain a bunch of HTML, to the main
# body template
html_file.write(body_template.render(word = the_word, d_tweets = d_str, r_tweets = r_str))
Example #2
0
from twitter_foo import get_ca_tweeters, get_profile, get_tweets, get_original_tweets
from twitter_foo import convert_twitter_timestamp, get_tweets_with_word
from datetime import datetime

ca_tweeters = get_ca_tweeters()
print("There are {} CA tweeters".format(len(ca_tweeters)))

for member in ca_tweeters:
    tid = member['twitter_id'].lower()
    profile = get_profile(tid)
    tweets = get_tweets(tid)

    days_ago = (datetime.today() -
                convert_twitter_timestamp(profile['created_at'])).days
    tweet_rate = round(profile['statuses_count'] / days_ago, 2)

    print("----------")
    istr = "{} has {} followers and tweets {} times per day since joining Twitter {} days ago"
    print(istr.format(tid, profile['followers_count'], tweet_rate, days_ago))
    wrd = 'obama'
    wrd_tweets = get_tweets_with_word(tid, wrd)
    print("Number of original tweets with '{}' in last 200 tweets: {}".format(
        wrd, len(wrd_tweets)))
Example #3
0
from twitter_foo import get_ca_tweeters, get_profile, get_tweets, get_original_tweets
from twitter_foo import convert_twitter_timestamp, get_tweets_with_word
from datetime import datetime

SEARCH_WORD = 'obama'
# get tweets from current congress members in CA
ca_tweeters = get_ca_tweeters()
print("There are {} CA tweeters".format(len(ca_tweeters)))

for member in ca_tweeters:

    # get tweets and profile
    tid = member['twitter_id'].lower()
    profile = get_profile(tid)
    tweets = get_tweets(tid)

    # calc how long in days ago account created and tweet rate
    days_ago = (datetime.today() -
                convert_twitter_timestamp(profile['created_at'])).days
    tweet_rate = round(profile['statuses_count'] / days_ago, 2)

    print("----------------")
    istr = "{} has {} followers and tweets {} times per day since joining Twitter {} days ago"
    print(istr.format(tid, profile['followers_count'], tweet_rate, days_ago))

    wrd_tweets = get_tweets_with_word(tid, SEARCH_WORD)
    print("Number of original tweets with '{}' in last 200 tweets: {}".format(
        SEARCH_WORD, len(wrd_tweets)))
""")

embed_tweet = Template("""
<blockquote class="twitter-tweet" lang="en"><p>
<a href="https://twitter.com/{{screen_name}}/status/{{tweet_id}}">X</a>
</p></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
""")


d_str = ""
r_str = ""

for member in get_ca_tweeters():
    screen_name = member['twitter_id'].lower()
    profile = get_profile(screen_name)
    word_tweets = get_tweets_with_word(screen_name, the_word)
   
    if len(word_tweets) > 0:
        tweet = word_tweets[0]

        t = embed_tweet.render(screen_name = screen_name, tweet_id = tweet['id'])
        if member['party'] == 'D':
            d_str += t
        else:
            r_str += t



html_file.write(body_template.render(word = the_word, d_tweets = d_str, r_tweets = r_str))
html_file.close()
Example #5
0
from twitter_foo import get_ca_tweeters, get_profile, get_tweets, get_original_tweets
from twitter_foo import convert_twitter_timestamp, get_tweets_with_word
from datetime import datetime

ca_tweeters = get_ca_tweeters()
print("There are {} CA tweeters".format(len(ca_tweeters)))

for member in ca_tweeters:
    tid = member['twitter_id'].lower()
    profile = get_profile(tid)
    tweets = get_tweets(tid)

    days_ago = (datetime.today() - convert_twitter_timestamp(profile['created_at'])).days
    tweet_rate = round(profile['statuses_count'] / days_ago, 2)

    print("----------------")
    istr = "{} has {} followers and tweets {} times per day since joining Twitter {} days ago"
    print(istr.format(tid, profile['followers_count'], tweet_rate, days_ago))
    wrd = 'obama'
    wrd_tweets = get_tweets_with_word(tid, wrd)
    print("Number of original tweets with '{}' in last 200 tweets: {}".format(
                                            wrd, len(wrd_tweets)))