tweetskim 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,7 +27,7 @@ Options:
27
27
 
28
28
  -a, --show-all Show all tweets (200max), not just unread tweets
29
29
 
30
- -e, --mentions: Show mentions instead of timeline
30
+ -e, --mentions Show mentions instead of timeline
31
31
 
32
32
  -i, --inverse-order Inverse/reverse ordered tweets
33
33
 
@@ -37,7 +37,7 @@ Options:
37
37
 
38
38
  -n, --last-n-tweets N Show the last N tweets in your timeline
39
39
 
40
- -o, --output-mode MODE Output as 'lines', 'column' or 'html'
40
+ -l, --html-output Output tweets as more readable html file
41
41
 
42
42
  -v, --version Current version
43
43
 
@@ -61,12 +61,6 @@ TODO:
61
61
  =====
62
62
 
63
63
 
64
- show status identifier
65
- ----
66
-
67
- option to prefix tweets with their status id and/or direct link (all modes)
68
-
69
-
70
64
  multiple accounts
71
65
  ------
72
66
 
@@ -76,11 +70,6 @@ split out authorization in separate, explicit step: tweetskim authorize USER
76
70
 
77
71
  set tokens per account (if username given)
78
72
 
79
- html output mode
80
- -----
81
-
82
- output single-page html version of tweets, do pretty and readable stuff here
83
-
84
73
 
85
74
  LICENSE:
86
75
  ========
data/bin/tweetskim CHANGED
@@ -24,7 +24,6 @@ def parse_options
24
24
  return options
25
25
  end
26
26
 
27
-
28
27
  def fetch_tweets(options = {})
29
28
  settings = Tweetskim::Settings.new
30
29
  adapter = Tweetskim::TwitterAdapter.new
@@ -53,20 +52,25 @@ def fetch_tweets(options = {})
53
52
  return tweets
54
53
  end
55
54
 
55
+ require 'launchy'
56
+ def show_in_browser(html_body)
57
+ File.open "/tmp/tweets.html", "w" do |filebody|
58
+ filebody.write(html_body)
59
+ end
60
+ Launchy.open("/tmp/tweets.html")
61
+ end
56
62
 
57
- def write_tweets_to_stdout(tweets, options = {})
63
+ def output_tweets(tweets, options = {})
58
64
  formatter = Tweetskim::Formatter.new
59
-
60
- if options[:html_output] # Print lines to stdout
61
- result = formatter.html(tweets, options)
65
+ if options[:html_output]
66
+ show_in_browser(formatter.html(tweets, options))
62
67
  else
63
- result = formatter.lines(tweets, options)
68
+ puts formatter.lines(tweets, options)
64
69
  end
65
-
66
- puts result
67
70
  end
68
71
 
69
72
 
73
+ # Run it
70
74
  options = parse_options
71
75
  tweets = fetch_tweets(options)
72
- write_tweets_to_stdout(tweets, options)
76
+ output_tweets(tweets, options)
@@ -1,3 +1,3 @@
1
1
  module Tweetskim
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/tweetskim.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency "twitter"
24
24
  s.add_runtime_dependency "oauth"
25
25
  s.add_runtime_dependency "OptionParser"
26
+ s.add_runtime_dependency "launchy"
26
27
 
27
28
  s.add_development_dependency "mocha"
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetskim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
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-03-30 00:00:00.000000000Z
12
+ date: 2012-04-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: twitter
16
- requirement: &18714980 !ruby/object:Gem::Requirement
16
+ requirement: &9961660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18714980
24
+ version_requirements: *9961660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth
27
- requirement: &18714560 !ruby/object:Gem::Requirement
27
+ requirement: &9961240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18714560
35
+ version_requirements: *9961240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: OptionParser
38
- requirement: &18714140 !ruby/object:Gem::Requirement
38
+ requirement: &9960820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *18714140
46
+ version_requirements: *9960820
47
+ - !ruby/object:Gem::Dependency
48
+ name: launchy
49
+ requirement: &9960400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *9960400
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: mocha
49
- requirement: &18713720 !ruby/object:Gem::Requirement
60
+ requirement: &9959980 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *18713720
68
+ version_requirements: *9959980
58
69
  description: ! 'Usage: tweetskim [options]'
59
70
  email:
60
71
  - thomas@kjeldahlnilsson.net
@@ -69,7 +80,6 @@ files:
69
80
  - Rakefile
70
81
  - bin/tweetskim
71
82
  - lib/tweetskim.rb
72
- - lib/tweetskim/core.rb
73
83
  - lib/tweetskim/formatter.rb
74
84
  - lib/tweetskim/settings.rb
75
85
  - lib/tweetskim/twitter_adapter.rb
@@ -1,174 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- module Tweetskim
4
- require 'rubygems'
5
- require 'twitter'
6
- require 'oauth'
7
-
8
- class Settings
9
- SETTINGS_TEMPLATE = {:token => nil,
10
- :secret => nil,
11
- :last_read_status_id => "111111"}
12
-
13
- SETTINGS_FILE_PATH = File.expand_path "~/.tweetskim/default-account"
14
-
15
- require "fileutils"
16
-
17
- def initialize
18
- FileUtils.mkdir_p(File.expand_path("~/.tweetskim"))
19
- FileUtils.touch SETTINGS_FILE_PATH
20
- end
21
-
22
- def load
23
- File.open SETTINGS_FILE_PATH, "r" do |filebody|
24
- YAML::load(filebody) || SETTINGS_TEMPLATE
25
- end
26
- end
27
-
28
- def save(settings)
29
- yml_str = YAML::dump(settings)
30
- File.open SETTINGS_FILE_PATH, "w" do |filebody|
31
- filebody.write yml_str
32
- end
33
- end
34
-
35
- def user_credentials_stored?
36
- if File.exists? SETTINGS_FILE_PATH
37
- settings = load
38
- return (settings[:token] && !settings[:token].empty? &&
39
- settings[:secret] && !settings[:secret].empty?)
40
- else
41
- false
42
- end
43
- end
44
-
45
- def save_credentials(token, secret)
46
- settings = load
47
- settings[:token] = token
48
- settings[:secret] = secret
49
- save settings
50
- end
51
-
52
- def load_credentials
53
- settings = load
54
- return settings[:token], settings[:secret]
55
- end
56
-
57
- def load_last_read_status_id
58
- settings = load
59
- return settings[:last_read_status_id]
60
- end
61
-
62
- def save_last_read_status_id(id)
63
- settings = load
64
- settings[:last_read_status_id] = id
65
- save settings
66
- end
67
-
68
- end
69
-
70
-
71
-
72
- class TwitterAdapter
73
- # TODO call for each user in config
74
- # implicit for the user authenticated in client. Different user =
75
- # different client
76
-
77
- def mentions(tweet_count, since_id)
78
- client = authenticated_client
79
- mentions = client.mentions({:count => tweet_count.to_i, :since_id => since_id.to_i})
80
- end
81
-
82
- def timeline(tweet_count, since_id)
83
- client = authenticated_client
84
- timeline = client.home_timeline({:count => tweet_count.to_i, :since_id => since_id.to_i})
85
- end
86
-
87
- CONSUMER_KEY = "3oUZhYLZcaqqQePajIjnBg"
88
- CONSUMER_SECRET = "mAYecEGPwy7BlkibFGHCACtY5x1Mm0YOvczxsll4OY"
89
-
90
- # TODO call for specific user
91
- def authenticated_client
92
- settings = Tweetskim::Settings.new
93
-
94
- if settings.user_credentials_stored?
95
- user_token, user_secret = settings.load_credentials
96
- else
97
- user_token, user_secret = oauth_pin_dance_for_token_and_secret
98
- settings.save_credentials(user_token, user_secret)
99
- end
100
-
101
- Twitter.configure do |config|
102
- config.consumer_key = CONSUMER_KEY
103
- config.consumer_secret = CONSUMER_SECRET
104
- config.oauth_token = user_token
105
- config.oauth_token_secret = user_secret
106
- end
107
-
108
- client = Twitter::Client.new
109
- client.verify_credentials
110
- return client
111
- end
112
-
113
- def oauth_pin_dance_for_token_and_secret
114
- oauth_consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET,
115
- :site => 'http://api.twitter.com',
116
- :request_token_path => '/oauth/request_token',
117
- :access_token_path => '/oauth/access_token',
118
- :authorize_path => '/oauth/authorize')
119
-
120
- request_token = oauth_consumer.get_request_token
121
- rtoken = request_token.token
122
- rsecret = request_token.secret
123
-
124
- puts "You have to set up Twitter authentication the first time you use tweetskim."
125
- puts "Please authenticate by following this URL:"
126
- puts request_token.authorize_url
127
-
128
- puts "What was the PIN that Twitter gave you? "
129
- pin = gets.chomp
130
-
131
- OAuth::RequestToken.new(oauth_consumer, rtoken, rsecret)
132
- access_token = request_token.get_access_token(:oauth_verifier => pin)
133
-
134
- return access_token.token, access_token.secret
135
- end
136
- end
137
-
138
-
139
- class Formatter
140
- def lines(tweets, options = {})
141
- tweet_texts = tweets.reverse.map {|tweet| "--#{tweet.user.name}-- #{text(tweet)}\n"}
142
- lines = tweet_texts.join("")
143
- end
144
-
145
- def column(tweets, options = {})
146
- tweet_texts = tweets.reverse.map {|tweet| "--\\033[1;34m#{tweet.user.name}\\033[0m-- #{text(tweet)}"}
147
- reflowed_tweets = tweet_texts.map {|tweet| `echo "#{tweet}" | fmt -w #{options[:width]}` }
148
- column = reflowed_tweets.join "\n\n"
149
- end
150
-
151
- def html(tweets, options = {})
152
-
153
- end
154
-
155
- def pad(column, width)
156
- padded_lines = []
157
- column.each_line do |line|
158
- chopped_line = line.chop
159
- padded_lines.push `printf "%-#{width}s\n" "#{chopped_line}"`
160
- end
161
- padded_lines.join ""
162
- end
163
-
164
- def text(tweet)
165
- if tweet.retweeted_status
166
- "RT @#{tweet.retweeted_status.user.screen_name}: #{tweet.retweeted_status.text}"
167
- else
168
- tweet.text
169
- end
170
- end
171
- end
172
-
173
-
174
- end