diff --git a/app/assets/stylesheets/index.css b/app/assets/stylesheets/index.css index f69c102..817c378 100644 --- a/app/assets/stylesheets/index.css +++ b/app/assets/stylesheets/index.css @@ -1,7 +1,9 @@ #container { - height: 100%; - width: 100%; + overflow: hidden; position: relative; + margin: auto; + height: 90vh; + width: 90vw; } #get_club_name { diff --git a/app/models/player.rb b/app/models/player.rb index 49c03a2..59b309d 100644 --- a/app/models/player.rb +++ b/app/models/player.rb @@ -38,4 +38,13 @@ def strip_nationality self.save end end + + # avatar methods + def avatar_remote_url=(url_value) + if url_value.present? + self.avatar = URI.parse(url_value) + @avatar_remote_url = url_value + end + end + end \ No newline at end of file diff --git a/app/views/landings/index.html.erb b/app/views/landings/index.html.erb index 8092120..e6fe902 100644 --- a/app/views/landings/index.html.erb +++ b/app/views/landings/index.html.erb @@ -2,47 +2,242 @@ <%= stylesheet_link_tag 'application' %> -
- <%= select("get", "club_name", Club.all.collect {|p| [ p.name ] }, {include_blank: 'Select club:'}) %> +
+ <%= select("get", "club_name", Club.all.collect {|p| [ p.name ] }, {include_blank: 'Select club:'}) %> diff --git a/lib/tasks/scrape_player_avatars.rake b/lib/tasks/scrape_player_avatars.rake new file mode 100644 index 0000000..53e24c5 --- /dev/null +++ b/lib/tasks/scrape_player_avatars.rake @@ -0,0 +1,55 @@ +# scrapes all players in database... arguments coming soon + +namespace :app do + task :scrape_player_avatars => :environment do + require 'nokogiri' + require 'open-uri' + require 'thread' + require 'resolv' + require 'resolv-replace' + + url_base = 'http://www.transfermarkt.com' + + club_players = Player.all + + start = Time.now + + puts "Number of avatars to update: " + club_players.count.to_s + + work_q = Queue.new + club_players.each {|player| work_q << player} + + i = 0 + workers = (0..4).map do + Thread.new do + begin + while player = work_q.pop(true) + begin + doc = Nokogiri::HTML(open(url_base + player.profile_link)) + + avatar_url = doc.at_css('.dataBild>img').attributes["src"].value + avatar_url.prepend("http:") + + player.avatar_remote_url=(avatar_url) + player.save! + + print "\rNumber of players birthplaces updated: #{i + 1}" + i = i+1 + + rescue => e + puts "problem at #{profile_url}" + puts e.inspect + end + + end + rescue ThreadError + end + end + end + workers.map(&:join) + + finish = Time.now + + puts "\nIt took #{finish - start} seconds to get all player avatars" + end +end