twail 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/twail.rb +23 -2
  2. data/twail.gemspec +1 -1
  3. metadata +4 -4
data/lib/twail.rb CHANGED
@@ -4,6 +4,10 @@ require 'json'
4
4
  require 'yaml'
5
5
  require 'twurl'
6
6
  require 'time'
7
+ require 'optparse'
8
+
9
+
10
+ # TODO DRY this code up!
7
11
 
8
12
  TIMELINES = %w( public home friends user)
9
13
  SPECIAL = %w(mentions retweeted_by_me retweeted_to_me retweets_of_me)
@@ -49,6 +53,14 @@ To stop returning search results after n pages, use
49
53
 
50
54
  twail s [n] [search args]
51
55
 
56
+ To include tweet ids, use the -i flag:
57
+
58
+ twail -i s [n] [search args]
59
+
60
+ To automatically wrap long text, use the -w flag:
61
+
62
+ twail -w m
63
+
52
64
  For more help, see the README at
53
65
 
54
66
  https://github.com/danchoi/twail
@@ -63,6 +75,13 @@ class String
63
75
  end
64
76
  end
65
77
 
78
+ options = {}
79
+ OptionParser.new {|opts|
80
+ opts.on("-w", "--wrap", "Wrap long text") {|x| options[:wrap] = x }
81
+ opts.on("-i", "--include-ids", "Include tweet ids") {|x| options[:tweet_ids] = x }
82
+ }.parse!
83
+
84
+ puts options.inspect
66
85
 
67
86
  # search is different
68
87
  if ARGV.first =~ /^s/ # search
@@ -85,7 +104,8 @@ if ARGV.first =~ /^s/ # search
85
104
  res['results'].each do |x|
86
105
  time = Time.parse(x['created_at']).localtime
87
106
  text = x['text'].gsub(/\n/, ' ')
88
- textlines = text.wrap(text_width).split(/\n/)
107
+ text += " #{x['id']}" if options[:tweet_ids]
108
+ textlines = options[:wrap] ? text.wrap(text_width).split(/\n/) : [text]
89
109
  puts "%s | %s | %s" % [time.to_s.gsub(/\s\S+$/,''), x['from_user'].rjust(18), textlines.shift]
90
110
  textlines.each do |line|
91
111
  puts("%s | %s" % [''.rjust(40), line])
@@ -158,11 +178,12 @@ loop do
158
178
  next if seen.include?(x['id'])
159
179
  seen << x['id']
160
180
  text = x['text'].gsub(/\n/, ' ')
181
+ text += " #{x['id']}" if options[:tweet_ids]
161
182
  user_width = 18
162
183
  from = x['user']['screen_name'][0,user_width]
163
184
  total_width = `tput cols`.to_i
164
185
  text_width = (total_width - user_width) - 3
165
- textlines = text.wrap(text_width).split(/\n/)
186
+ textlines = options[:wrap] ? text.wrap(text_width).split(/\n/) : [text]
166
187
 
167
188
  puts("%s| %s" % [from.rjust(user_width), textlines.shift])
168
189
  textlines.each do |line|
data/twail.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "twail"
5
- s.version = '0.1.3'
5
+ s.version = '0.1.4'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.required_ruby_version = '>= 1.9.0'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000Z
12
+ date: 2012-01-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twurl
16
- requirement: &70140390071860 !ruby/object:Gem::Requirement
16
+ requirement: &70216751766600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.6.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70140390071860
24
+ version_requirements: *70216751766600
25
25
  description: tail your Twitter timelines, or search Twitter
26
26
  email:
27
27
  - dhchoi@gmail.com