# 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 # Now add the d_str and r_str strings, which contain a bunch of HTML, to the main # body template
{{ 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'], "tweets_count": profile['statuses_count'], "days_ago": days_ago,
{{ 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'], "tweets_count": profile['statuses_count'], "days_ago": days_ago,
""") 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()