Created
July 22, 2010 21:05
-
-
Save ashaw/486594 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
tpm_twitter_wire_* |
This file contains hidden or 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
<style> | |
.retweet{ | |
-moz-background-clip:border; | |
-moz-background-inline-policy:continuous; | |
-moz-background-origin:padding; | |
background-attachment:scroll; | |
background-color:#e7e7e7; | |
background-image:none; | |
background-position:0 0; | |
background-repeat:repeat; | |
font-size:11px; | |
line-height:13px; | |
padding-left:3px; | |
padding-right:3px; | |
padding-top:1px; | |
padding-bottom:1px; | |
text-decoration:none; | |
} | |
.retweet:hover{ | |
background-color:#cecece; | |
} | |
.retweet a{ | |
color:#990000; | |
font-family:Helvetica,arial,sans-serif; | |
} | |
.retweet a:hover{ | |
text-decoration:none; | |
} | |
</style> | |
<div class="storywrap"> | |
<h2 class="eyebrow"><span class="tpmred">TPM</span> Live Updates</h2> | |
<h2 class="twohed"><a href=""><%= @title %></a></h2> | |
<p> </p> | |
<ul class="widewire"> | |
<% @tweets[0..2].each do |tweet| %> | |
<li> | |
<span class="widewiredate"><strong><a href="http://twitter.com/<%= tweet[:user] %>"><%= tweet[:user] %></a></strong> <%= tweet[:created_at] %> — | |
</span> | |
<span class="widewireblurb"> | |
<%= tweet[:text] %> <%if tweet[:url] %><span class="retweet"><a href="<%= tweet[:url] %>">Read more »</a></span> <%end%> | |
<span class="retweet"><a href="http://twitter.com/?status=RT+@<%=USER%>+<%=CGI::escape(tweet[:original_text])%>">RT</a></span> | |
</span> | |
</li> | |
<% end %> | |
</ul> | |
<p style="text-align:right; margin-bottom:0px; margin-top:2px;"> | |
<a href="http://tpmlivewire.talkingpointsmemo.com/2010/07/live-tweets-from-netroots-nation-featuring-christina-bellantoni.php">See more Twitter updates »</a> | |
</p> |
This file contains hidden or 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
$KCODE = 'UTF8' | |
require 'uri' | |
require 'open-uri' | |
require 'erb' | |
require 'rubygems' | |
require 'curb' | |
require 'twitter' | |
require 'twitter-text' | |
#### RUNNER | |
if ARGV.empty? | |
raise "you must enter a user!" | |
end | |
#USER = 'cbellantoni' | |
USER = ARGV[0].to_s | |
LIST = ARGV[1].to_s | |
#### LIB | |
# Usage: ruby tpm_twitter_wire.rb tpmmedia staff "stafflist" | |
module TwitterWire | |
class Timeline | |
include Twitter::Extractor | |
include Twitter::Autolink | |
attr_reader :timeline | |
def initialize | |
@timeline = Twitter.list_timeline(USER,LIST) | |
end | |
def run | |
slim | |
linkify | |
de_short_link | |
end | |
def slim | |
@lean_timeline = [] | |
@timeline.each do |update| | |
if update['in_reply_to_user_id'] == nil | |
@lean_timeline << {:created_at => Time.parse(update['created_at']).strftime("%l:%M %p"), :text => update['text'], :id => update['id'], :user => update["user"]["screen_name"], :userpic => update["user"]["profile_image_url"], :user_bio => update["user"]["description"]} | |
end | |
end | |
end | |
def linkify | |
urls = [] | |
@lean_timeline.each do |update| | |
# preserve original tweet | |
update[:original_text] = update[:text].dup | |
# extract links into :url | |
update[:url] = extract_urls(update[:text])[0] | |
# remove link from tweet itself | |
update[:text].gsub!(Twitter::Regex[:valid_url],'') | |
# linkify @ and # | |
update[:text] = auto_link(update[:text]) | |
# get twitpix | |
update[:twitpic] = update[:original_text][/http:\/\/twitpic\.com\/([^\s|$]+?)(\s|$)/,1] | |
end | |
end | |
def de_short_link | |
@lean_timeline.each do |update| | |
url = update[:url] || nil | |
if not url.nil? | |
c = Curl::Easy.new(url) | |
c.follow_location = true | |
c.max_redirects = nil | |
c.perform | |
update[:url] = c.last_effective_url | |
end | |
end | |
@lean_timeline | |
end | |
end | |
class View | |
# v = TwitterWire::View.new(TwitterWire::Timeline.new.run, { | |
# :template => (File.dirname(__FILE__) + '/' + "twitter_wire_full.erb"), | |
# :outfile => (File.dirname(__FILE__) + '/' + "tpm_twitter_wire_#{USER}.php") | |
# }) | |
# | |
def initialize(timeline,opts = {}) | |
@tweets = timeline | |
@title = ARGV[2].to_s || "" | |
@outfile = opts[:outfile] | |
@template = opts[:template] | |
end | |
def to_html | |
t = File.open(@template) | |
template = t.read.to_s | |
@tweeters = @tweets.collect{|tweet| [tweet[:user],tweet[:userpic], tweet[:user_bio]]}.uniq | |
html = ERB.new(template).result(binding) | |
self.write(html) | |
t.close | |
end | |
def write(html) | |
f = File.new(@outfile,"w+") | |
f.write(html) | |
f.close | |
end | |
end | |
end | |
# to run everything | |
def generate_twitter_wire | |
t = TwitterWire::Timeline.new | |
t = t.run | |
TwitterWire::View.new(t, { | |
:template => (File.dirname(__FILE__) + '/' + "tpm_twitter_wire.erb"), | |
:outfile => (File.dirname(__FILE__) + '/' + "tpm_twitter_wire_#{USER}.php") | |
}).to_html | |
TwitterWire::View.new(t, { | |
:template => (File.dirname(__FILE__) + '/' + "tpm_twitter_wire_full.erb"), | |
:outfile => (File.dirname(__FILE__) + '/' + "tpm_twitter_wire_full_#{USER}.php") | |
}).to_html | |
end | |
generate_twitter_wire() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment