tweetskim 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -32
- data/bin/tweetskim +54 -11
- data/lib/tweetskim/core.rb +8 -15
- data/lib/tweetskim/version.rb +1 -1
- data/test/test_tweetskim.rb +17 -24
- data/tweetskim.gemspec +2 -1
- metadata +18 -7
data/README.md
CHANGED
@@ -3,73 +3,82 @@ DESCRIPTION:
|
|
3
3
|
===========
|
4
4
|
|
5
5
|
A stripped down, command line-centered way to read tweets
|
6
|
-
efficiently.
|
7
|
-
|
6
|
+
efficiently.
|
7
|
+
|
8
|
+
Combine with unix tools and pipelines to read tweets
|
9
|
+
however *you* want.
|
8
10
|
|
9
11
|
|
10
12
|
USAGE:
|
11
13
|
======
|
12
14
|
|
13
|
-
`tweetskim`
|
15
|
+
`tweetskim [options]`
|
14
16
|
|
15
|
-
Prints
|
16
|
-
|
17
|
-
pipe to `less` to page output, concat it to file (`tweetskim >
|
18
|
-
tweets.txt`), and so on.
|
17
|
+
Prints the tweet timeline to stdout, either as plain lines, more readable column
|
18
|
+
or extra-readable single html page.
|
19
19
|
|
20
|
+
Use it like any other command line tool: page the output (`less
|
21
|
+
tweetskim`), concat it to file (`tweetskim > tweets.txt`), search for specific stuff (`tweetskim | grep conference`) and so on.
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
options
|
24
|
+
----
|
23
25
|
|
24
|
-
|
26
|
+
-a, --show-all
|
25
27
|
|
28
|
+
-e, --mentions
|
26
29
|
|
27
|
-
|
28
|
-
========
|
30
|
+
-i, --inverse-order
|
29
31
|
|
30
|
-
|
32
|
+
-h, --help
|
31
33
|
|
32
|
-
|
33
|
-
the first time you run it.)
|
34
|
+
-m, --mark-all-read
|
34
35
|
|
36
|
+
-n, --last-n-tweets N
|
35
37
|
|
36
|
-
|
37
|
-
=====
|
38
|
+
-o, --output-mode lines|column|html
|
38
39
|
|
40
|
+
-u, --user
|
39
41
|
|
40
|
-
|
41
|
-
----
|
42
|
+
-v, --version
|
42
43
|
|
43
|
-
add usage text, handle options
|
44
44
|
|
45
|
-
|
45
|
+
PREREQUISITES:
|
46
|
+
==============
|
46
47
|
|
47
|
-
|
48
|
+
You must have some version of Ruby and RubyGems installed first. That's it.
|
48
49
|
|
49
|
-
-l=N, --last-n-tweets=N
|
50
50
|
|
51
|
-
|
51
|
+
INSTALL:
|
52
|
+
========
|
52
53
|
|
53
|
-
|
54
|
+
`gem install tweetskim`
|
54
55
|
|
55
|
-
|
56
|
+
The program will help you set up OAuth/pincode authentication with Twitter
|
57
|
+
the first time you run it.
|
56
58
|
|
57
|
-
-hm, --hide-mentions
|
58
59
|
|
59
|
-
|
60
|
+
TODO:
|
61
|
+
=====
|
60
62
|
|
61
|
-
-x=USER, --exclude=USER
|
62
63
|
|
63
|
-
|
64
|
+
options
|
65
|
+
----
|
64
66
|
|
67
|
+
Finish options enumerated above
|
65
68
|
|
66
69
|
multiple accounts
|
67
70
|
------
|
71
|
+
|
68
72
|
handle explicit, different username options
|
69
73
|
|
70
|
-
split out authorization in separate, explicit step
|
74
|
+
split out authorization in separate, explicit step: tweetskim authorize USER
|
75
|
+
|
76
|
+
set tokens per account (if username given)
|
77
|
+
|
78
|
+
html output mode
|
79
|
+
-----
|
71
80
|
|
72
|
-
|
81
|
+
output single-page html version of tweets, do pretty and readable stuff here
|
73
82
|
|
74
83
|
|
75
84
|
LICENSE:
|
data/bin/tweetskim
CHANGED
@@ -1,21 +1,64 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "tweetskim"
|
4
|
+
require "optparse"
|
4
5
|
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def parse_options
|
8
|
+
options = {}
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
OptionParser.new do |o|
|
11
|
+
#TODO o.on("-a", "--show-all", "Show all tweets, not just unread ones (max 300)") { |b| options[:show_all] = b }
|
12
|
+
o.on("-e", "--mentions", "Show mentions instead of timeline") { |b| options[:mentions] = b }
|
13
|
+
o.on("-i", "--inverse-order", "Inverse/reverse ordered tweets") { |b| options[:inverse_order] = b }
|
14
|
+
o.on("-h", "--help", "Help page") { puts o; exit }
|
15
|
+
#TODO o.on("-m", "--mark-all-read", "Mark everything up to now as read") { |b| options[:mark_all_read] = b }
|
16
|
+
o.on("-n N", "--last-n-tweets N", "Show only the last N tweets") { |n| options[:last_n_tweets] = n }
|
17
|
+
o.on("-o MODE", "--output-mode MODE", "Output as 'lines', 'column' or 'html'") { |mode| options[:output_mode] = mode }
|
18
|
+
#TODO o.on("-u USER", "--user USER", "Which twitter user I am. Example: tweetskim -u thomanil") { |u| options[:user] = u }
|
19
|
+
o.on("-v", "--version", "Spit out version") { |b| puts Tweetskim::VERSION; exit }
|
11
20
|
|
12
|
-
|
13
|
-
|
21
|
+
o.parse!
|
22
|
+
end
|
14
23
|
|
15
|
-
|
16
|
-
|
24
|
+
return options
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
27
|
+
def fetch_tweets(options = {})
|
28
|
+
adapter = Tweetskim::TwitterAdapter.new
|
20
29
|
|
21
|
-
|
30
|
+
if options[:mentions]
|
31
|
+
tweets = adapter.mentions(:count => options[:last_n_tweets] || 300)
|
32
|
+
else
|
33
|
+
tweets = adapter.timeline(:count => options[:last_n_tweets] || 300)
|
34
|
+
end
|
35
|
+
|
36
|
+
if options[:inverse_order]
|
37
|
+
tweets = tweets.reverse
|
38
|
+
end
|
39
|
+
|
40
|
+
return tweets
|
41
|
+
end
|
42
|
+
|
43
|
+
def write_tweets_to_stdout(tweets, options = {})
|
44
|
+
formatter = Tweetskim::Formatter.new
|
45
|
+
output_mode = options[:output_mode]
|
46
|
+
|
47
|
+
if !output_mode || output_mode == "lines"
|
48
|
+
result = formatter.lines(tweets, options)
|
49
|
+
elsif output_mode == "column"
|
50
|
+
result = formatter.column(tweets, {:width => 40})
|
51
|
+
elsif output_mode == "html"
|
52
|
+
puts "Html mode not done yet."; exit
|
53
|
+
else
|
54
|
+
puts "Invalid output mode."
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
|
58
|
+
puts result
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
options = parse_options
|
63
|
+
tweets = fetch_tweets(options)
|
64
|
+
write_tweets_to_stdout(tweets, options)
|
data/lib/tweetskim/core.rb
CHANGED
@@ -7,7 +7,12 @@ module Tweetskim
|
|
7
7
|
|
8
8
|
|
9
9
|
class Formatter
|
10
|
-
|
10
|
+
|
11
|
+
def lines(tweets, options = {})
|
12
|
+
tweet_texts = tweets.reverse.map {|tweet| "--#{tweet.user.name}-- #{tweet.text}\n"}
|
13
|
+
lines = tweet_texts.join("")
|
14
|
+
end
|
15
|
+
|
11
16
|
def column(tweets, options = {})
|
12
17
|
tweet_texts = tweets.reverse.map {|tweet| "--#{tweet.user.name}-- #{tweet.text}"}
|
13
18
|
reflowed_tweets = tweet_texts.map {|tweet| `echo "#{tweet}" | fmt -w #{options[:width]}` }
|
@@ -22,20 +27,7 @@ module Tweetskim
|
|
22
27
|
end
|
23
28
|
padded_lines.join ""
|
24
29
|
end
|
25
|
-
|
26
|
-
def pasted_columns(columns)
|
27
|
-
col_tmp_files = []
|
28
|
-
|
29
|
-
columns.each_with_index do |col, i|
|
30
|
-
filepath = "/tmp/tweetskim-col#{i}.txt"
|
31
|
-
`rm #{filepath}; echo "#{col}" > #{filepath}`
|
32
|
-
col_tmp_files.push filepath
|
33
|
-
end
|
34
|
-
|
35
|
-
col_tmp_files = col_tmp_files.join " "
|
36
|
-
`paste #{col_tmp_files}`.chomp "\t\n"
|
37
|
-
end
|
38
|
-
|
30
|
+
|
39
31
|
end
|
40
32
|
|
41
33
|
|
@@ -44,6 +36,7 @@ module Tweetskim
|
|
44
36
|
# TODO call for each user in config
|
45
37
|
# implicit for the user authenticated in client. Different user =
|
46
38
|
# different client
|
39
|
+
|
47
40
|
def mentions(options = {})
|
48
41
|
client = authenticated_client #
|
49
42
|
mentions = client.mentions(options)
|
data/lib/tweetskim/version.rb
CHANGED
data/test/test_tweetskim.rb
CHANGED
@@ -18,7 +18,7 @@ class TestTweetskim < Test::Unit::TestCase
|
|
18
18
|
def test_column_creation
|
19
19
|
tweets = [t("Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."), t("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "), t("Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")]
|
20
20
|
|
21
|
-
expected = <<
|
21
|
+
expected = <<COLUMN
|
22
22
|
--Mock User-- Excepteur sint occaecat
|
23
23
|
cupidatat non proident, sunt in culpa
|
24
24
|
qui officia deserunt mollit anim id
|
@@ -34,13 +34,28 @@ cillum dolore eu fugiat nulla pariatur.
|
|
34
34
|
quis nostrud exercitation ullamco
|
35
35
|
laboris nisi ut aliquip ex ea commodo
|
36
36
|
consequat.
|
37
|
-
|
37
|
+
COLUMN
|
38
38
|
|
39
39
|
actual = @f.column(tweets, {:width => 40})
|
40
40
|
|
41
41
|
assert_equal expected, actual
|
42
42
|
end
|
43
43
|
|
44
|
+
def test_line_creation
|
45
|
+
tweets = [t("Ut enimad minim veniam, quis nostrud."), t("Duis aute irure dolor in reprehenderit"), t("Excepteur sint occaecat cupidatat non proident")]
|
46
|
+
|
47
|
+
expected = <<LINES
|
48
|
+
--Mock User-- Excepteur sint occaecat cupidatat non proident
|
49
|
+
--Mock User-- Duis aute irure dolor in reprehenderit
|
50
|
+
--Mock User-- Ut enimad minim veniam, quis nostrud.
|
51
|
+
LINES
|
52
|
+
|
53
|
+
actual = @f.lines(tweets);
|
54
|
+
|
55
|
+
assert_equal expected, actual
|
56
|
+
end
|
57
|
+
|
58
|
+
|
44
59
|
def test_whitespace_padding
|
45
60
|
|
46
61
|
col = <<COL
|
@@ -66,27 +81,5 @@ COL
|
|
66
81
|
assert_equal expected, @f.pad(col, 6)
|
67
82
|
end
|
68
83
|
|
69
|
-
|
70
|
-
def test_column_pasting
|
71
|
-
first_col = <<COL
|
72
|
-
aaa
|
73
|
-
aaa
|
74
|
-
aaa
|
75
|
-
COL
|
76
|
-
second_col = <<COL
|
77
|
-
bbb
|
78
|
-
bbb
|
79
|
-
bbb
|
80
|
-
COL
|
81
|
-
|
82
|
-
expected = <<COL
|
83
|
-
aaa\tbbb
|
84
|
-
aaa\tbbb
|
85
|
-
aaa\tbbb
|
86
|
-
COL
|
87
|
-
|
88
|
-
assert_equal expected, @f.pasted_columns([first_col, second_col])
|
89
|
-
end
|
90
|
-
|
91
84
|
end
|
92
85
|
|
data/tweetskim.gemspec
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-03 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: twitter
|
16
|
-
requirement: &
|
16
|
+
requirement: &18929420 !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: *
|
24
|
+
version_requirements: *18929420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: oauth
|
27
|
-
requirement: &
|
27
|
+
requirement: &18929000 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18929000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: OptionParser
|
38
|
+
requirement: &18928580 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *18928580
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: mocha
|
38
|
-
requirement: &
|
49
|
+
requirement: &18928160 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *18928160
|
47
58
|
description: ! 'Usage: tweetskim [username]'
|
48
59
|
email:
|
49
60
|
- thomas@kjeldahlnilsson.net
|