Track last attack

This commit is contained in:
Andrew Tomaka 2015-04-23 16:32:57 -04:00
parent b3d110ea39
commit ab9322581e
2 changed files with 19 additions and 5 deletions

20
app.rb
View file

@ -13,13 +13,27 @@ get '/' do
mechanize = Mechanize.new mechanize = Mechanize.new
page = mechanize.get('http://trugul.com/highscores') 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]" highscores = page.search "//table[@id='highscores_table']//tr[@class='clickable']/td[2]"
@top20 = []
require 'pp'
@top20 = {}
highscores.each do |td_user| highscores.each do |td_user|
@top20 << td_user.text.strip user = td_user.text.scan(/[A-Za-z]+/)
@top20[user.first] = nil
end 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 erb :index
end end

View file

@ -25,7 +25,7 @@
<div class="col-md-3"> <div class="col-md-3">
<ul class="list-group"> <ul class="list-group">
<% @top20.each do |user| %> <% @top20.each do |user, last| %>
<li class="list-group-item"><%= user %></li> <li class="list-group-item"><%= user %><span class="pull-right"><%= last.strftime('%H:%M on %m-%d-%Y') if last %></li>
<% end %> <% end %>
</div> </div>