Hatena::Grouprubyist

たばさの RSSフィード

01/03(土) 2009

はてブお気に入り、500までらしいので

| はてブお気に入り、500までらしいので - たばさの を含むブックマーク はてなブックマーク - はてブお気に入り、500までらしいので - たばさの

はてブお気に入りjoin


hatebufavoritelist.txt に取得したいはてブユーザー一覧、一行に一人のリストをつくる。(hatebu_rss_head.rbの)rssを保存するtmpフォルダを適当な場所に設定。

以下のファイルを全部同じフォルダにおいて、そこにroot0というフォルダを作っておく。

hatebu_rss_server_loop.batを実行するとサーバーを立ち上げ、はてブrssを取得しtmpに保存、新着ぶくマ順にrss作成。

http://localhost:8000/rsstes.rss 

http://localhost:8000/rsstes_m.htm

にアクセスして見えればOK。


hatebu_rss_server_loop.bat

start rss_server.rb
start hatebu_rssgettmp_loop.bat
start hatebu_rssgettmp2join_deamon.bat

rss_server.rb

#!ruby -Ku
# 20081225 , tabasa
# 参考 http://www.thinkit.co.jp/article/117/2/

require 'thread'
require 'optparse'
require 'webrick'
include WEBrick

$timer=30
idListFile="hatebufavoritelist.txt"
maxfeed=10
opt = OptionParser.new
opt.on('-t val') {|v| $timer=v.to_i }
opt.on('-i file') {|v| idListFile=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.parse!(ARGV)

$timer = ($timer<10 ? 10 : $timer)

#rss=%w{
#http://b.hatena.ne.jp/hatecha/favorite.rss
#http://rubyist.g.hatena.ne.jp/hatecha/rss
#}

def rssUpdate
  system("start ruby hatebu_rssgettmp2join_start.rb -s -m300 -i hatebufavoritelist.txt")
end


#Thread.new{
# while 1
#  rssUpdate
#  sleep $timer*60
# end
#}

s = HTTPServer.new(
 :Port => 8000,
 :DocumentRoot => File.join(Dir::pwd, "root0")
)

s.mount_proc("/update") { |req, res|
  rssUpdate
  res.body = "up"
}

trap("INT"){ s.shutdown }
s.start


# http://localhost:8000/rsstes.rss

hatebu_rssgettmp_loop.bat

hatebu_rssgettmp_start.rb -t20 -T30 -m300 -i hatebufavoritelist.txt

hatebu_rssgettmp2join_start.rb

#!ruby -Ku
require 'rss'
require 'optparse'

$timer=0
maxfeed=10
idListFile="hatebufavoritelist.txt"

opt = OptionParser.new
opt.on('-t val') {|v| $timer=v.to_i }
opt.on('-i file') {|v| idListFile=v }
opt.on('-s') {|v| $single=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.parse!(ARGV)

rss=%w{
http://b.hatena.ne.jp/hatecha/favorite.rss
http://rubyist.g.hatena.ne.jp/hatecha/rss
}

$timer = ($timer<10 ? 10 : $timer)
while 1
  puts Time.now
  open("rssfeedlist.txt"){|f| rss =f.readlines.map{|i|i.chomp}.sort.uniq }
  p rss.size

  tmp="root0\\hateburssgettmp.txt"
  target="root0\\rsstes.rss"
  puts `rsstmp_join.rb -s -m #{maxfeed} #{rss*" "} #{idListFile} >#{tmp}`
  `copy #{tmp} #{target}`
  puts Time.now
  break if $single
  sleep $timer*60
end

hatebu_rssgettmp2join_deamon.bat

hatebu_rssgettmp2join_deamon.rb -t10 -m300 -i hatebufavoritelist.txt

hatebu_rssgettmp_start.rb

#!ruby -Ku
require 'rss'
require 'optparse'

$timer=0
$timer2=0
maxfeed=10
idListFile="hatebufavoritelist.txt"

opt = OptionParser.new
opt.on('-t val') {|v| $timer=v.to_i }
opt.on('-T val') {|v| $timer2=v.to_i }
opt.on('-i file') {|v| idListFile=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.parse!(ARGV)

rss=%w{
http://b.hatena.ne.jp/hatecha/favorite.rss
http://rubyist.g.hatena.ne.jp/hatecha/rss
}

$timer = ($timer<3 ? 3 : $timer)
$timer2 = ($timer2<10 ? 10 : $timer2)
while 1
  puts Time.now
  open("rssfeedlist.txt"){|f| rss =f.readlines.map{|i|i.chomp}.sort.uniq }
  p rss.size
  puts `ruby rssgettmp.rb -s -t #{$timer} -m #{maxfeed} #{rss*" "} #{idListFile}`
  puts Time.now
  sleep $timer2*60
end

hatebu_rss_head.rb

def maketmpname rss_url
  tmp="d:\\tmp\\"
  tmp +rss_url.gsub(/[:\/\\\*\"<>\|]/,"_")
end

rssgettmp.rb

#!ruby -Ku
require 'rss'
require 'optparse'
require 'hatebu_rss_head'

timer=3
maxfeed=10
opt = OptionParser.new
opt.on('-url') {|v| $urlmode=v }
opt.on('-r') {|v| $rand=v }
opt.on('-f') {|v| $fast=v }
opt.on('-n') {|v| $sortoff=v }
opt.on('-s') {|v| $stamp=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.on('-t timer') {|v| timer=v.to_i }
opt.parse!(ARGV)

$stderr.puts maxfeed,"timer=#{timer}"
rss_feeds = []
rss_urls = []
title="" 

# $stderr.puts "start0"

if ARGV==nil
  puts "output rss or urls (unique)"
  puts opt.to_s
  exit
end

# $stderr.puts "start"

rsslist=[]
ARGV.each{|i|
  if i=~/\.txt$/
    fav=[]
    open(i){|f| fav =(f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }
    rsslist += fav
  else
    rsslist << i
  end
}
open("hatebu_errorlist.txt"){|f| rsslist -= (f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }

 $stderr.puts rsslist.size

rsslist.each do | rss_url |
  sleep timer #
 # $stderr.puts rss_url
  begin
    open(rss_url) do | http |
      response = http.read
      tmpf = maketmpname( rss_url )
      open(tmpf, "w") do | file |
        file.puts response
      end
      $stderr.print ","
    end
  rescue Exception=>e
    err="#{e},#{rss_url}"
    $stderr.puts"#{err}"
  end
end

hatebu_rssgettmp2join_deamon.rb

#!ruby -Ku
require 'rss'
require 'optparse'

$timer=0
maxfeed=10
idListFile="hatebufavoritelist.txt"

opt = OptionParser.new
opt.on('-t val') {|v| $timer=v.to_i }
opt.on('-i file') {|v| idListFile=v }
opt.on('-s') {|v| $single=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.parse!(ARGV)

rss=%w{
http://b.hatena.ne.jp/hatecha/favorite.rss
http://rubyist.g.hatena.ne.jp/hatecha/rss
}

$timer = ($timer<10 ? 10 : $timer)
  puts Time.now
  open("rssfeedlist.txt"){|f| rss =f.readlines.map{|i|i.chomp}.sort.uniq }
  p rss.size

  tmp="root0\\hateburssgettmp.txt"
  target="root0\\rsstes.rss"
  puts `ruby rsstmp_join_deamon.rb -t15 -s -m #{maxfeed} #{rss*" "} #{idListFile} -o #{target} `
  puts Time.now

rsstmp_join_deamon.rb

#!ruby -Ku
require 'rss'
require 'optparse'
require 'hatebu_rss_head'
require 'thread'

maxfeed=10
timer=1
opt = OptionParser.new
opt.on('-url') {|v| $urlmode=v }
opt.on('-r') {|v| $rand=v }
opt.on('-f') {|v| $fast=v }
opt.on('-n') {|v| $sortoff=v }
opt.on('-s') {|v| $stamp=v }
opt.on('-o outfile') {|v| $outfile=v }
opt.on('-a autoexec') {|v| $auto=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.on('-t time') {|v| timer=v.to_i }
opt.parse!(ARGV)

$stderr.puts maxfeed
rss_feeds = {}
rss_urls = []
title="" 

# $stderr.puts "start0"

if ARGV==nil
  puts "output rss or urls (unique)"
  puts opt.to_s
  exit
end

# $stderr.puts "start"

rsslist=[]
ARGV.each{|i|
  if i=~/\.txt$/
    fav=[]
    open(i){|f| fav =(f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }
    rsslist += fav
  else
    rsslist << i
  end
}
open("hatebu_errorlist.txt"){|f| rsslist -= (f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }

 $stderr.puts rsslist.size

flag=false

Thread.new{
while 1
 rss_urls = []
 rsslist.each do | rss_url |
  sleep 5 # local file なので
  flag = true if rss_feeds.size > 10
  begin
    rss_url = maketmpname( rss_url )
    # $stderr.puts rss_url
    open(rss_url) do | http |
      response = http.read
      #$stderr.print","
      begin
        rss_results = RSS::Parser.parse(response, false)
      rescue
        $stderr.print"?"
        break
      end
      # $stderr.print"!"
      if rss_results && rss_results.channel && rss_results.channel.title
        title += "" if title.size > 0
        title += rss_results.channel.title
      end
    
      rss_results.items.each do | item |
        if item.link =~ /rd\.yahoo\..*\*(.*)/
          item.link = $1
        end
        unless rss_urls.include? item.link
          puts item.link if $fast
          rss_urls << item.link
          rss_feeds[item.link] = item
         # $stderr.print "."
        end
      end
      $stderr.print "."
    end
  rescue Exception=>e
    err="#{e},#{rss_url}"
    $stderr.puts"#{err}"
  end
 end
 flag=true
 sleep 10
end
}


def sellect feeds, size
  $stderr.puts feeds.size
  feeds.values.sort_by{|i| i.dc_date }.reverse[0..size]
end

while not flag
 sleep 4
end

while true
 $stderr.print">>"
 rss = RSS::Maker.make("2.0") do | writer |
  writer.channel.title = title || ""
  writer.channel.link = rss_urls[0] || ""
  writer.channel.description = title || ""
  writer.items.do_sort = true if not $sortoff
  sellect(rss_feeds, maxfeed).each do | feed | 
    # $stderr.puts ",", feed.dc_date, feed.dc_creator, feed.title
    feedcp =feed.dup
    creator = ((feed.dc_creator||"")+"  ")[0..1]
    feedcp.title =(creator)+"_"+(feed.title||"")+" "+feed.dc_date.to_s.sub("T"," ")
  #  feedcp.content_encoded=""
    feedcp.setup_maker(writer)
  end

  if $stamp
    item = writer.items.new_item
    item.title = Time.now.strftime('[rss update - %m月%d日(%a) %p %I:%M, %Y]') # ('%Y年%m月%d日(%a) %p %I時%M分%S秒')
    item.link = ""
    item.dc_subject =""
    item.description =""
    item.date = Time.parse(Time.now.to_s)
  end
 end


 case 
 when $urlmode
  if not $fast
    if $rand
      puts rss_urls.sort_by{rand}
    else
      puts rss_urls
    end
  end
 else
   if $outfile
     open($outfile, "w"){|f| f.puts rss.to_s }
     $stderr.puts `rss2html_g.rb #{$outfile}>root0\\rsstes_m.htm`#
   else
     puts rss.to_s
   end
   if $auto
     $stderr.puts `#{$auto}`
     $stderr.print $auto
   end
 end
 $stderr.print "(#{rss_urls.size})"
 sleep timer*60
end

rss2html_g.rb

lock

rsstmp_join.rb

#!ruby
# 参考
# http://builder.japan.zdnet.com/sp/ruby-doukaku-panel/story/0,3800086254,20375937,00.htm
require 'rss'
require 'optparse'
require 'hatebu_rss_head'

maxfeed=10
opt = OptionParser.new
opt.on('-url') {|v| $urlmode=v }
opt.on('-r') {|v| $rand=v }
opt.on('-f') {|v| $fast=v }
opt.on('-n') {|v| $sortoff=v }
opt.on('-s') {|v| $stamp=v }
opt.on('-m max') {|v| maxfeed=v.to_i }
opt.parse!(ARGV)

$stderr.puts maxfeed
rss_feeds = []
rss_urls = []
title="" 

# $stderr.puts "start0"

if ARGV==nil
  puts "output rss or urls (unique)"
  puts opt.to_s
  exit
end

# $stderr.puts "start"

rsslist=[]
ARGV.each{|i|
  if i=~/\.txt$/
    fav=[]
    open(i){|f| fav =(f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }
    rsslist += fav
  else
    rsslist << i
  end
}
open("hatebu_errorlist.txt"){|f| rsslist -= (f.readlines-["\n"]).map{|i|"http://b.hatena.ne.jp/#{i.chomp}/rss"}.sort.uniq }

 $stderr.puts rsslist.size

rsslist.each do | rss_url |
  # sleep 3 # local file なので
  begin
    rss_url = maketmpname( rss_url )
    # $stderr.puts rss_url
    open(rss_url) do | http |
      response = http.read
      $stderr.print","
      begin
        rss_results = RSS::Parser.parse(response, false)
      rescue
        $stderr.print"?"
        break
      end
      $stderr.print"!"
      if rss_results && rss_results.channel && rss_results.channel.title
        title += "" if title.size > 0
        title += rss_results.channel.title
      end
    
      rss_results.items.each do | item |
        if item.link =~ /rd\.yahoo\..*\*(.*)/
          item.link = $1
        end
        unless rss_urls.include? item.link
          puts item.link if $fast
          rss_urls << item.link
          rss_feeds << item
         # $stderr.print "."
        end
      end
      $stderr.print "."
    end
  rescue Exception=>e
    err="#{e},#{rss_url}"
    $stderr.puts"#{err}"
  end
end

def sellect feeds, size
  $stderr.puts feeds.size
  feeds.sort_by{|i| i.dc_date }.reverse[0..size]
end

rss = RSS::Maker.make("2.0") do | writer |
  writer.channel.title = title || ""
  writer.channel.link = rss_urls[0] || ""
  writer.channel.description = title || ""
  writer.items.do_sort = true if not $sortoff
  sellect(rss_feeds, maxfeed).each do | feed | 
    # $stderr.puts ",", feed.dc_date, feed.dc_creator, feed.title
    creator = ((feed.dc_creator||"")+"  ")[0..1]
    feed.title =(creator)+"_"+(feed.title||"")+" "+feed.dc_date.to_s.sub("T"," ")
    feed.setup_maker(writer)
  end 
  if $stamp
    item = writer.items.new_item
    item.title = Time.now.strftime('[rss update - %m月%d日(%a) %p %I:%M, %Y]') # ('%Y年%m月%d日(%a) %p %I時%M分%S秒')
    item.link = "" 
    item.dc_subject =""
    item.description =""
    item.date = Time.parse(Time.now.to_s) 
  end
end


case 
when $urlmode
  if not $fast
    if $rand
      puts rss_urls.sort_by{rand}
    else
      puts rss_urls
    end
  end
else
  puts rss.to_s
end
$stderr.print rss_urls.size


とまあいろいろ複雑になってしまった。

リストを作るのも面倒なので

add_hatebufavoritelist.rb

#!ruby 
print "field No.="
field=gets.to_i-1
li=[]
while gets
  $_=$_.split[ field ]
  f="hatebufavoritelist.txt"
  open(f, "a"){|f| f.puts $_; li<<$_ }
end
puts li*","

こんなかんじで適当なエントリーページでブックマーカーをコピペ収集。

それをftpで上げてみた

それをftpで上げてみた - たばさの を含むブックマーク はてなブックマーク - それをftpで上げてみた - たばさの

プログラム関係のはてブユーザーrssを900ほど使った。更新するかは未定。

http://www004.upp.so-net.ne.jp/tabasa/rsstes_m.htm

timeoutする

| timeoutする - たばさの を含むブックマーク はてなブックマーク - timeoutする - たばさの

http://golf.shinh.org/p.rb?Maximum+Cyclic+Segment+Sum

#!ruby -n
n=(a=$_.split*2).size/2
z={}
n.times{|j|j.upto(j+n-1){|k|z[[j,k]]=eval(a[j..k]*"+")}}
x=z.select{|i,j|j==z.values.max}[0][0];puts a[x[0]..x[1]]*" "
トラックバック - http://rubyist.g.hatena.ne.jp/hatecha/20090103
カレンダー
<< 2009/01 >>
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
archive Error : RSSが取得できませんでした。