jugyo-termtter 0.4.5 → 0.5.0

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.
data/Manifest.txt CHANGED
@@ -10,6 +10,8 @@ lib/termtter/notify-send.rb
10
10
  lib/termtter/standard_commands.rb
11
11
  lib/termtter/uri-open.rb
12
12
  lib/termtter/growl.rb
13
+ lib/termtter/say.rb
14
+ lib/termtter/english.rb
13
15
  test/test_termtter.rb
14
16
  test/friends_timeline.json
15
17
  test/search.json
@@ -0,0 +1,51 @@
1
+ Termtter::Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb
2
+
3
+ # english? :: String -> Boolean
4
+ def english?(message)
5
+ /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
6
+ end
7
+
8
+ # FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
9
+ Termtter::Client.add_hook do |statuses, event|
10
+ colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
11
+
12
+ case event
13
+ when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
14
+ unless statuses.empty?
15
+ if event == :update_friends_timeline then statuses = statuses.reverse end
16
+ statuses.each do |s|
17
+ text = s.text.gsub("\n", '')
18
+ next unless english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
19
+ color_num = colors[s.user_screen_name.hash % colors.size]
20
+ status = "#{s.user_screen_name}: #{text}"
21
+ if s.in_reply_to_status_id
22
+ status += " (reply to #{s.in_reply_to_status_id})"
23
+ end
24
+
25
+ case event
26
+ when :update_friends_timeline, :list_friends_timeline
27
+ time_format = '%H:%M:%S'
28
+ else
29
+ time_format = '%m-%d %H:%d'
30
+ end
31
+ time_str = "(#{s.created_at.strftime(time_format)})"
32
+
33
+ puts "#{color(time_str, 90)} #{color(status, color_num)}"
34
+ end
35
+ end
36
+ when :search
37
+ statuses.each do |s|
38
+ text = s.text.gsub("\n", '')
39
+ color_num = colors[s.user_screen_name.hash % colors.size]
40
+ status = "#{s.user_screen_name}: #{text}"
41
+ time_str = "(#{s.created_at.strftime('%m-%d %H:%d')})"
42
+
43
+ puts "#{color(time_str, 90)} #{color(status, color_num)}"
44
+ end
45
+ end
46
+ end
47
+
48
+ # USAGE:
49
+ # Write the line on the *first line* of your ~/.termtter
50
+ # require 'termtter/english'
51
+ # (english.rb will destroy plugins which were required before)
@@ -0,0 +1,22 @@
1
+ raise 'say.rb runs only in OSX Leopard' if /darwin9/ !~ RUBY_PLATFORM
2
+
3
+ # say :: String -> String -> IO ()
4
+ def say(who, what)
5
+ voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
6
+ voice = voices[who.hash % voices.size]
7
+ system 'say', '-v', voice, what
8
+ end
9
+
10
+ class Termtter::Client
11
+ add_hook do |statuses, event, t|
12
+ if !statuses.empty? && event == :update_friends_timeline
13
+ statuses.reverse.each do |s|
14
+ text_without_uri = s.text.gsub(%r|https?://[^\s]+|, 'U.R.I.')
15
+ say s.user_screen_name, text_without_uri
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ # KNOWN BUG:
22
+ # * exit or <C-c> doen't work quickly.
data/lib/termtter.rb CHANGED
@@ -10,7 +10,7 @@ $:.unshift(File.dirname(__FILE__)) unless
10
10
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
11
11
 
12
12
  module Termtter
13
- VERSION = '0.4.5'
13
+ VERSION = '0.5.0'
14
14
 
15
15
  class Twitter
16
16
 
@@ -33,7 +33,7 @@ module Termtter
33
33
 
34
34
  def get_friends_timeline(since_id = nil)
35
35
  uri = "http://twitter.com/statuses/friends_timeline.json"
36
- uri += "?since_id=#{since_id}" if since_id
36
+ uri << "?since_id=#{since_id}" if since_id
37
37
  return get_timeline(uri)
38
38
  end
39
39
 
@@ -43,12 +43,12 @@ module Termtter
43
43
 
44
44
  def search(query)
45
45
  results = JSON.parse(open('http://search.twitter.com/search.json?q=' + CGI.escape(query)).read)['results']
46
- return results.inject([]) do |statuses, s|
46
+ return results.map do |s|
47
47
  status = Status.new
48
48
  status.text = s['text']
49
49
  status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
50
50
  status.user_screen_name = s['from_user']
51
- statuses << status
51
+ status
52
52
  end
53
53
  end
54
54
 
@@ -67,17 +67,17 @@ module Termtter
67
67
  else
68
68
  [data]
69
69
  end
70
- return data.inject([]) do |statuses, s|
70
+ return data.map do |s|
71
71
  u = s["user"]
72
72
  status = Status.new
73
73
  status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
74
74
  %w(id text truncated in_reply_to_status_id in_reply_to_user_id).each do |key|
75
- status.send("#{key}=".to_sym, s[key])
75
+ status.__send__("#{key}=".to_sym, s[key])
76
76
  end
77
77
  %w(id name screen_name url profile_image_url).each do |key|
78
- status.send("user_#{key}=".to_sym, u[key])
78
+ status.__send__("user_#{key}=".to_sym, u[key])
79
79
  end
80
- statuses << status
80
+ status
81
81
  end
82
82
  end
83
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-termtter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-04 00:00:00 -08:00
12
+ date: 2009-01-05 00:00:00 -08:00
13
13
  default_executable: termtter
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,8 @@ files:
64
64
  - lib/termtter/standard_commands.rb
65
65
  - lib/termtter/uri-open.rb
66
66
  - lib/termtter/growl.rb
67
+ - lib/termtter/say.rb
68
+ - lib/termtter/english.rb
67
69
  - test/test_termtter.rb
68
70
  - test/friends_timeline.json
69
71
  - test/search.json