Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Include live Tweets an email
# 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