コード例 #1
0
""")

# Documentation on Twitter's embed tweet code:
# 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


コード例 #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)))
コード例 #3
0
  </td>
  <td>
    {{ tweets_count }}
  </td>
  <td>
    {{ days_ago }}
  </td>
  <td>
    {{ daily_tweet_rate }}
  </td>
</tr>
"""

row_template = Template(row_str)

for member in get_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)

    data = {
        "profile_pic_url": profile['profile_image_url'],
        "title": member['title'],
        "party": member['party'],
        "full_name": " ".join([member['firstname'], member['lastname']]),
        "twitter_id": tid,
        "followers_count": profile['followers_count'],
コード例 #4
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)))