Changeset 26904
- Timestamp:
- 12/17/08 01:29:04 (4 years ago)
- Files:
-
- 1 modified
-
lang/ruby/robot-twitter/trunk/robot-twitter.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/robot-twitter/trunk/robot-twitter.rb
r26902 r26904 14 14 require 'gmail' 15 15 16 $last_statuses = ""16 $last_statuses = '' 17 17 load 'last_statuses.rb' 18 18 … … 25 25 page = agent.submit(form, form.buttons.first) 26 26 27 mail = ""27 mail = '' 28 28 is_first = true 29 statuses = ""29 statuses = '' 30 30 31 31 for i in 1..30 32 puts "scraping ... Page " + i.to_s + "\n"33 page = agent.get( 'http://twitter.com/home/?page=' + i.to_s)32 puts "scraping ... Page #{i}\n" 33 page = agent.get("http://twitter.com/home/?page=#{i}") 34 34 page.body = page.body.toutf8 35 35 … … 38 38 content = CGI.unescapeHTML(entry.search('span.entry-content').first.inner_html).gsub(/^\s+/, '') 39 39 40 # リンクは ... で省略されるので urlに置き換える41 content = content.gsub(%r{<a\s+href="([^"]* ?)"\s+rel="[^"]*?"[^>]*?>.*?</a>}m, '\1')40 # リンクは ... で省略されるので URL に置き換える 41 content = content.gsub(%r{<a\s+href="([^"]*)"\s+rel="[^"]*"[^>]*>.*?</a>}m, '\1') 42 42 43 43 # 文字オーバーのリンクは削除する 44 content = content.gsub(%r{<a\s+href="[^"]* ?"[^>]*?>\.+</a>}m, '')44 content = content.gsub(%r{<a\s+href="[^"]*"[^>]*>\.+</a>}m, '') 45 45 46 46 # @username のリンクを外す 47 content = content.gsub(%r{<a\s+href="[^"]* ?"[^>]*?>(.*?)</a>}m, '\1')47 content = content.gsub(%r{<a\s+href="[^"]*"[^>]*>(.*?)</a>}m, '\1') 48 48 49 49 meta = entry.search('a[@class="entry-date"]').first 50 50 time = meta.search('span.published').first.inner_text 51 statuses = meta[ "href"]51 statuses = meta['href'] 52 52 53 # 既読になった最新のステータスの urlを記録する53 # 既読になった最新のステータスの URL を記録する 54 54 if is_first 55 File.open( "last_statuses.rb", "wb") {|file| file.write('$lastStatuses = "' + statuses + '"' + "\n")}55 File.open('last_statuses.rb', 'wb') {|file| file.write(%{$lastStatuses = "#{statuses}"\n})} 56 56 is_first = false 57 57 end … … 62 62 63 63 # 逆順に追加する 64 stat = "-----------------------------------------\n"65 stat += name + "\n\n"66 stat += content + "\n"67 stat += time + "\n"64 stat = "-----------------------------------------\n" 65 stat << "#{name}\n\n" 66 stat << "#{content}\n" 67 stat << "#{time}\n" 68 68 mail = stat + mail 69 69 end 70 70 71 if mail == ""72 puts "** ERROR ** incorrect account or passowrd, otherwise robot-twitter does not work on updated twitter.com"71 if mail == '' 72 puts '** ERROR ** incorrect account or passowrd, otherwise robot-twitter does not work on updated twitter.com' 73 73 break 74 74 end … … 79 79 end 80 80 81 if mail != ""82 Gmail.send(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD'], ENV['GMAIL_ADDRESS'], ENV['GMAIL_ADDRESS'], "from robot-twitter", mail.tosjis.tojis)81 if mail != '' 82 Gmail.send(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD'], ENV['GMAIL_ADDRESS'], ENV['GMAIL_ADDRESS'], 'from robot-twitter', mail.tosjis.tojis) 83 83 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)