Skip to content

Instantly share code, notes, and snippets.

@tondol
Last active December 31, 2015 08:39
Show Gist options
  • Save tondol/7962213 to your computer and use it in GitHub Desktop.
Save tondol/7962213 to your computer and use it in GitHub Desktop.
スタドリ効率でモバマスのアイドルをソートする
# -*- coding: utf-8 -*-
require 'open-uri'
require 'nokogiri'
# 下記サイトから相場データを取得する
# http://imascg.info/
url = "http://imascg.info/idol/?targetDate=ALL"
accept_language = "ja,en;q=0.8"
html = open(url, "accept-language" => accept_language).read
rows = []
Nokogiri::HTML(html).css("#IdolTable tbody tr").each {|elem|
cols = []
elem.css("td").each {|td|
cols << td.content.strip
}
rows << cols
}
# [MAX攻]が15000以上のものを抽出する
rows.select! {|cols|
cols[4].to_i >= 15000
}
# [MAX攻]/[先週のスタドリ相場]でソートする
rows.each {|cols|
cost = cols[4].to_f
rate = cols[12].to_f
cols << (rate == 0 ? 0 : cost / rate)
}
rows.sort! {|a, b| -1.0 * (a[19] <=> b[19]) }
filename = "idol.html"
headers = [
"名前","属性","レアリティ","コスト","MAX攻","MAX守","攻守合計","攻コス比","守コス比","特技","効果",
"1ヶ月スタドリ相場","1週間スタドリ相場","昨日のスタ相場","今日のスタ相場",
"1ヶ月マニー相場","1週間マニー相場","昨日のマニー相場","今日のマニー相場",
"スタドリ効率",
]
# HTMLテンプレートの定義
# http://weboook.blog22.fc2.com/blog-entry-329.html
html_header = <<-EOS
<html>
<head>
<meta charset="utf-8" />
<style>
table {
width: auto;
border-spacing: 0;
font-size:14px;
}
table th {
color: #fff;
padding: 8px 15px;
background: #258;
background:-moz-linear-gradient(rgba(34,85,136,0.7), rgba(34,85,136,0.9) 50%);
background:-webkit-gradient(linear, 100% 0%, 100% 50%, from(rgba(34,85,136,0.7)), to(rgba(34,85,136,0.9)));
font-weight: bold;
border-left:1px solid #258;
border-top:1px solid #258;
border-bottom:1px solid #258;
line-height: 120%;
text-align: center;
text-shadow:0 -1px 0 rgba(34,85,136,0.9);
box-shadow: 0px 1px 1px rgba(255,255,255,0.3) inset;
}
table th:first-child {
border-radius: 5px 0 0 0;
}
table th:last-child {
border-radius:0 5px 0 0;
border-right:1px solid #258;
box-shadow: 2px 2px 1px rgba(0,0,0,0.1),0px 1px 1px rgba(255,255,255,0.3) inset;
}
table tr td {
padding: 8px 15px;
border-bottom: 1px solid #84b2e0;
border-left: 1px solid #84b2e0;
text-align: center;
}
table tr td:last-child {
border-right: 1px solid #84b2e0;
box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
}
table tr {
background: #fff;
}
table tr:nth-child(2n+1) {
background: #f1f6fc;
}
table tr:last-child td {
box-shadow: 2px 2px 1px rgba(0,0,0,0.1);
}
table tr:last-child td:first-child {
border-radius: 0 0 0 5px;
}
table tr:last-child td:last-child {
border-radius: 0 0 5px 0;
}
table tr:hover {
background: #bbd4ee;
cursor:pointer;
}
</style>
</head>
<body>
<table>
EOS
html_footer = <<-EOS
</table>
</body>
</html>
EOS
File.open(filename, "w") {|f|
f.puts(html_header)
f.puts("<tr>")
f.puts("<th>" + headers.join("</th><th>") + "</th>")
f.puts("</tr>")
rows.each {|cols|
f.puts("<tr>")
f.puts("<td>" + cols.join("</td><td>") + "</td>")
f.puts("<tr>")
}
f.puts(html_footer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment