tweetline 0.0.1

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 +135 -0
  2. metadata +102 -0
data/bin/tl ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'twitter'
5
+ require 'json'
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
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tweetline
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Anthony Crumley
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-03 00:00:00 -05:00
19
+ default_executable: tl
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: twitter
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 31
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 0
34
+ version: 1.2.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 1
48
+ - 5
49
+ - 1
50
+ version: 1.5.1
51
+ type: :runtime
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.
54
+ email: anthony.crumley@gmail.com
55
+ executables:
56
+ - tl
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - bin/tl
63
+ has_rdoc: true
64
+ homepage: https://github.com/craftycode/tweetline
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 57
78
+ segments:
79
+ - 1
80
+ - 8
81
+ - 7
82
+ version: 1.8.7
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 23
89
+ segments:
90
+ - 1
91
+ - 3
92
+ - 6
93
+ version: 1.3.6
94
+ requirements: []
95
+
96
+ rubyforge_project: tweetline
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Command line client for Twitter.
101
+ test_files: []
102
+