Sha256: 80b2716866c89ccee0420925fb07a58732077e1368029ca513141f0fc5ff4ab0
Contents?: true
Size: 1.94 KB
Versions: 33
Compression:
Stored size: 1.94 KB
Contents
module SportsDb class ExternalFeedBuilder def self.update_external_feeds Rails.logger.info('updating team external feeds') count = 0 open( SimpleConfig.for(:feeds).team_feeds_xml ) do |file| doc = Nokogiri::XML(file.read) doc.xpath('//team').each do |team_node| team_obj = Team.find_by_key(team_node.xpath("key").first.text) if !team_obj.blank? external_twitter_url = team_node.xpath("sn_twitter_feed").first.text woven_twitter_url = team_node.xpath("woven_twitter_feed").first.text store_feed(external_twitter_url, woven_twitter_url, "twitter", "Sporting News", team_obj.id) external_news_url = team_node.xpath("sn_news_feed").first.text woven_news_url = team_node.xpath("woven_news_feed").first.text store_feed(external_news_url, woven_news_url, "news", "Sporting News", team_obj.id) count += 1 end end p "Processed #{count} teams" end rescue Exception => e Zumobi::ExceptionHandler.error e end def self.store_feed(external_url, woven_url, content_type, source, team_id) if !external_url.blank? && !woven_url.blank? feed = ExternalFeed.find(:first, :conditions => ["team_id = ? and content_type = ? and provider = ?", team_id, content_type, source]) if feed.blank? ExternalFeed.create({ :team_id => team_id, :feed_source_url => external_url, :woven_feed_url => woven_url, :provider => source, :content_type => content_type }) else feed.update_attributes({ :team_id => team_id, :feed_source_url => external_url, :woven_feed_url => woven_url, :provider => source, :content_type => content_type }) end end end end end
Version data entries
33 entries across 33 versions & 1 rubygems