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
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/sports_db/news_builder.rb', line 4
def self.update_player_news
p "Updating SN Player news ..."
config = SimpleConfig.for(:feeds)
require 'open-uri'
articles = []
unless !config.player_news_url.blank?
p "No sporting news player new URL given."
return
end
open( config.player_news_url ) do |file|
doc = Nokogiri::XML(file.read)
doc.xpath('//row').each do |player_element|
player = Player.find_by_sporting_news_id( player_element['PLAYER_ID'].to_i )
if player
content = "#{player_element['COMMENT']}. #{player_element['IMPACT']}."
content.gsub!("..",".")
article = Article.new
article.title = "News for #{player.first_name} #{player.last_name}"
article.category = "Player News"
article.player = player
article.contents = content
articles << article
p "#{player.first_name} #{player.last_name}"
end
end
end
Article.transaction do
Article.delete_all("player_id is not null")
articles.each {|article| article.save }
end
rescue Exception => e
Zumobi::ExceptionHandler.error e
end
|