wassrfeed 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ vendor/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wassrfeed.gemspec
4
+ gemspec
@@ -0,0 +1,23 @@
1
+ # wassrfeed - RSS feedの内容をWassrのヒトコトへ流す
2
+
3
+ パラメタに与えたURLからfeedを取得して、その内容をWassrに流します。現在サポートしているfeedはほぼTwitterのみです(ようするにTwitterのつぶやきをWassrに転送するのが目的)。
4
+
5
+ ## How to Install
6
+ gemでインストールできます:
7
+
8
+ % gem install wassrfeed
9
+
10
+ ## How to Use
11
+ TwitterのRSS feedをパラメタに与えて実行します:
12
+
13
+ % wassrfeed https://twitter.com/statuses/user_timeline/EXAMPLE.rss
14
+
15
+ "EXAMPLE"にTwitterのユーザ名を指定することで、そのユーザのtweetを取得できます。
16
+
17
+ 参考→[TwitterのRSSフィードを取得したい場合](http://memorandum.char-aznable.com/web_service/twitter-rss.html)
18
+
19
+ cron等で、2分間隔くらいで回すと良いでしょう。前回の状態を記録しておくので、次の実行では追加分のみを流します。
20
+
21
+ ----
22
+
23
+ Copyright (C) 2009 TADA Tadashi <t@tdtds.jp> / You can redistribute it and/or modify it under GPL.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8; -*-
3
+ #
4
+ # wassrfeed.rb
5
+ #
6
+ # Copyright (C) 2012 TADA Tadashi <t@tdtds.jp>
7
+ # You can redistribute it and/or modify it under GPL.
8
+ #
9
+
10
+ require 'rubygems'
11
+ require 'open-uri'
12
+ require 'rss'
13
+
14
+ require 'pit'
15
+ require 'cgi'
16
+ require 'net/wassr'
17
+ require 'wassrfeed/rcfile'
18
+
19
+
20
+ def resolve_redirect( uri, depth = 1 ) # depth IS NOT SUPPORTED
21
+ uri = URI( uri )
22
+ px_host, px_port = (ENV['http_proxy']||'').scan( %r|^(?:.*?)://(.*?):(\d+)?| ).flatten
23
+ Net::HTTP.Proxy( px_host, px_port ).start( uri.host ) do |h|
24
+ res = h.get( uri.path.empty? ? '/' : uri.path )
25
+ if res.is_a? Net::HTTPRedirection
26
+ res['location']
27
+ else
28
+ uri.to_s
29
+ end
30
+ end
31
+ end
32
+
33
+ conf = WassrFeed::RCfile::load
34
+
35
+ while uri = ARGV.shift
36
+ # reading feed
37
+ begin
38
+ feed = RSS::Parser::parse( open( uri, &:read ), false, false )
39
+ rescue OpenURI::HTTPError, Errno::ECONNRESET
40
+ $stderr.puts "error on reading feed: #$!"
41
+ exit( 1 )
42
+ end
43
+
44
+ # reading latest status
45
+ latest = conf[:latest][feed.channel.link] || Time::now
46
+
47
+ # making status list
48
+ status = []
49
+ feed.channel.items.each do |item|
50
+ status << item if item.pubDate > latest
51
+ end
52
+
53
+ login = Pit::get( 'wassr', :require => {
54
+ 'user' => 'your ID of Wassr.',
55
+ 'pass' => 'your Password of Wassr.',
56
+ } )
57
+ wassr = Net::Wassr.new( login['user'], login['pass'] )
58
+ status.sort_by{|i| i.pubDate}.each do |item|
59
+ # trimming ID when twitter
60
+ if %r|^http://twitter\.com/| =~ item.link then
61
+ item.description.sub!( /^[^:]*: /, '' )
62
+ next if item.description.include?( '@' )
63
+ end
64
+
65
+ text = CGI::unescapeHTML( CGI::unescapeHTML( item.description ) )
66
+ text.gsub!( %r|(http://t.co/\w+)| ) do |re|
67
+ resolve_redirect re
68
+ end
69
+
70
+ if text.sub!( /^#([a-zA-Z0-9]+)\s/, '' )
71
+ wassr.post_channel( $1, text )
72
+ else
73
+ wassr.post_status( text )
74
+ end
75
+ conf[:latest][feed.channel.link] = item.pubDate
76
+ WassrFeed::RCfile.save( conf )
77
+ sleep( 1 )
78
+ end
79
+ WassrFeed::RCfile.save( conf )
80
+ end
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8; -*-
2
+ #
3
+ # Net::Wassr : An implementation of of Wassr API (post only)
4
+ #
5
+ # Copyright (C) 2012 TADA Tadashi <t@tdtds.jp>
6
+ # You can redistribute it and/or modify it under GPL.
7
+ #
8
+ require 'net/http'
9
+ require 'timeout'
10
+ require 'cgi'
11
+
12
+ module Net #:nodoc:
13
+
14
+ class Wassr
15
+ def initialize( user, pass )
16
+ @login = { user: user, pass: pass }
17
+ end
18
+
19
+ def post_status( status )
20
+ params = "source=wassrfeed&status=#{CGI::escape status}"
21
+ post( '/statuses/update.json', params )
22
+ end
23
+
24
+ def post_channel( channel, status )
25
+ params = "body=#{CGI::escape status}"
26
+ post( "/channel_message/update.json?name_en=#{channel}", params )
27
+ end
28
+
29
+ :private
30
+ def post( end_point, params )
31
+ px_host, px_port = (ENV['http_proxy']||'').scan( %r|^(?:.*?)://(.*?):(\d+)?| ).flatten
32
+ timeout( 10 ) do
33
+ Net::HTTP.version_1_2
34
+ req = Net::HTTP::Post.new( end_point )
35
+ req.basic_auth( @login[:user], @login[:pass] )
36
+ req.body = params
37
+ Net::HTTP::Proxy( px_host, px_port ).start( 'api.wassr.jp', 80 ) do |http|
38
+ res = http.request( req )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ require "wassrfeed/version"
2
+
3
+ module Wassrfeed
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8; -*-
2
+ #
3
+ # WassrFeed::RCfile
4
+ #
5
+ # Copyright (C) 2012 TADA Tadashi <t@tdtds.jp>
6
+ # You can redistribute it and/or modify it under GPL.
7
+ #
8
+
9
+ module WassrFeed
10
+ module RCfile
11
+ RCFILE = "#{ENV['HOME']}/.wassrfeedrc"
12
+
13
+ module_function
14
+ def load
15
+ begin
16
+ YAML::load( open( RCFILE, &:read ) )
17
+ rescue Errno::ENOENT
18
+ {
19
+ :latest => {
20
+ }
21
+ }
22
+ end
23
+ end
24
+
25
+ def save( conf )
26
+ open( RCFILE, 'w' ) {|f| f.write conf.to_yaml }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module WassrFeed
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wassrfeed/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wassrfeed"
7
+ s.version = WassrFeed::VERSION
8
+ s.authors = ["TADA Tadashi"]
9
+ s.email = ["t@tdtds.jp"]
10
+ s.homepage = "http://github.com/tdtds/wassrfeed"
11
+ s.summary = %q{Posting feed items to wassr}
12
+ s.description = %q{A command to post from RSS feed to Wassr.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ s.add_runtime_dependency "pit"
22
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wassrfeed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TADA Tadashi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pit
16
+ requirement: &79678120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *79678120
25
+ description: A command to post from RSS feed to Wassr.
26
+ email:
27
+ - t@tdtds.jp
28
+ executables:
29
+ - wassrfeed
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - README.md
36
+ - Rakefile
37
+ - bin/wassrfeed
38
+ - lib/net/wassr.rb
39
+ - lib/wassrfeed.rb
40
+ - lib/wassrfeed/rcfile.rb
41
+ - lib/wassrfeed/version.rb
42
+ - wassrfeed.gemspec
43
+ homepage: http://github.com/tdtds/wassrfeed
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.11
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Posting feed items to wassr
67
+ test_files: []