tweetline 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/tl +3 -131
  2. metadata +21 -5
data/bin/tl CHANGED
@@ -1,135 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'rubygems'
4
- require 'twitter'
5
- require 'json'
4
+ require 'lib/tweetline'
5
+ require 'lib/tweetline/cli'
6
6
 
7
- Twitter.configure do |config|
8
- File.open(File.expand_path('~/.tweetlinerc')) do |yaml|
9
- options = YAML.load(yaml)
10
- config.consumer_key = options[:consumer_key]
11
- config.consumer_secret = options[:consumer_secret]
12
- config.oauth_token = options[:oauth_token]
13
- config.oauth_token_secret = options[:oauth_token_secret]
14
- end
15
- end
16
-
17
- STDOUT.sync = true
18
-
19
- @is_piped_to_tweetline = `ps -ax -o pid,args | grep -E "^#{Process.pid+1}"` =~ /\/tl[^\/]*$/
20
-
21
- def time_stamp(time)
22
- time = Time.parse(time)
23
- format = '%I:%M %p'
24
- format = '%m/%d/%y ' + format unless time.yday == Time.now.yday
25
-
26
- return time.strftime(format)
27
- end
28
-
29
- def cat_tweet(tweet_id, created_at, name, screen_name, text)
30
- put_tweet(tweet_id, created_at, name, screen_name, text)
31
-
32
- tweet = Twitter.status(tweet_id)
33
- puts "Conversation:", "" if tweet.in_reply_to_status_id
34
- while tweet.in_reply_to_status_id
35
- tweet = Twitter.status(tweet.in_reply_to_status_id)
36
- put_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text)
37
- end
38
- end
39
-
40
- def say_tweet(tweet_id, created_at, name, screen_name, text)
41
- tweet_text = text.strip.gsub(/http:.*?( |$)/, '').gsub(/^RT/, '').gsub(/@/, '').split(/ /).map{|s| s.gsub(/[^A-Za-z0-9.!?,']/, '')}.join(' ')
42
- connector = text.strip =~ /^RT/ ? " retweets " : "says"
43
- # puts name, " #{connector} #{tweet_text}", ""
44
- put_tweet(tweet_id, created_at, name, screen_name, text)
45
- `say #{name} #{connector} "#{tweet_text}"`
46
- end
47
-
48
- def put_tweet(tweet_id, created_at, name, screen_name, text)
49
- if STDOUT.fcntl(Fcntl::F_GETFL, 0) == 1 and @is_piped_to_tweetline
50
- puts({"id" => tweet_id, "created_at" => created_at, "name" => name, "screen_name" => screen_name, "text" => text}.to_json)
51
- else
52
- puts "#{name} (@#{screen_name}) [#{time_stamp(created_at)}]", " #{text} (#{tweet_id})", ""
53
- end
54
- end
55
-
56
- def each_tweet(options={:count => 10})
57
- if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
58
- STDIN.each do |line|
59
- yield JSON.load(line)
60
- end
61
- else
62
- if options[:screen_name]
63
- screen_name = options.delete(:screen_name)
64
- timeline = Twitter.user_timeline(screen_name, options)
65
- else
66
- timeline = Twitter.home_timeline(options)
67
- end
68
- timeline.each do |tweet|
69
- yield({"id" => tweet.id, "created_at" => tweet.created_at, "name" => tweet.user.name, "screen_name" => tweet.user.screen_name, "text" => tweet.text})
70
- end
71
- end
72
- end
73
-
74
- if ARGV[0] == "say"
75
- each_tweet(:count => 1) do |tweet|
76
- say_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"])
77
- end
78
- elsif ARGV[0] == "json"
79
- each_tweet do |tweet|
80
- puts tweet.to_json
81
- end
82
- elsif ARGV[0] == "yaml"
83
- each_tweet do |tweet|
84
- puts tweet.to_yaml
85
- end
86
- elsif ARGV[0] == "ls" or ARGV.length == 0
87
- options = {:count => 10}
88
- options[:screen_name] = ARGV[1] if ARGV[1]
89
- each_tweet(options) do |tweet|
90
- put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"])
91
- end
92
- elsif ARGV[0] == "retweet"
93
- if ARGV[1]
94
- Twitter.retweet(ARGV[1])
95
- else
96
- each_tweet do |tweet|
97
- Twitter.retweet(tweet["id"])
98
- puts "Retweeted:" unless @is_piped_to_tweetline
99
- put_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"])
100
- end
101
- end
102
- elsif ARGV[0] == "cat"
103
- if ARGV[1]
104
- tweet = Twitter.status(ARGV[1])
105
- cat_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text)
106
- else
107
- each_tweet do |tweet|
108
- cat_tweet(tweet["id"], tweet["created_at"], tweet["name"], tweet["screen_name"], tweet["text"])
109
- end
110
- end
111
- elsif ARGV[0] == "tail"
112
- if ARGV[1] == "-f"
113
- previous_id = "1"
114
- count = 1
115
- while true
116
- begin
117
- Twitter.home_timeline(:count => count, :since_id => previous_id).reverse_each do |tweet|
118
- put_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text)
119
- previous_id = tweet.id
120
- end
121
- rescue
122
- put_tweet("", Time.now.to_s, "Tweetline", "tweetline", "Twitter is having issues.")
123
- end
124
- count = 5
125
- sleep(30)
126
- end
127
- else
128
- count = ARGV[1] == "-n" && ARGV[2].to_i > 0 ? ARGV[2].to_i : 10
129
- Twitter.home_timeline(:count => count).reverse_each do |tweet|
130
- put_tweet(tweet.id, tweet.created_at, tweet.user.name, tweet.user.screen_name, tweet.text)
131
- end
132
- end
133
- elsif ARGV[0] == "update"
134
- Twitter.update(ARGV[1..-1].join(' '))
135
- end
7
+ Tweetline::CLI.start
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetline
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anthony Crumley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-03 00:00:00 -05:00
18
+ date: 2011-04-09 00:00:00 -05:00
19
19
  default_executable: tl
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,23 @@ dependencies:
50
50
  version: 1.5.1
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
- description: Tweetline is a command line Twitter client for those who can't imagine a better interface to anything than the command line. Also, some folks may find it useful for automating some Twitter interactions.
53
+ - !ruby/object:Gem::Dependency
54
+ name: thor
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 43
62
+ segments:
63
+ - 0
64
+ - 14
65
+ - 6
66
+ version: 0.14.6
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: Tweetline is a command line Twitter client for those who can't imagine a better interface to anything than the command line. Also, some folks may find it useful for automating Twitter interactions.
54
70
  email: anthony.crumley@gmail.com
55
71
  executables:
56
72
  - tl