-
Notifications
You must be signed in to change notification settings - Fork 1
/
amiami.rb
46 lines (41 loc) · 1.32 KB
/
amiami.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# coding: utf-8
require 'open-uri'
require 'nokogiri'
class Amiami
URLS = ["http://www.amiami.jp/top/detail/detail?gcode=GAME-0017669", # neon+zelda
"http://www.amiami.jp/top/detail/detail?gcode=GAME-0017666", # gray+zelda
"http://www.amiami.jp/top/detail/detail?gcode=GAME-0017599", # neon
"http://www.amiami.jp/top/detail/detail?gcode=GAME-0017598", # gray
]
def check(htmlfp=nil)
items = URLS.map do |url|
check_one(url, htmlfp)
end.compact
return nil if items.empty?
items.map do |t|
t[:url] + "\n" + t[:name] + "\n" + t[:price] + "\n"
end
end
def check_one(url, htmlfp=nil)
charset = nil
html = open(url) do |f|
charset = f.charset
f.read
end
if htmlfp
htmlfp.puts("-----------------------------------------------------------------------")
htmlfp.puts("URL => #{url}")
htmlfp.write(html)
end
doc = Nokogiri::HTML.parse(html, nil, charset)
name = doc.css("h2.heading_10").text.strip
return nil if name =~ /在庫切れ/
price = doc.css(".selling_price").text.strip
available = (doc.css("#right_menu img[alt='販売停止中']").count != 1)
if name.empty? || price.empty? || !available
nil
else
{name: name, price: price, available: available, url: url}
end
end
end