Created
May 31, 2015 22:31
-
-
Save neudabei/d3f0125ab0b33c58b424 to your computer and use it in GitHub Desktop.
Include live Tweets an email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code is based on the explanations by Kevin Thompson (http://kevinthompson.info/) here https://gist.github.com/kevinthompson/c3023df8e2c904ad00d9 | |
# See the email here: http://www.mailerbob.com/live-tweets/email.html | |
require 'sinatra' | |
require 'twitter' | |
helpers do | |
def twitter | |
@twitter ||= Twitter::REST::Client.new do |config| | |
config.consumer_key = ENV.fetch("TWITTER_CONSUMER_KEY") | |
config.consumer_secret = ENV.fetch("TWITTER_CONSUMER_SECRET") | |
end | |
end | |
end | |
get "/tweets.css" do | |
content_type "text/css" | |
code = | |
"@media screen and (-webkit-min-device-pixel-ratio: 0) { | |
.tweet .copy:before { | |
white-space: pre-wrap; | |
} | |
<% tweets = twitter.search(ENV.fetch(\"TWITTER_SEARCH_STRING\")) %> | |
<% tweets.take(6).map.with_index do |tweet, i| %> | |
#<%= \"tweet\" %>-<%=i+1%> .copy::before { content: \"<%= tweet.text %>\" ; | |
} | |
#<%= \"tweet\" %>-<%=i+1%> .avatar { background: url(\"<%= tweet.user.profile_image_url %>\") ; | |
} | |
#<%= \"tweet\" %>-<%=i+1%> .name::before { content: \"<%= tweet.user.name %>\" ; | |
} | |
#<%= \"tweet\" %>-<%=i+1%> .handle::after { content: \"@<%= tweet.user.screen_name %>\" ; | |
} | |
#<%= \"tweet\" %>-<%=i+1%> .timestamp::after { content: \"<%= tweet.created_at %>\" ; | |
} | |
<% end %> | |
}" | |
erb code | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment