ruby

Delphi code posted
created at 27 Jan 10:52, updated at 31 Jan 18:18

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def get_and_parse_news(date = Time.now)
    response = news_request(date)
    if response
      cur_season_id = Season.get_cur_season.id
      response['Updates'].each do |update_item|
        footballer = Footballer.where(extid: update_item['Player']['OptaId'], season_id: cur_season_id).first
        next if footballer.nil?

        news_item = News.find_or_initialize_by(rotowire_update_idi: update_item['Id'])
        if news_item.new_record?
          news_item.assign_attributes(
            rotowire_update_idi: update_item['Id'],
            headline: update_item['Headline'],
            notes: update_item['Notes'],
            analysis: update_item['Analysis'],
            news_date: update_item['DateTime'],
            headline_background_color: footballer.real_team.color,
            source: 'http://rotowire.com',
            source_name: 'RotoWire'
          )
          news_item.save!
          news_item.footballers << footballer
        end
      end
    end
  end
1012 Bytes in 5 ms with coderay