Changeset 26904

Show
Ignore:
Timestamp:
12/17/08 01:29:04 (4 years ago)
Author:
drry
Message:
  • fixed regexes.
  • et cetera.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/robot-twitter/trunk/robot-twitter.rb

    r26902 r26904  
    1414require 'gmail' 
    1515 
    16 $last_statuses = "" 
     16$last_statuses = '' 
    1717load 'last_statuses.rb' 
    1818 
     
    2525page = agent.submit(form, form.buttons.first) 
    2626 
    27 mail = "" 
     27mail = '' 
    2828is_first = true 
    29 statuses = "" 
     29statuses = '' 
    3030 
    3131for 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}") 
    3434  page.body = page.body.toutf8 
    3535 
     
    3838    content = CGI.unescapeHTML(entry.search('span.entry-content').first.inner_html).gsub(/^\s+/, '') 
    3939 
    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') 
    4242 
    4343    # 文字オーバーのリンクは削除する 
    44     content = content.gsub(%r{<a\s+href="[^"]*?"[^>]*?>\.+</a>}m, '') 
     44    content = content.gsub(%r{<a\s+href="[^"]*"[^>]*>\.+</a>}m, '') 
    4545 
    4646    # @username のリンクを外す 
    47     content = content.gsub(%r{<a\s+href="[^"]*?"[^>]*?>(.*?)</a>}m, '\1') 
     47    content = content.gsub(%r{<a\s+href="[^"]*"[^>]*>(.*?)</a>}m, '\1') 
    4848 
    4949    meta = entry.search('a[@class="entry-date"]').first 
    5050    time = meta.search('span.published').first.inner_text 
    51     statuses = meta["href"] 
     51    statuses = meta['href'] 
    5252 
    53     # 既読になった最新のステータスの url を記録する 
     53    # 既読になった最新のステータスの URL を記録する 
    5454    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})} 
    5656      is_first = false 
    5757    end 
     
    6262 
    6363    # 逆順に追加する 
    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" 
    6868    mail = stat + mail 
    6969  end 
    7070 
    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' 
    7373    break 
    7474  end 
     
    7979end 
    8080 
    81 if mail != "" 
    82   Gmail.send(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD'], ENV['GMAIL_ADDRESS'], ENV['GMAIL_ADDRESS'], "from robot-twitter", mail.tosjis.tojis) 
     81if mail != '' 
     82  Gmail.send(ENV['GMAIL_USERNAME'], ENV['GMAIL_PASSWORD'], ENV['GMAIL_ADDRESS'], ENV['GMAIL_ADDRESS'], 'from robot-twitter', mail.tosjis.tojis) 
    8383end