stars 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +44 -23
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/stars/client.rb +37 -3
- data/lib/stars/favstar.rb +12 -8
- data/lib/stars/formatter.rb +4 -4
- data/stars.gemspec +5 -2
- data/test/test_client.rb +6 -2
- data/test/test_favstar.rb +3 -7
- data/test/test_formatter.rb +3 -3
- metadata +16 -4
data/README.markdown
CHANGED
@@ -11,28 +11,32 @@ So anyway, I spend a lot of time on the command line, and switching over to the
|
|
11
11
|
|
12
12
|
Install with `gem install stars`, then do a quick `stars`, fill in your Twitter username, and let it do its sultry magic. This is me lately:
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
|
19
|
-
| *
|
20
|
-
| *
|
21
|
-
| *
|
22
|
-
| * |
|
23
|
-
| *
|
24
|
-
| * *
|
25
|
-
|
|
26
|
-
| *
|
27
|
-
| *
|
28
|
-
|
|
29
|
-
| * * *
|
30
|
-
|
|
31
|
-
| *
|
32
|
-
| * * *
|
33
|
-
| * |
|
34
|
-
| *
|
35
|
-
|
14
|
+
★ by @holman
|
15
|
+
+----+-----------+--------------+--------------------------------------------------------+
|
16
|
+
| # | Stars | Time | Your Funnies |
|
17
|
+
+----+-----------+--------------+--------------------------------------------------------+
|
18
|
+
| 1 | * | 12 hours ago | Today's GitHub todo list: put cupholders in the for... |
|
19
|
+
| 2 | * * * | 1 day ago | This bus is going so slowly that my AT&T 3G coverag... |
|
20
|
+
| 3 | * * * * * | 2 days ago | Every now and then I bust out that I'm from North D... |
|
21
|
+
| 4 | * * * | 3 days ago | Was told that "y'alls be stupid" by an adamant stre... |
|
22
|
+
| 5 | * * | 4 days ago | Now that we've fixed healthcare forever, who wants ... |
|
23
|
+
| 6 | * * * * | 4 days ago | Just wikipedia'd "Justin Bieber" and I still don't ... |
|
24
|
+
| 7 | * * * * | 5 days ago | Look. I'm not saying David Copperfield is a little ... |
|
25
|
+
| 8 | * | 6 days ago | SFO. Guys, we're at TERROR ALERT ORANGE. I don't t... |
|
26
|
+
| 9 | * | 7 days ago | Dammit. 2012 looks like garbage so far, but if a mo... |
|
27
|
+
| 10 | * | 10 days ago | At the MySQL + Rails combined meetup. I don't want ... |
|
28
|
+
| 11 | * | 10 days ago | Oh, they're doing a MacGruber movie. This makes sen... |
|
29
|
+
| 12 | * * * | 10 days ago | Just got my third free replacement earbuds from the... |
|
30
|
+
| 13 | * x 13 | 11 days ago | So for the seven of us that are both nerdy *and* va... |
|
31
|
+
| 14 | * * * * * | 11 days ago | I wouldn't say I'm "saving daylight" as much as I'm... |
|
32
|
+
| 15 | * * * | 13 days ago | I pre-ordered an iPad, checked into lunch, and now ... |
|
33
|
+
| 16 | * * | 13 days ago | In another life I want to be a pop star heartthrob ... |
|
34
|
+
| 17 | * | 14 days ago | Oh hey, a year or so of my beer consumption: http:/... |
|
35
|
+
| 18 | * | 14 days ago | Going to totally refork and rework my dotfiles soon... |
|
36
|
+
| 19 | * * * | 15 days ago | You change your Facebook pic, that syncs to my iPho... |
|
37
|
+
| 20 | * * | 17 days ago | just about finished my thesis on generating free en... |
|
38
|
+
+----+-----------+--------------+--------------------------------------------------------+
|
39
|
+
|
36
40
|
|
37
41
|
You can tell from the relative dearth of stars that I'm in my *screw followers I'm important so here's what I had for lunch* phase. Don't worry; I'll become a star whore again and tweet pop culture references in relation to presidential penile size soon enough.
|
38
42
|
|
@@ -43,9 +47,26 @@ You can also specify which user you want to run the query against by passing it
|
|
43
47
|
stars goodtutorials # generates @goodtutorials' stars
|
44
48
|
stars # generates @goodtutorials' stars
|
45
49
|
|
50
|
+
You can also get some knowledge dropped all over your face about a specific toot:
|
51
|
+
|
52
|
+
Type the number of the toot that you want to learn about
|
53
|
+
(or hit return to view all again, you ego-maniac) >>
|
54
|
+
14
|
55
|
+
|
56
|
+
5 stars: I wouldn't say I'm "saving daylight" as much as
|
57
|
+
I'm sequestering it in a small room underneath my stairs so
|
58
|
+
its screams can't be heard.
|
59
|
+
|
60
|
+
★ twilighteyes08
|
61
|
+
★ itsjustEm
|
62
|
+
★ aklw
|
63
|
+
★ shariv67
|
64
|
+
★ IsJonas
|
65
|
+
|
66
|
+
|
46
67
|
## state of affairs
|
47
68
|
|
48
|
-
|
69
|
+
Fork this bad boy and shape it as you see fit. I just randomly built some shit that I might like; maybe that process will work for you, too. Send me a pull request if you ship something awesome. Reminder: something is never awesome without tests.
|
49
70
|
|
50
71
|
## who
|
51
72
|
|
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ begin
|
|
13
13
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
14
|
gem.add_dependency('httparty')
|
15
15
|
gem.add_dependency('terminal-table')
|
16
|
+
gem.add_dependency('nokogiri')
|
16
17
|
end
|
17
18
|
Jeweler::GemcutterTasks.new
|
18
19
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/stars/client.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Stars
|
2
2
|
class Client
|
3
|
-
|
3
|
+
|
4
4
|
def self.load!(new_username=nil)
|
5
5
|
remember_username(new_username) if new_username
|
6
|
-
|
6
|
+
@recent = Stars::Favstar.new.recent(username)
|
7
|
+
display
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.display
|
11
|
+
system 'clear'
|
7
12
|
puts "\n ★ by @#{username}"
|
8
|
-
puts Stars::Formatter.new(
|
13
|
+
puts Stars::Formatter.new(@recent)
|
14
|
+
select_star
|
9
15
|
end
|
10
16
|
|
11
17
|
def self.username
|
@@ -29,6 +35,34 @@ module Stars
|
|
29
35
|
def self.config_path
|
30
36
|
File.join(ENV['HOME'], '.stars')
|
31
37
|
end
|
38
|
+
|
39
|
+
def self.select_star
|
40
|
+
selection = ''
|
41
|
+
while true
|
42
|
+
puts "Type the number of the toot that you want to learn about"
|
43
|
+
puts " (or hit return to view all again, you ego-maniac) >>"
|
44
|
+
selection = gets.chomp
|
45
|
+
break if ['','q','quit','exit','fuckthis'].include?(selection.downcase)
|
46
|
+
show_selection(selection)
|
47
|
+
end
|
48
|
+
display if selection == ''
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.show_selection(id)
|
52
|
+
puts ''
|
53
|
+
puts wrap_text(' ' + @recent[id.to_i - 1]['title'], 60)
|
54
|
+
puts parse_who(@recent[id.to_i - 1]['guid'])
|
55
|
+
puts ''
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.parse_who(url)
|
59
|
+
Stars::Favstar.new.show(url)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.wrap_text(txt, col = 80)
|
63
|
+
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
|
64
|
+
"\\1\\3\n ")
|
65
|
+
end
|
32
66
|
|
33
67
|
end
|
34
68
|
end
|
data/lib/stars/favstar.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
require 'nokogiri'
|
1
2
|
module Stars
|
2
3
|
class Favstar
|
3
4
|
include HTTParty
|
4
5
|
base_uri 'favstar.fm'
|
5
|
-
format :xml
|
6
|
-
attr_accessor :username
|
7
|
-
|
8
|
-
def initialize(username)
|
9
|
-
@username = username
|
10
|
-
end
|
11
6
|
|
12
|
-
def recent
|
13
|
-
self.class.get("/users/#{
|
7
|
+
def recent(username)
|
8
|
+
self.class.get("/users/#{username}/rss",
|
9
|
+
:format => :xml)['rss']['channel']['item']
|
10
|
+
end
|
11
|
+
|
12
|
+
def show(url)
|
13
|
+
# hardcode 17 to strip favstar domain for now
|
14
|
+
html = self.class.get(url[17..200], :format => :html)
|
15
|
+
Nokogiri::HTML(html).css('.avatarList img').collect do |img|
|
16
|
+
" ★ #{img.attributes['alt'].value}"
|
17
|
+
end
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
data/lib/stars/formatter.rb
CHANGED
@@ -15,9 +15,9 @@ module Stars
|
|
15
15
|
truncated + (truncated.size == text.size ? '' : '...')
|
16
16
|
end
|
17
17
|
|
18
|
-
def format(tweet)
|
18
|
+
def format(i, tweet)
|
19
19
|
stars,text = split_stars(tweet['title'])
|
20
|
-
[stars,relative_time(tweet['pubDate']),text]
|
20
|
+
[i,stars,relative_time(tweet['pubDate']),text]
|
21
21
|
end
|
22
22
|
|
23
23
|
def split_stars(text)
|
@@ -40,8 +40,8 @@ module Stars
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_s
|
43
|
-
tweets = @tweets.
|
44
|
-
table(['Stars','Time','Your Funnies'], *tweets).render
|
43
|
+
tweets = @tweets.collect_with_index{|tweet,i| format(i+1,tweet)}
|
44
|
+
table(['#','Stars','Time','Your Funnies'], *tweets).render
|
45
45
|
end
|
46
46
|
|
47
47
|
def relative_time(time)
|
data/stars.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stars}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Zach Holman"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-25}
|
13
13
|
s.default_executable = %q{stars}
|
14
14
|
s.description = %q{Recent favstar faves on your command line.}
|
15
15
|
s.email = %q{github.com@zachholman.com}
|
@@ -57,13 +57,16 @@ Gem::Specification.new do |s|
|
|
57
57
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
58
|
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
59
59
|
s.add_runtime_dependency(%q<terminal-table>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
60
61
|
else
|
61
62
|
s.add_dependency(%q<httparty>, [">= 0"])
|
62
63
|
s.add_dependency(%q<terminal-table>, [">= 0"])
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
63
65
|
end
|
64
66
|
else
|
65
67
|
s.add_dependency(%q<httparty>, [">= 0"])
|
66
68
|
s.add_dependency(%q<terminal-table>, [">= 0"])
|
69
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
data/test/test_client.rb
CHANGED
@@ -3,14 +3,18 @@ require 'helper'
|
|
3
3
|
class TestClient < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_load_with_username
|
6
|
-
mock(Stars::
|
6
|
+
mock(Stars::Client).system.with('clear').returns('')
|
7
|
+
mock(Stars::Formatter).new.times(any_times).with_any_args
|
7
8
|
mock(Stars::Client).puts.times(any_times).with_any_args
|
9
|
+
mock(Stars::Client).gets.times(any_times).with_any_args.returns('q')
|
8
10
|
Stars::Client.load!('holman')
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_load_without_username
|
12
|
-
mock(Stars::
|
14
|
+
mock(Stars::Client).system.with('clear').returns('')
|
15
|
+
mock(Stars::Formatter).new.times(any_times).with_any_args
|
13
16
|
mock(Stars::Client).puts.times(any_times).with_any_args
|
17
|
+
mock(Stars::Client).gets.times(any_times).with_any_args.returns('q')
|
14
18
|
Stars::Client.load!(nil)
|
15
19
|
end
|
16
20
|
|
data/test/test_favstar.rb
CHANGED
@@ -3,18 +3,14 @@ require 'helper'
|
|
3
3
|
class TestFavstar < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@favstar = Stars::Favstar.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_sets_username
|
10
|
-
assert_equal @favstar.username, 'holman'
|
6
|
+
@favstar = Stars::Favstar.new
|
11
7
|
end
|
12
8
|
|
13
9
|
def test_parties_hard
|
14
|
-
mock(Stars::Favstar).get('/users/holman/rss') {
|
10
|
+
mock(Stars::Favstar).get('/users/holman/rss', :format => :xml) {
|
15
11
|
{'rss' => {'channel' => {'item' => 'etc'} } }
|
16
12
|
}
|
17
|
-
@favstar.recent
|
13
|
+
@favstar.recent('holman')
|
18
14
|
end
|
19
15
|
|
20
16
|
end
|
data/test/test_formatter.rb
CHANGED
@@ -19,9 +19,9 @@ class TestFormatter < Test::Unit::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_format
|
22
|
-
format = @formatter.format(favstar_tweet_hash[0])
|
23
|
-
assert_equal format.size,
|
24
|
-
assert_equal format[0], '* *'
|
22
|
+
format = @formatter.format(1,favstar_tweet_hash[0])
|
23
|
+
assert_equal format.size, 4
|
24
|
+
assert_equal 1,format[0], '* *'
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_split_stars
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Zach Holman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-25 00:00:00 -07:00
|
18
18
|
default_executable: stars
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,18 @@ dependencies:
|
|
41
41
|
version: "0"
|
42
42
|
type: :runtime
|
43
43
|
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: nokogiri
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id003
|
44
56
|
description: Recent favstar faves on your command line.
|
45
57
|
email: github.com@zachholman.com
|
46
58
|
executables:
|