neo4apis-twitter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/twitter.yml +6 -0
- data/lib/neo4apis-twitter.rb +1 -0
- data/lib/neo4apis/cli/twitter.rb +69 -0
- data/lib/neo4apis/twitter.rb +1 -0
- data/neo4apis-twitter.gemspec +3 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4ea71535fbe17e2305b38c9acc1a20c3362ea53
|
4
|
+
data.tar.gz: d2f2266563615e7adc2c6e1e4f8d59a9c6f18003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b71ebd8a79a4cb0b8fe966c7dc9abb38a379e183543b100d2b434b128eabf382f5a481c26e1d7d0356165774cd37d56b5105ca20563875cf7062084de396a2ad
|
7
|
+
data.tar.gz: 4c4ebf38beea41ed436230bfc103bc7f9d50c12ba3fcfcf6b43ac0d62208d6f5705689473ddf42ffcd73420e697eec31eed7afbc1a8edc662fd37fd5d53f05d6
|
data/README.md
CHANGED
data/config/twitter.yml
ADDED
data/lib/neo4apis-twitter.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'twitter'
|
2
|
+
|
3
|
+
module Neo4Apis
|
4
|
+
module CLI
|
5
|
+
class Twitter < Thor
|
6
|
+
class_option :config_path, type: :string, default: 'config/twitter.yml'
|
7
|
+
|
8
|
+
desc "filter TRACK", "Streams tweets via a filter"
|
9
|
+
def filter(track)
|
10
|
+
neo4apis_client.batch do
|
11
|
+
twitter_client(true).filter(track: track, &tweet_importer)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
option :result_type, type: :string
|
16
|
+
desc "search QUERY COUNT", "Import tweets via a search query"
|
17
|
+
def search(query, count)
|
18
|
+
neo4apis_client.batch do
|
19
|
+
twitter_client(false).search(query, options).take(count.to_i).each(&tweet_importer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def tweet_importer
|
26
|
+
Proc.new do |object|
|
27
|
+
case object
|
28
|
+
when ::Twitter::Tweet
|
29
|
+
say "got tweet from @#{object.user.screen_name}: #{object.text}"
|
30
|
+
neo4apis_client.import :Tweet, object
|
31
|
+
when ::Twitter::Streaming::StallWarning
|
32
|
+
puts "Falling behind!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
NEO4APIS_CLIENT_CLASS = ::Neo4Apis::Twitter
|
38
|
+
|
39
|
+
def neo4apis_client
|
40
|
+
@neo4apis_client ||= NEO4APIS_CLIENT_CLASS.new(Neo4j::Session.open(:server_db, parent_options[:neo4j_url]), import_retweets: true, import_hashtags: true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def twitter_client(streaming)
|
44
|
+
return @twitter_client if @twitter_client
|
45
|
+
|
46
|
+
twitter_client_class = streaming ? ::Twitter::Streaming::Client : ::Twitter::REST::Client
|
47
|
+
|
48
|
+
@twitter_client = twitter_client_class.new do |config|
|
49
|
+
yml_config.each do |key, value|
|
50
|
+
config.send("#{key}=", value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# For reference for this gem's documentation:
|
56
|
+
# https://github.com/sferik/twitter/blob/master/examples/Configuration.md
|
57
|
+
def yml_config
|
58
|
+
require 'yaml'
|
59
|
+
@yml_config ||= YAML.load(File.open(options[:config_path]).read)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Base < Thor
|
64
|
+
desc "twitter SUBCOMMAND ...ARGS", "methods of importing data automagically from Twitter"
|
65
|
+
subcommand "twitter", CLI::Twitter
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/neo4apis/twitter.rb
CHANGED
data/neo4apis-twitter.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.unshift lib unless $:.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "neo4apis-twitter"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.2.0'
|
7
7
|
s.required_ruby_version = ">= 1.9.1"
|
8
8
|
|
9
9
|
s.authors = "Brian Underwood"
|
@@ -18,7 +18,7 @@ A ruby gem using neo4apis to make importing twitter data to neo4j easy
|
|
18
18
|
s.require_path = 'lib'
|
19
19
|
s.files = Dir.glob("{bin,lib,config}/**/*") + %w(README.md Gemfile neo4apis-twitter.gemspec)
|
20
20
|
|
21
|
-
s.add_dependency('neo4apis',
|
22
|
-
s.add_dependency('twitter',
|
21
|
+
s.add_dependency('neo4apis', '~> 0.3.0')
|
22
|
+
s.add_dependency('twitter', '~> 5.12.0')
|
23
23
|
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo4apis-twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Underwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neo4apis
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: twitter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,7 +47,9 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- Gemfile
|
49
49
|
- README.md
|
50
|
+
- config/twitter.yml
|
50
51
|
- lib/neo4apis-twitter.rb
|
52
|
+
- lib/neo4apis/cli/twitter.rb
|
51
53
|
- lib/neo4apis/twitter.rb
|
52
54
|
- neo4apis-twitter.gemspec
|
53
55
|
homepage: https://github.com/neo4jrb/neo4apis-twitter/
|