Skip to content

Instantly share code, notes, and snippets.

@etdebruin
Created August 25, 2011 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save etdebruin/1169941 to your computer and use it in GitHub Desktop.
Save etdebruin/1169941 to your computer and use it in GitHub Desktop.
For Matt
require 'pp'
puts "Starting Twitter Stream Client for Campaign ID #{MyGivingTweetConf::HASHTAG}"
TweetStream::Client.new('stevenbono','rom121').track(MyGivingTweetConf::HASHTAG) do |status|
begin
puts "[#{status.user.screen_name}] #{status.text} #{status.id}"
if retweet?(status)
status_id = status.retweeted_status.id
campaign = StreamCampaign.find(status_id) #based on status.id of original tweet
if campaign
campaign.update(status) #update with status id and retweet count
else
# this is orphan campaign retweet
# update_orphan_campaign(status)
end
else
# start_orphan_campaign(status)
end
# retweeted => false
# retweet_count => 0
pp status.inspect
# Find the @charity twitter handle in status.text
# Find the orginator twitter user id
#
# How do we identify which campaign this is?
# - extract twitter name, i.e. @habitat
# We no longer us the bit.ly link because we have no guarantee that a twitter client
# won't override the bit.ly link with something else
#
# extract_urls = URI.extract(status.text)
# campaign_url = ''
# extract_urls.each do |u|
# if u.match('bit.ly')
# campaign_url = u
# end
# end
#
# puts "Campaign URL = (#{campaign_url})"
#
# unless campaign_url == ''
# c = Campaign.find_by_campaign_url(campaign_url)
#
# while c.nil? do
# c = Campaign.find_by_campaign_url(campaign_url)
# end
# else
# puts "There is no bit.ly link?"
# end
# unless c.nil?
# puts "Campaign ID #{c.id}"
# puts "Charity URL #{c.url}"
# c.add_tweet(status)
# else
# puts "ERROR: Couldn't figure out which Campaign this was?"
# end
rescue Exception => e
p e.inspect
end
end
def retweet?(status)
status.retweeted
end
class StreamCampaign
attr_accessor :status_id, :retweet_count, :retweet_status_ids
@cached_campaigns = {}
def self.find(status_id)
# do lookup in redis on status.id
@cached_campaigns[status_id] ||= $redis.get("campaign:#{status_id}") # make sure nil is returned if key is empty
end
end
# def start_campaign(status)
# create_originator(status)
# end
# def create_originator(status)
# save
# fetch_followers(user_id)
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment