Archive for 1月, 2010

とりあえずPOSTする箇所とかは除いて、コアの部分だけ。
質問はコメントにください。

#!/home/ikemo/local/bin/ruby -Ku

# -*- encoding: utf-8 -*-

require 'net/http'
require 'rexml/document'
require 'timeout'
require 'time'
require 'dbm'
require 'uri'

include REXML

$yoruho = URI.encode("よるほ")
$yoruho_pittari = URI.encode("さんよるほーピッタリ賞です。おめでとうございます。")

user = 'yoruho'
pass = 'password'

def get_yoruho_buzztter(max_id)
  rss = ""
  begin
    res = nil
    now = Time::now
    yoru = Time::local(now.year, now.month, now.day, 0, 0, 0)

    timeout(60, IOError) {
      http = Net::HTTP.new("buzztter.com")
      if max_id then
        res = http.get("/ja/rss/#{$yoruho}?since=#{yoru.to_i}&max_id=#{max_id}",
                      {'User-Agent' => "Ruby/#{RUBY_VERSION}"})
      else
        res = http.get("/ja/rss/#{$yoruho}?since=#{yoru.to_i}",
                      {'User-Agent' => "Ruby/#{RUBY_VERSION}"})
      end
      rss = res.body
    }

    raise IOError if res.code != "200"
  end

  id = nil
  success = []
  doc = Document.new(rss)
  doc.elements.each("/rss/channel/item") {|item|
    title = item.elements["title"].text
    title_regexp = %r|([^:]+): .*|
    title_regexp.match(title)
    name = $1
    time = Time::parse(item.elements["pubDate"].text).localtime
    link = item.elements["link"].text
    link_regexp = %r|http://twitter.com/[^/]+/statuses/(.*)|
    link_regexp.match(link)
    id = $1
    if time.day == Time::now.day && time.hour == 0 && time.min == 0 && time.sec == 0 then
      success.push(name)
    elsif time.day != Time::now.day then
      return success, true, id
    end
  }

  return success, false, id
end

def get_yoruho_official(i)
  rss = ""
  begin
    res = nil

    timeout(60, IOError) {
      http = Net::HTTP.new("search.twitter.com")
      res = http.get("/search.atom?q=#{$yoruho}&page=#{i}&rpp=50",
                    {'User-Agent' => "Ruby/#{RUBY_VERSION}"})
      rss = res.body
    }

    raise IOError if res.code != "200"
  end

  success = []
  doc = Document.new(rss)
  doc.elements.each("//feed/entry") {|entry|
    url = entry.elements["author/uri"].text
    name_regexp = %r|^http://twitter.com/(.*)$|
    name_regexp.match(url)
    name = $1
    time = Time::parse(entry.elements["updated"].text).localtime
    if time.day == Time::now.day && time.hour == 0 && time.min == 0 && time.sec == 0 then
      success.push(name)
    elsif time.day != Time::now.day then
      return success, true
    end
  }

  return success, false
end

def get_yoruho(i)
  rss = ""
  begin
    res = nil

    timeout(60, IOError) {
      http = Net::HTTP.new("pcod.no-ip.org")
      res = http.get("/yats/search?query=#{$yoruho}&page=#{i}&rss",
                    {'User-Agent' => "Ruby/#{RUBY_VERSION}"})
      rss = res.body
    }

    raise IOError if res.code != "200"
  end

  success = []
  doc = Document.new(rss)
  doc.elements.each("//feed/entry") {|entry|
    name = entry.elements["author/name"].text
    time = Time::parse(entry.elements["updated"].text).localtime
    if time.day == Time::now.day && time.hour == 0 && time.min == 0 && time.sec == 0 then
      success.push(name)
    elsif time.day != Time::now.day then
      return success, true
    end
  }

  return success, false
end

def get_yoruho_timeline(max_id)
  xml = ""
  begin
    res = nil

    timeout(60, IOError) {
      path = if max_id != nil then
               "/statuses/friends_timeline.xml?count=200&max_id=#{max_id}"
             else
               "/statuses/friends_timeline.xml?count=200"
             end
      req = Net::HTTP::Get.new(path)
      req.basic_auth "yoruho", "password"

      Net::HTTP.start("twitter.com", 80) {|http|
        res = http.request(req)

        xml = res.body
      }
    }

    raise IOError if res.code != "200"
  end

  success = []
  id = nil
  doc = Document.new(xml)
  doc.elements.each("/statuses/status") {|status|
    screen_name = status.elements["user/screen_name"].text
    time = Time::parse(status.elements["created_at"].text).localtime
    text = status.elements["text"].text
    id = status.elements["id"].text

    if text.include?("よるほ") && time.day == Time::now.day && time.hour == 0 && time.min == 0 && time.sec == 0 then
      success.push(screen_name)
    elsif time.day != Time::now.day then
      return success, true, id
    end
  }

  return success, false, id
end

def post(name, status)
  # ここでTwitterにPOSTする
end

#
# kokokara
#
success_list_timeline = []
max_id = nil
(1..50).each {|i|
  count = 0

  begin
    (success, end_flag, max_id) = get_yoruho_timeline(max_id)
    success_list_timeline += success
    if end_flag == true then
      break
    end
  rescue
    count += 1
    retry if count <= 0
  end
}

success_list_buzztter = []
max_id = nil
[1].each {|i|
  count = 0

  begin
    (success, end_flag, max_id) = get_yoruho_buzztter(max_id)
    success_list_buzztter += success
    if end_flag == true then
      break
    end
  rescue
    count += 1
    retry if count <= 0
  end
}

success_list_pcod = []
(1..0).each {|i|
  count = 0

  begin
    (success, end_flag) = get_yoruho(i)
    success_list_pcod += success
    if end_flag == true then
      break
    end
  rescue
    count += 1
    retry if count <= 0
  end
}

success_list_official = []
(1..50).each {|i|
  count = 0

  begin
    (success, end_flag) = get_yoruho_official(i)
    success_list_official += success
    if end_flag == true then
      break
    end
  rescue
    count += 1
    retry if count <= 0
  end
}

success_list = success_list_timeline | success_list_pcod | success_list_official | success_list_buzztter

db = DBM::open("yoruho")
success_list.each {|name|
  if db[name] == nil then
    db[name] = "1"
  else
    db[name] = (db[name].to_i + 1).to_s
  end
}

success_list.each {|name|
  status = 'status=@' + name + "%20" + $yoruho_pittari + "%20" + db[name] + "%E5%9B%9E%E7%9B%AE%E3%80%82"
  post(name, status)

  # ここで段級の判定

  post(name, words)
}

# ここで人数を出力

まずはiPhone OS 4.0に期待すること

・Bluetooth機能向上

Bluetoothのヘッドセット買ったんですが、曲送りなどが出来ないのが残念。これは特に問題もないと思うので対応して欲しい。キーボードは…iPadを使えということかなぁ。SCMS-Tは…evilな規格なんで実装しないでしょうねw

・マルチタスクとは言わなくてもバックグラウンドで動かせる機能

例えばダウンロードとかバックグラウンドで動かせると少し嬉しい。マルチタスクはUIやメモリの問題があると思うけど、バックグラウンドで動かすための専用APIなら提供できるはず。

・Flashはどうなる?

ライセンスの問題で搭載しないと思ってたんですが、互換ソフト作るのOKになったんですね…ならAppleが独自に実装するというのもありかも。開発はしているでしょうね。載せるかどうかは別。少なくとも今のスタンスはHTML5使えということでしょうね。

・動画管理の改善

動画リストは欲しいっすね…。

Mac OS Xに期待すること

・Mail.appのバグ

なんかPOPでうまく取得できないバグあるんですが(´・ω・`)

・iTunesの動画処理の改善

今の仕様だとiPhoneとiPodとiPad用にそれぞれファイルを管理しないといけないので、解像度の違う動画をまとめられて、バックグラウンドで勝手に変換してくれる機能が欲しいです。

27日(日本時間28日)発表されたイベント見てたんですが、買うかどうか微妙ですね。

とりあえずハードと基本ソフトは予想通りです。まず大きさは7インチと10インチの2つという話もあったんですが、 当然一つに絞ると思ってました。解像度はiPhoneの整数倍だと思ってたのではずれ。値段は5万だろうと思ってたので当たり。まぁ16GBモデルですが。$999はないよな。残念だったのはカメラがないことくらいかな。CPUも独自のを載せてくるとは思わなかったな。

OSはiPhone OS搭載。当然iPhoneのアプリも動く。そりゃそうだろと思った。Mac OS Xと予想した人はどう見てもセンスない。

で、買いかと言われると微妙な感じですね。確かにiPhone使ってるとPDFを読んだりするときに大きい画面があるといいなぁと思いますが、携帯性が損なわれるという問題もあるので何とも。

Appleとしては、開発者に面白いものを作ってもらおうという発想じゃないかなぁと。これが新規参入者なら開発者を引きつけるだけでも大変だと思いますが、AppleはiPhoneの実績があるので。単純に画面が大きくなったiPhoneというだけでもそれなりに面白そうな感じはします。

自分の場合はその前にMacBookを買い換えなきゃと思うわけですが…。まだ発表されないのかなぁ。

“パール金属 レンジby シリコーンシャカシャカ チップス セット C-807″ (パール金属)

こんなの買いました。Amazonでは類似のもっと安い商品もあるようです。

じゃがいものスライサーと、スライスしたじゃがいもを立てるゴムの箇所から出来てます。

24枚立てられますが、12枚にスライスして(じゃがいもの半分)間を空けておくのがオススメ。

時間は600Wで4分30秒。手持ちの電子レンジによって変えてみてください。

市販のようにパリパリにはなりませんが、おいしいです。

とか書いてたら、Twitterでスモークチーズパウダーというのを教えてもらいました。今度買って試してみよう。