require 'hpricot' require 'rubygems' require 'facebook_web_session' require 'open-uri' TVA_URL = "http://www0.rdthdo.bbc.co.uk" TVA_API = "cgi-perl/api/query.pl?" SHOW_LIMIT = 2 RAILS_ENV = "production" def path_to_aod(network) "#{network}.shtml" end def profile_markup(networks_markup, user) <<-PROFILE View BBC Radio #{ %( Mine Mine | Friends | Everyone ) unless user.is_page }
    #{networks_markup}
PROFILE end def fetch_network_markup(networks, user) markup = [] fb_page_id = "u=#{user.fbid}&" if user.is_page networks.each do |n| markup << <<-NET
  • Bbc
  • NET end markup end namespace :admin do desc "Re-publish all profiles. WARNING! This will take a long time!" task :republish_profiles => :environment do puts "Starting..." if users = User.find(:all) fb = RFacebook::FacebookWebSession.new(FACEBOOK["key"], FACEBOOK["secret"]) fb.activate_with_previous_session(FB_SESSION_NON_EXIRES, FB_USER_ID) end users.each do |user| networks_markup = fetch_network_markup(user.networks, user) unless networks_markup.empty? markup = profile_markup(networks_markup, user) begin fb.profile_setFbml( :uid => [user.fbid], :markup => markup ) puts "success ... User #{user.first_name} #{user.last_name} (#{user.fbid})" rescue Exception => e puts "Error, couldn't send fbid:#{user.fbid}" end end end puts "Finished..." end desc "Re-publish the given profile/s (ex: FBUIDS=12345,67899)" task :rebuild_profile => :environment do # assume nothing fbids = [] # if ids parsed in create fb session and chop up fbids if ENV.include?("FBUIDS") fb = RFacebook::FacebookWebSession.new(FACEBOOK["key"], FACEBOOK["secret"]) fb.activate_with_previous_session(FB_SESSION_NON_EXIRES, FB_USER_ID) fbids = ENV['FBUIDS'].split(',') end # loop and re-send profiles fbids.each do |fbid| next unless user = User.find_by_fbid(fbid) networks_markup = fetch_network_markup(user.networks, user) unless networks_markup.empty? markup = profile_markup(networks_markup, user) fb.profile_setFbml( :uid => [user.fbid], :markup => markup ) puts "success ... User (#{user.fbid}) Updated" end end end end