From ab9322581e481f3cbdf4a652658daeabda3baba3 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 23 Apr 2015 16:32:57 -0400 Subject: [PATCH] Track last attack --- app.rb | 20 +++++++++++++++++--- views/index.erb | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app.rb b/app.rb index a3722cd..972878e 100644 --- a/app.rb +++ b/app.rb @@ -13,13 +13,27 @@ get '/' do mechanize = Mechanize.new page = mechanize.get('http://trugul.com/highscores') -# //div[@id='allEdition']/table//tr/td/span[@class='symbol']/a" highscores = page.search "//table[@id='highscores_table']//tr[@class='clickable']/td[2]" - @top20 = [] + + require 'pp' + @top20 = {} highscores.each do |td_user| - @top20 << td_user.text.strip + user = td_user.text.scan(/[A-Za-z]+/) + @top20[user.first] = nil end + @top20.keys.each do |top20| + @raids.each do |raid| + if raid.attacker == top20 || raid.defender == top20 + @top20[top20] = raid.created_at + break + end + end + end + + # get last attack for each + # order by date + erb :index end diff --git a/views/index.erb b/views/index.erb index a1126a8..08512c6 100644 --- a/views/index.erb +++ b/views/index.erb @@ -25,7 +25,7 @@