Skip to content

Instantly share code, notes, and snippets.

@st63jun
Last active December 12, 2015 04:18
Show Gist options
  • Save st63jun/4713317 to your computer and use it in GitHub Desktop.
Save st63jun/4713317 to your computer and use it in GitHub Desktop.
学食のメニュー取得するやつ
#!env ruby
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Jun SAITO <jsaito@xopowo.info>
#
# This is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this. If not, see <http://www.gnu.org/licenses/>.
require 'pebbles/citlunch'
require 'nkf'
require 'methadone'
include Methadone::Main
include Methadone::CLILogging
places = {
'tsuda' => [:tsuda_dining, "津田沼学生食堂"],
'shiba' => [:shiba_dining, "芝園学生食堂"],
'marin' => [:shiba_kissa, "芝園喫茶マリン"]
}
main do
date = Date.today + options[:after] - options[:before]
place = places[options[:place]]
raise ArgumentError.new("Error: 引数が不正です.") unless place
menus = CITLunch.get(place[0], date)
if menus == nil
puts "Error: メニューがありませんでした."
exit 1
end
WIDTH = 25
puts "# " + place[1]
menus.each do |menu|
header = "<#{menu.name}>"
padding = WIDTH - count_chars(header)
print "#{header}#{" " * padding}#{menu.price}円 "
puts "#{menu.details.join(", ")}"
end
end
description "工大ランチのメニュー情報を取得して表示します."
# defaults
options[:place] = 'tsuda'
options[:after] = options[:before] = 0
on("-p tsuda|shiba|marin", "--place", "どこのメニューを表示するかを指定します.") do |place|
options[:place] = place
end
on("-a N", "--after", "N日後のメニューを取得します.") do |after|
options[:after] = after.to_i
end
on("-b N", "--before", "N日前のメニューを取得します.") do |before|
options[:before] = before.to_i
end
# monkey patch for convert hankaku-kana to zenkaku-kana
module CITLunch
class Menu
def to_zenkana(str)
NKF::nkf("-Xw", str)
end
def name
to_zenkana(@name)
end
def details
@details.map {|s| to_zenkana(s)}
end
end
end
def count_chars(str)
str.encode("Shift_JIS").bytes.entries.size
end
go!
@st63jun
Copy link
Author

st63jun commented Feb 5, 2013

インストール

先に依存するGem入れてください.

$ gem install pebbles-citlunch -v '0.0.2'
$ gem install methadone -v '1.2.4'

あとはダウンロードしたスクリプトをcitmenu等の名前で保存して実行属性つけてください.

使い方な

Usage: citmenu [options]

工大ランチのメニュー情報を取得して表示します.

Options:
    -h, --help                       Show command line help
    -p, --place tsuda|shiba|marin    どこのメニューを表示するかを指定します.
                                     (default: tsuda)
    -a, --after N                    N日後のメニューを取得します.
                                     (default: 0)
    -b, --before N                   N日前のメニューを取得します.
                                     (default: 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment