socialinvestigator 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/socialinvestigator.rb +1 -0
- data/lib/socialinvestigator/cli.rb +4 -0
- data/lib/socialinvestigator/cli/twitter.rb +153 -0
- data/lib/socialinvestigator/client/twitter.rb +28 -0
- data/lib/socialinvestigator/config.rb +61 -0
- data/lib/socialinvestigator/version.rb +1 -1
- data/socialinvestigator.gemspec +1 -0
- metadata +19 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 68ac5910584d162d37369db68b69401cc5f85213
|
|
4
|
+
data.tar.gz: 0cb5ce2e0e7311a36be9a6b0a8c227a7507935cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56f8c7088524492a8e9a3f6eae31c48d73ae0a958fc41f1a569be0a0810ffd92fdbe0e040babeb72f4e5c0600980b406f7a906015c1e8abee487fdf5c7f72201
|
|
7
|
+
data.tar.gz: eb6f2479c6db084d9955632b418bfc90a7145c10d8fdf9fba696008adbf2cc84141f14a7f69edffc1a24fe185be78d5cb3f1472acbe3a89b0b5e8568174687b1
|
data/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Currently this tool is available command line only, and is installed by:
|
|
|
10
10
|
|
|
11
11
|
Then you can run the command 'socialinvestigator' to begin using it.
|
|
12
12
|
|
|
13
|
-
$
|
|
13
|
+
$ socialinvestigator
|
|
14
14
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
@@ -20,9 +20,17 @@ Full help
|
|
|
20
20
|
Search hacker news for a url:
|
|
21
21
|
|
|
22
22
|
$ socialinvestigator hn search http://willschenk.com
|
|
23
|
+
|
|
24
|
+
Setting up twitter. You'll need to register a twitter app for this to work.
|
|
25
|
+
Full walk through is here http://willschenk.com/scripting-twitter.
|
|
26
|
+
|
|
27
|
+
Once you have the twitter info, you put it in using the twitter config command:
|
|
28
|
+
|
|
29
|
+
$ socialinvestigator twitter config
|
|
30
|
+
|
|
23
31
|
## Contributing
|
|
24
32
|
|
|
25
|
-
1. Fork it ( https://github.com/
|
|
33
|
+
1. Fork it ( https://github.com/sublimeguile/socialinvestigator/fork )
|
|
26
34
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
35
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
36
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/socialinvestigator.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'thor'
|
|
2
2
|
require 'socialinvestigator/cli/hn'
|
|
3
|
+
require 'socialinvestigator/cli/twitter'
|
|
3
4
|
|
|
4
5
|
module Socialinvestigator
|
|
5
6
|
class HammerOfTheGods < Thor
|
|
@@ -25,5 +26,8 @@ module Socialinvestigator
|
|
|
25
26
|
|
|
26
27
|
desc "hn COMMANDS", "Hacker News Control Module"
|
|
27
28
|
subcommand "hn", Socialinvestigator::CLI::Hn
|
|
29
|
+
|
|
30
|
+
desc "twitter COMMANDS", "Twitter Control Module"
|
|
31
|
+
subcommand "twitter", Socialinvestigator::CLI::TwitterCli
|
|
28
32
|
end
|
|
29
33
|
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'twitter'
|
|
2
|
+
require 'socialinvestigator/client/twitter'
|
|
3
|
+
|
|
4
|
+
module Socialinvestigator
|
|
5
|
+
module CLI
|
|
6
|
+
class TwitterCli < Thor
|
|
7
|
+
desc "user SCREENAME", "Look up info for a specific user."
|
|
8
|
+
def user( username )
|
|
9
|
+
agent.print_user_info client.user( "wschenk" )
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
desc "lookup URL", "Resolve a link"
|
|
13
|
+
def lookup( url )
|
|
14
|
+
puts agent.lookup_url( url )
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "user_timeline", "Show the authenticated user's tweets"
|
|
18
|
+
def user_timeline
|
|
19
|
+
client.user_timeline.each do |tweet|
|
|
20
|
+
puts "@#{tweet.user.user_name}:#{tweet.text}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
desc "home_timeline", "Show the authenticated user's timeline"
|
|
25
|
+
def home_timeline
|
|
26
|
+
client.home_timeline.each do |tweet|
|
|
27
|
+
puts "@#{tweet.user.user_name}:#{tweet.text}"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc "retweets", "Show the authenticated user's retweets"
|
|
32
|
+
def retweets
|
|
33
|
+
client.retweets_of_me.each do |tweet|
|
|
34
|
+
puts "@#{tweet.user.user_name}:#{tweet.text}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
desc "mentions", "Show the authenticated user's mentions"
|
|
39
|
+
def mentions
|
|
40
|
+
client.mentions.each do |tweet|
|
|
41
|
+
puts "@#{tweet.user.user_name}:#{tweet.text}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
desc "limits", "Print out the current rate limits"
|
|
46
|
+
def limits
|
|
47
|
+
resp = client.get( "/1.1/application/rate_limit_status.json" )
|
|
48
|
+
current_time = Time.now.to_i
|
|
49
|
+
template = " %-40s %5d remaining, resets in %3d seconds\n"
|
|
50
|
+
resp.body[:resources].each do |category,resources|
|
|
51
|
+
puts category.to_s
|
|
52
|
+
resources.each do |resource,info|
|
|
53
|
+
printf template, resource.to_s, info[:remaining], (info[:reset] - current_time)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
desc "followers SCREENNAME", "Prints out all of the users followers"
|
|
59
|
+
def followers( screenname )
|
|
60
|
+
client.followers( screenname ).each do |u|
|
|
61
|
+
printf( "@%-15s %-20s %s\n", u.user_name, u.name, u.description )
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
desc "search STRING", "Shows all the tweets that match the string"
|
|
66
|
+
options [:exact, :user_info]
|
|
67
|
+
def search( string )
|
|
68
|
+
string = "\"#{string}\"" if options[:exact]
|
|
69
|
+
reach = 0
|
|
70
|
+
client.search( string, count: 100 ).each do |t|
|
|
71
|
+
puts "#{t.id}:#{t.created_at}:@#{t.user.user_name}:#{t.user.followers_count}:#{t.retweet_count}:#{t.text}"
|
|
72
|
+
reach += t.user.followers_count
|
|
73
|
+
if options[:user_info]
|
|
74
|
+
agent.print_user_info t.user if options[:user_info]
|
|
75
|
+
puts
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
puts "#{string} reached #{reach} people."
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
desc "filter TERMS", "Print out tweets that match the terms"
|
|
82
|
+
def filter( terms )
|
|
83
|
+
streaming_client.filter(track: terms) do |object|
|
|
84
|
+
puts "@#{object.user.user_name}:#{object.text}" if object.is_a?(Twitter::Tweet)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
desc "listen", "Prints our the authenticated user's stream as it happens"
|
|
89
|
+
def listen
|
|
90
|
+
streaming_client.user do |object|
|
|
91
|
+
case object
|
|
92
|
+
when Twitter::Tweet
|
|
93
|
+
puts "Tweet:@#{object.user.user_name}:#{object.text}"
|
|
94
|
+
when Twitter::DirectMessage
|
|
95
|
+
puts "DM:@#{object.sender.user_name}:#{object.text}"
|
|
96
|
+
when Twitter::Streaming::StallWarning
|
|
97
|
+
warn "Falling behind!"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
desc "config", "Prompts for the authnetication settings"
|
|
103
|
+
def config
|
|
104
|
+
config = Socialinvestigator::Config.config.twitter_config || {}
|
|
105
|
+
print "App key : "
|
|
106
|
+
config[:twitter_app_key] = $stdin.gets.strip
|
|
107
|
+
print "App Secret : "
|
|
108
|
+
config[:twitter_app_secret] = $stdin.gets.strip
|
|
109
|
+
print "Access token : "
|
|
110
|
+
config[:twitter_access_token] = $stdin.gets.strip
|
|
111
|
+
print "Access token secret: "
|
|
112
|
+
config[:twitter_access_token_secret] = $stdin.gets.strip
|
|
113
|
+
Socialinvestigator::Config.config.twitter_config = config
|
|
114
|
+
puts "Saved."
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
private
|
|
118
|
+
def agent
|
|
119
|
+
@agent ||= Socialinvestigator::Client::Twitter.new
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def client
|
|
123
|
+
tc = Socialinvestigator::Config.config.twitter_config
|
|
124
|
+
if tc.nil? || tc[:twitter_app_key].nil?
|
|
125
|
+
puts "Twitter config not found, try running:"
|
|
126
|
+
puts "socialinvestigator twitter config"
|
|
127
|
+
exit
|
|
128
|
+
end
|
|
129
|
+
@client ||= ::Twitter::REST::Client.new do |config|
|
|
130
|
+
config.consumer_key = tc[:twitter_app_key]
|
|
131
|
+
config.consumer_secret = tc[:twitter_app_secret]
|
|
132
|
+
config.access_token = tc[:twitter_access_token]
|
|
133
|
+
config.access_token_secret = tc[:twitter_access_token_secret]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def streaming_client
|
|
138
|
+
tc = Socialinvestigator::Config.config.twitter_config
|
|
139
|
+
if tc.nil?
|
|
140
|
+
puts "Twitter config not found, try running:"
|
|
141
|
+
puts "socialinvestigator twitter config"
|
|
142
|
+
exit
|
|
143
|
+
end
|
|
144
|
+
@streaming_client ||= ::Twitter::Streaming::Client.new do |config|
|
|
145
|
+
config.consumer_key = tc[:twitter_app_key]
|
|
146
|
+
config.consumer_secret = tc[:twitter_app_secret]
|
|
147
|
+
config.access_token = tc[:twitter_access_token]
|
|
148
|
+
config.access_token_secret = tc[:twitter_access_token_secret]
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
|
|
3
|
+
module Socialinvestigator
|
|
4
|
+
module Client
|
|
5
|
+
class Twitter
|
|
6
|
+
def print_user_info( u )
|
|
7
|
+
t = "%-20s: %s\n"
|
|
8
|
+
printf t, "Screenname", u.user_name
|
|
9
|
+
printf t, "Full Name", u.name
|
|
10
|
+
printf t, "Bio", u.description
|
|
11
|
+
printf t, "Website", lookup_url( u.website.to_s )
|
|
12
|
+
printf t, "Joined", u.created_at.strftime( "%Y-%m-%d" )
|
|
13
|
+
printf t, "Location", u.location
|
|
14
|
+
printf t, "Verified", u.verified?
|
|
15
|
+
printf t, "Tweets", u.tweets_count
|
|
16
|
+
printf t, "Followers", u.followers_count
|
|
17
|
+
printf t, "Following", u.friends_count
|
|
18
|
+
printf t, "Favorites count", u.favorites_count
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def lookup_url( url )
|
|
22
|
+
return nil if url.nil? || url == ""
|
|
23
|
+
r = HTTParty.head url, { follow_redirects: false }
|
|
24
|
+
r['location'] || url
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
module Socialinvestigator
|
|
4
|
+
module Config
|
|
5
|
+
def self.config
|
|
6
|
+
FileConfigStorage.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class AbstractConfigStorage
|
|
10
|
+
def twitter_config
|
|
11
|
+
raise "Not implemented in #{self.class.name}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class FileConfigStorage < AbstractConfigStorage
|
|
16
|
+
def initialize( dir = nil )
|
|
17
|
+
@dir = dir || "#{ENV['HOME']}/.socialinvestigator"
|
|
18
|
+
|
|
19
|
+
FileUtils.mkdir_p @dir
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def twitter_config
|
|
23
|
+
read_yaml( "twitter.yml" )
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def twitter_config= config
|
|
27
|
+
save_yaml( "twitter.yml", config )
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def read_yaml( name )
|
|
31
|
+
file = "#{@dir}/#{name}"
|
|
32
|
+
|
|
33
|
+
if File.exists? file
|
|
34
|
+
return YAML::load_file( file )
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def save_yaml( name, obj )
|
|
41
|
+
File.open( "#{@dir}/#{name}", "w" ) do |out|
|
|
42
|
+
out.write obj.to_yaml
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# def credential_store
|
|
50
|
+
# "#{@dir}/oauth2_creds.json"
|
|
51
|
+
# end
|
|
52
|
+
|
|
53
|
+
# def client_secrets
|
|
54
|
+
# "#{@dir}/client_secrets.json"
|
|
55
|
+
# end
|
|
56
|
+
|
|
57
|
+
# def cached_api( api, version )
|
|
58
|
+
# "#{@dir}/#{api}-#{version}.cache"
|
|
59
|
+
# end
|
|
60
|
+
# end
|
|
61
|
+
# end
|
data/socialinvestigator.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: socialinvestigator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Will Schenk
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-11-
|
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - '>='
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: twitter
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: bundler
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -83,7 +97,10 @@ files:
|
|
|
83
97
|
- lib/socialinvestigator.rb
|
|
84
98
|
- lib/socialinvestigator/cli.rb
|
|
85
99
|
- lib/socialinvestigator/cli/hn.rb
|
|
100
|
+
- lib/socialinvestigator/cli/twitter.rb
|
|
86
101
|
- lib/socialinvestigator/client/hn.rb
|
|
102
|
+
- lib/socialinvestigator/client/twitter.rb
|
|
103
|
+
- lib/socialinvestigator/config.rb
|
|
87
104
|
- lib/socialinvestigator/version.rb
|
|
88
105
|
- socialinvestigator.gemspec
|
|
89
106
|
homepage: https://github.com/sublimeguile/socialinvestigator
|