Class: SportsDb::ExternalFeedBuilder
- Inherits:
-
Object
- Object
- SportsDb::ExternalFeedBuilder
- Defined in:
- lib/sports_db/external_feed_builder.rb
Class Method Summary collapse
- .store_feed(external_url, woven_url, content_type, source, team_id) ⇒ Object
- .update_external_feeds ⇒ Object
Class Method Details
.store_feed(external_url, woven_url, content_type, source, team_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/sports_db/external_feed_builder.rb', line 34 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 |
.update_external_feeds ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sports_db/external_feed_builder.rb', line 4 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 |