twail 0.1.8 → 0.1.9

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 +31 -15
  2. data/twail.gemspec +1 -1
  3. metadata +2 -2
@@ -9,8 +9,8 @@ require 'optparse'
9
9
 
10
10
  # TODO DRY this code up!
11
11
 
12
- TIMELINES = %w( public home friends user)
13
- SPECIAL = %w(mentions retweeted_by_me retweeted_to_me retweets_of_me)
12
+ TIMELINES = %w( home user mentions)
13
+ SPECIAL = %w(retweets_of_me)
14
14
 
15
15
  if %w(-h --help).include?(ARGV.first)
16
16
  puts <<END
@@ -30,20 +30,16 @@ Usage: twail [timeline]
30
30
 
31
31
  [timeline] can be any of these:
32
32
 
33
- public
34
33
  home
35
- friends
36
34
  user
37
35
  mentions
38
- retweeted_by_me
39
- retweeted_to_me
40
36
  retweets_of_me
41
37
 
42
38
  "home" is the default.
43
39
 
44
40
  You can use these abbreviations:
45
41
 
46
- p h f u m by to of
42
+ h u m r
47
43
 
48
44
  twail will perform a Twitter search if you use
49
45
 
@@ -99,18 +95,38 @@ if ARGV.first =~ /^s/ # search
99
95
 
100
96
  total_width = `tput cols`.to_i
101
97
  text_width = (total_width - 44)
98
+ network = true
102
99
 
103
100
  while query
104
101
  begin
105
- url = "http://search.twitter.com/search.json#{query}"
106
- json = `curl -s '#{url}'`
107
- res = JSON.parse(json)
108
- res['results'].each do |x|
102
+ url = "/1.1/search/tweets.json#{query}"
103
+ raw = begin
104
+ Twurl::CLI.output = StringIO.new
105
+ Twurl::CLI.run([url])
106
+ if network == false
107
+ network = true
108
+ $stderr.print(" The network is back up!\n")
109
+ end
110
+ Twurl::CLI.output.read
111
+ Twurl::CLI.output.rewind
112
+ Twurl::CLI.output.read
113
+ rescue SocketError
114
+ if network
115
+ $stderr.print("The network seems to be down.")
116
+ else
117
+ $stderr.print('.')
118
+ end
119
+ network = false
120
+ sleep 20
121
+ next
122
+ end
123
+ res = JSON.parse(raw)
124
+ res['statuses'].each do |x|
109
125
  time = Time.parse(x['created_at']).localtime
110
126
  text = x['text'].gsub(/\n/, ' ')
111
127
  text += " #{x['id']}" if options[:tweet_ids]
112
128
  textlines = options[:wrap] ? text.wrap(text_width).split(/\n/) : [text]
113
- puts "%s | %s | %s" % [time.to_s.gsub(/\s\S+$/,''), x['from_user'].rjust(18), textlines.shift]
129
+ puts "%s | %s | %s" % [time.to_s.gsub(/\s\S+$/,''), x['user']['screen_name'].rjust(18), textlines.shift]
114
130
  textlines.each do |line|
115
131
  puts("%s | %s" % [''.rjust(40), line])
116
132
  end
@@ -141,11 +157,11 @@ puts "Logging #{timeline} timeline at #{Time.now}"
141
157
  url = case timeline
142
158
  when 'retweets_of_me'
143
159
  # This doesn't seem to do anything different; figure out later
144
- "/1/statuses/#{timeline}.json?include_entities=true"
160
+ "/1.1/statuses/#{timeline}.json?include_entities=true"
145
161
  when *SPECIAL
146
- "/1/statuses/#{timeline}.json"
162
+ "/1.1/statuses/#{timeline}.json"
147
163
  else
148
- "/1/statuses/#{timeline}_timeline.json"
164
+ "/1.1/statuses/#{timeline}_timeline.json"
149
165
  end
150
166
 
151
167
 
@@ -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.8'
5
+ s.version = '0.1.9'
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.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-17 00:00:00.000000000 Z
12
+ date: 2013-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twurl