Add top 20 listing
This commit is contained in:
parent
14c25dd6b1
commit
b3d110ea39
4 changed files with 69 additions and 22 deletions
1
Gemfile
1
Gemfile
|
@ -8,6 +8,7 @@ gem 'sinatra-flash'
|
|||
gem 'sinatra-redirect-with-flash'
|
||||
gem 'rake'
|
||||
gem 'json'
|
||||
gem 'mechanize'
|
||||
|
||||
group :production do
|
||||
gem 'pg'
|
||||
|
|
25
Gemfile.lock
25
Gemfile.lock
|
@ -16,11 +16,31 @@ GEM
|
|||
tzinfo (~> 1.1)
|
||||
arel (6.0.0)
|
||||
builder (3.2.2)
|
||||
domain_name (0.5.24)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
foreman (0.78.0)
|
||||
thor (~> 0.19.1)
|
||||
http-cookie (1.0.2)
|
||||
domain_name (~> 0.5)
|
||||
i18n (0.7.0)
|
||||
json (1.8.2)
|
||||
mechanize (2.7.3)
|
||||
domain_name (~> 0.5, >= 0.5.1)
|
||||
http-cookie (~> 1.0)
|
||||
mime-types (~> 2.0)
|
||||
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
||||
net-http-persistent (~> 2.5, >= 2.5.2)
|
||||
nokogiri (~> 1.4)
|
||||
ntlm-http (~> 0.1, >= 0.1.1)
|
||||
webrobots (>= 0.0.9, < 0.2)
|
||||
mime-types (2.4.3)
|
||||
mini_portile (0.6.2)
|
||||
minitest (5.6.0)
|
||||
net-http-digest_auth (1.4)
|
||||
net-http-persistent (2.9.4)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
ntlm-http (0.1.1)
|
||||
pg (0.18.1)
|
||||
rack (1.6.0)
|
||||
rack-protection (1.5.3)
|
||||
|
@ -43,6 +63,10 @@ GEM
|
|||
tilt (2.0.1)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.7.1)
|
||||
webrobots (0.1.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
@ -51,6 +75,7 @@ DEPENDENCIES
|
|||
activerecord
|
||||
foreman
|
||||
json
|
||||
mechanize
|
||||
pg
|
||||
rake
|
||||
sinatra
|
||||
|
|
12
app.rb
12
app.rb
|
@ -1,6 +1,8 @@
|
|||
require 'sinatra'
|
||||
require 'sinatra/activerecord'
|
||||
require 'json'
|
||||
require 'mechanize'
|
||||
require 'nokogiri'
|
||||
require './environments'
|
||||
|
||||
set :public_folder, 'public'
|
||||
|
@ -8,6 +10,16 @@ set :public_folder, 'public'
|
|||
# CONTROLLER
|
||||
get '/' do
|
||||
@raids = Raid.all.reverse
|
||||
|
||||
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 = []
|
||||
highscores.each do |td_user|
|
||||
@top20 << td_user.text.strip
|
||||
end
|
||||
|
||||
erb :index
|
||||
end
|
||||
|
||||
|
|
|
@ -1,22 +1,31 @@
|
|||
<table class="table table-striped table-hover table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Attacker</td>
|
||||
<td>Defender</td>
|
||||
<td>Soldiers</td>
|
||||
<td>Money</td>
|
||||
<td>Time</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @raids.each do |raid| %>
|
||||
<tr>
|
||||
<td style="<%= player_style(raid.attacker) %>"><%= raid.attacker %></td>
|
||||
<td style="<%= player_style(raid.defender) %>"><%= raid.defender %></td>
|
||||
<td class="text-right"><%= readable_number(raid.soldiers) %></td>
|
||||
<td class="text-right"><%= readable_number(raid.money) %></td>
|
||||
<td class="text-right"><%= raid.created_at.strftime('%H:%M on %m-%d-%Y') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="col-md-9">
|
||||
<table class="table table-striped table-hover table-bordered table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Attacker</td>
|
||||
<td>Defender</td>
|
||||
<td>Soldiers</td>
|
||||
<td>Money</td>
|
||||
<td>Time</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @raids.each do |raid| %>
|
||||
<tr>
|
||||
<td style="<%= player_style(raid.attacker) %>"><%= raid.attacker %></td>
|
||||
<td style="<%= player_style(raid.defender) %>"><%= raid.defender %></td>
|
||||
<td class="text-right"><%= readable_number(raid.soldiers) %></td>
|
||||
<td class="text-right"><%= readable_number(raid.money) %></td>
|
||||
<td class="text-right"><%= raid.created_at.strftime('%H:%M on %m-%d-%Y') %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<ul class="list-group">
|
||||
<% @top20.each do |user| %>
|
||||
<li class="list-group-item"><%= user %></li>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue