Skip to content

Instantly share code, notes, and snippets.

@smokeymonkey
Created June 21, 2011 05:18
Show Gist options
  • Save smokeymonkey/1037291 to your computer and use it in GitHub Desktop.
Save smokeymonkey/1037291 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
require "rubygems"
require 'oauth'
require 'rubytter'
require 'rss/1.0'
require 'open-uri'
# 設定ファイルをロードする
# OAuth用の以下4つの変数を定義
# CONSUMER_KEY
# CONSUMER_SECRET
# ACCESS_TOKEN
# ACCESS_SECRET
load "#{ENV['HOME']}/jvn.oauth"
begin
flg = 0
slink = nil
lfile = open("jvn.txt",'r')
lfile.each do |link| slink = link.chop end
lfile.close
consumer = OAuth::Consumer.new(
CONSUMER_KEY,
CONSUMER_SECRET,
:site => 'http://api.twitter.com'
)
token = OAuth::AccessToken.new(
consumer,
ACCESS_TOKEN,
ACCESS_SECRET
)
client = OAuthRubytter.new(token)
open('http://jvn.jp/rss/jvn.rdf') do |http|
response = http.read
result = RSS::Parser.parse(response, false)
result.items.each do |item|
title = item.title
link = item.link
if link == slink then break end
if flg == 0 and link != slink then
lfile = open("jvn.txt",'w')
lfile.puts link
lfile.close
flg = 1
end
mess = title + " " + link
client.update(mess)
sleep 60
end
end
rescue
print "RuntimeError: ", $!, "\n";
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment