caw 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in caw.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/caw ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/caw'
4
+
5
+ Caw::CLI.run!
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "caw/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "caw"
7
+ s.version = Caw::VERSION
8
+ s.authors = ["Philippe Creux"]
9
+ s.email = ["pcreux@gmail.com"]
10
+ s.homepage = "https://github.com/pcreux/caw"
11
+ s.summary = %q{Read your Twitter timeline aloud}
12
+ s.description = %q{Caw reads aloud your Twitter timeline.}
13
+
14
+ s.default_executable = %q{caw}
15
+
16
+ s.add_dependency 'twitter', '>=1.5.0'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,118 @@
1
+ $:.push File.expand_path("..", __FILE__)
2
+
3
+ require "thread"
4
+
5
+ require "rubygems"
6
+ require "twitter"
7
+
8
+ require "caw/cli"
9
+ require "caw/version"
10
+
11
+
12
+ module Caw
13
+ class Maestro
14
+ def play(search)
15
+ tweets = TwitterStream.new(search)
16
+ until 1 + 1 == 3
17
+ p tweet = tweets.pop!
18
+ tweet.text = enhance_text(tweet.text)
19
+ Mimic.say(tweet)
20
+ end
21
+ end
22
+
23
+ def enhance_text(text)
24
+ puts text
25
+ text.gsub!(/http:\S+/, '')
26
+ text.gsub!(/RT @/, 'Retweet ')
27
+ text.gsub!(/@/, 'At ')
28
+ puts text
29
+
30
+ text
31
+ end
32
+ end # class Maestro
33
+
34
+
35
+ class TwitterStream
36
+ def initialize(search_term)
37
+ @search_term = search_term
38
+ @queue = Queue.new
39
+ start!
40
+ end
41
+
42
+ def pop!
43
+ @queue.pop
44
+ end
45
+
46
+
47
+ protected
48
+
49
+ def start!
50
+ Thread.new do
51
+ while run?
52
+ enqueue_new_tweets
53
+ sleep 10
54
+ end
55
+ end
56
+ end
57
+
58
+ def run?
59
+ true
60
+ end
61
+
62
+ def enqueue_new_tweets
63
+ new_tweets.each do |t|
64
+ puts "Enqueuing: #{t.text}"
65
+ @queue << t
66
+ end
67
+ end
68
+
69
+ # Return new tweets last comes first
70
+ def new_tweets
71
+ q = search.q(@search_term)
72
+ q = q.since_id(@last_id) if @last_id
73
+ tweets = q.fetch
74
+ tweets.reverse!
75
+
76
+ @last_id = tweets.last.id_str if tweets.last
77
+
78
+ tweets
79
+ end
80
+
81
+ def search
82
+ @search ||= Twitter::Search.new
83
+ end
84
+ end # class TwitterStream
85
+
86
+ class Mimic
87
+ def self.say(tweet)
88
+ mimic.announce(tweet)
89
+ mimic.mimic(tweet)
90
+ end
91
+
92
+ def self.mimic
93
+ @mimic ||= new
94
+ end
95
+
96
+ VOICES = %w(Bruce Fred Junior Ralph)
97
+
98
+ def announce(tweet)
99
+ say(tweet.from_user)
100
+ end
101
+
102
+ def mimic(tweet)
103
+ say(tweet.text, voice_for(tweet.from_user))
104
+ end
105
+
106
+ protected
107
+
108
+ def say(txt, voice = 'Alex')
109
+ txt ||= ''
110
+ puts "Saying: #{txt}"
111
+ system("say -v '#{voice}' '#{txt.gsub("'", "")}'")
112
+ end
113
+
114
+ def voice_for(name)
115
+ VOICES.at(name[1] % VOICES.length)
116
+ end
117
+ end # class Mimic
118
+ end
@@ -0,0 +1,15 @@
1
+ module Caw
2
+ class CLI
3
+ def self.run!
4
+ if ARGV[0]
5
+ Maestro.new.play(ARGV[0])
6
+ else
7
+ puts <<-EOF
8
+ Usage:
9
+ caw SEARCH
10
+
11
+ EOF
12
+ end
13
+ end
14
+ end # class CLI
15
+ end # module Caw
@@ -0,0 +1,3 @@
1
+ module Caw
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caw
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Philippe Creux
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-08 00:00:00 -07:00
19
+ default_executable: caw
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: twitter
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 1
32
+ - 5
33
+ - 0
34
+ version: 1.5.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Caw reads aloud your Twitter timeline.
38
+ email:
39
+ - pcreux@gmail.com
40
+ executables:
41
+ - caw
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Rakefile
50
+ - bin/caw
51
+ - caw.gemspec
52
+ - lib/caw.rb
53
+ - lib/caw/cli.rb
54
+ - lib/caw/version.rb
55
+ has_rdoc: true
56
+ homepage: https://github.com/pcreux/caw
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Read your Twitter timeline aloud
89
+ test_files: []
90
+