2010年1月 のアーカイブ

よるほーbotのソースコード

2010年1月31日 日曜日

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

?Download yoruho.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/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)
}
 
# ここで人数を出力

Mac/iPhoneのソフトに期待すること

2010年1月31日 日曜日

まずは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用にそれぞれファイルを管理しないといけないので、解像度の違う動画をまとめられて、バックグラウンドで勝手に変換してくれる機能が欲しいです。

iPadは買いか?

2010年1月31日 日曜日

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

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

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

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

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

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

自作ポテトチップスがおいしいでござる

2010年1月15日 金曜日

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

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

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

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

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

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

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