module SportsDb class TeamAndRosterBuilder def self.update_player_image_urls p "update_player_image_urls ..." config_feeds = SimpleConfig.for(:feeds) require 'open-uri' open( config_feeds.player_images_url ) do |file| doc = Nokogiri::XML(file.read) doc.xpath('//row').each do |player_element| # The date is in format '08-MAY-77' and we need '8/5/1977' as a string. However, this still doesn't # strip leading zeroes off days, which we need to do to match this date as a string. # Convert to string, replace last bit so it says "19xx", parse to date, and then format # in the D/M/Y format. Then finally remove leading zeroes. if !player_element['BIRTH_DATE'].blank? adj_birth_date = DateTime.strptime(player_element['BIRTH_DATE'].to_s, "%m/%d/%Y").to_s end # Try only the name first. matches = Player.find_by_last_comma_first( player_element['PLAYER_NAME'] ) # But if there's more than one, then attempt to whittle it down with the birthday matches = matches.select {|p| p.birth_date == adj_birth_date } if (matches.length > 1) if (matches.length == 1) player = matches[0] player.image_url = player_element['PLAYER_MUG'] player.sporting_news_id = player_element['PLAYER_ID'].to_i player.save p "img- #{player_element['PLAYER_NAME']} - #{player_element['PLAYER_MUG']}" else p "Unable to Match -- #{player_element['PLAYER_NAME']}" end end end rescue Exception => e Zumobi::ExceptionHandler.error e end def self.update_team_top25_rank p "Set Top 25 Rank" rank_issuer_key = map_poll_key(CONFIG.rank_based_on_poll) rankings = PollRanking.all(:conditions => ["issuer_key = ?", rank_issuer_key]) rankings.each do |obj| team_obj = Team.find(obj.team_id) # Only rank 1-25 (bug 24359) if team_obj.present? && obj.rank.to_i < 26 p "#{team_obj.city_name} ##{obj.rank}" team_obj.rank = obj.rank team_obj.save end end end def self.map_poll_key(poll_key) case poll_key when "poll-ap" "1" when "poll-usat" "2" when "ranking-bcs" "3" when "ap" "ap" when "coaches" "coaches" when "rpi" "rpi" else "1" end end end end