-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
958b60d
commit 452a3ef
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'rexml/document' | ||
require 'pp' | ||
|
||
module Swimmy | ||
module Command | ||
class Coop < Swimmy::Command::Base | ||
class ShopInfoFormatter | ||
def format(shop) | ||
result = "" | ||
result += (shop.name + "\t" + shop.time + "\n") | ||
return result | ||
end | ||
end #ShopInfoFormatter | ||
|
||
command "coop" do |client, data, match| | ||
shopinfo = Swimmy::Service::Coop.new.get_shopinfolist("https://vsign.jp/okadai/maruco/shops") | ||
script = "" | ||
case match[:expression] | ||
when "open" | ||
shopinfo.each do |shop| | ||
if shop.open? == true | ||
script += ShopInfoFormatter.new.format(shop) | ||
end | ||
end | ||
client.say(channel: data.channel, text: script) | ||
when "time" | ||
shopinfo.each do |shop| | ||
script += ShopInfoFormatter.new.format(shop) | ||
end | ||
client.say(channel: data.channel, text: script) | ||
else script = "入力が間違っています\n" + | ||
"swimmy help coop と入力してコマンドを確認してください" | ||
client.say(channel: data.channel, text: script) | ||
end | ||
end #command | ||
|
||
help do | ||
title "coop" | ||
desc "生協の情報を表示する" | ||
long_desc "coop open - 空いているショップを表示する\n" + | ||
"coop time - ショップごとの営業時間を表示する" | ||
|
||
end #help | ||
end #class Coop | ||
end #module Command | ||
end #module Swimmy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Swimmy | ||
module Resource | ||
class ShopInfo | ||
attr_accessor :f_name,:state,:n_name,:time,:ex | ||
|
||
def initialize(f_name,state,n_name,time,ex) | ||
@f_name, @state, @n_name ,@time ,@ex = f_name, state, n_name, time, ex | ||
end | ||
|
||
def open? | ||
if @state == "OPEN" | ||
return true | ||
end | ||
end | ||
|
||
def name | ||
s = @f_name.chomp | ||
if s == @n_name | ||
return s | ||
end | ||
return s +"/"+ @n_name | ||
end | ||
|
||
def time | ||
return @time | ||
end | ||
end #class ShopInfo | ||
end #module Resouce | ||
end #module Swimmy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'open-uri' | ||
require 'nokogiri' | ||
|
||
module Swimmy | ||
module Service | ||
class Coop | ||
def get_shopinfolist(url) | ||
html = Nokogiri::HTML.parse(URI.open(url)) | ||
shops = [] | ||
shopdata = [] | ||
html.xpath('//h3[@class="bg-title-gray"]').each do |char| | ||
i = 0 | ||
d = 1 | ||
f_name = char.text | ||
f_name.slice!(0) #先頭の\nを削除 | ||
char.next_element.search('//span[@class = "text"]') | ||
text = char.next_element.text | ||
text = text.gsub(/\s+/,"\n") | ||
text = text.gsub(/\n{2,}/,"\n") | ||
text.slice!(0) | ||
text.lines(chomp: true) do |char| | ||
if d >4 | ||
shops << Swimmy::Resource::ShopInfo.new(f_name,shopdata[0],shopdata[1],shopdata[2],shopdata[3]) | ||
d = 1 | ||
i = 0 | ||
end | ||
shopdata[i]= char | ||
d = d + 1 | ||
i = i + 1 | ||
end | ||
shops << Swimmy::Resource::ShopInfo.new(f_name,shopdata[0],shopdata[1],shopdata[2],shopdata[3]) | ||
i = i + 1 | ||
end | ||
return shops | ||
end | ||
end | ||
end | ||
end |