twitterscraper-ruby 0.2.0 → 0.3.0
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/Gemfile.lock +1 -1
- data/bin/twitterscraper +13 -0
- data/lib/twitterscraper/cli.rb +34 -0
- data/lib/twitterscraper/tweet.rb +8 -2
- data/lib/version.rb +1 -1
- data/twitterscraper-ruby.gemspec +3 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68f4f63474e0c165316575e8d5fc2ac8ec9cdb18218be2f084263effbdf78bb0
|
4
|
+
data.tar.gz: d91edfdbd1cc36f4bf722e5a4673238a814846066370cd6810af483d089d1768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7b0f2ce114a2eef72be3147d9459f7b91f15813825cd65baf10b0c891a64a9911c6b4e15db72425925e287043e46ac73cc956f088eb03c5ad960d213b4b4175
|
7
|
+
data.tar.gz: 8f42a24221aebc9fa361b7dbf9bb23cc683112b03bd549456fdd6f49bf8763d5d8797c73ce1d5cfe60d534f329d649d845a741baedcefaca46a17dd194055778
|
data/Gemfile.lock
CHANGED
data/bin/twitterscraper
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$stdout.sync = true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'optparse'
|
5
|
+
require 'twitterscraper'
|
6
|
+
|
7
|
+
module Twitterscraper
|
8
|
+
class Cli
|
9
|
+
def parse
|
10
|
+
@options = parse_options(ARGV)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
client = Twitterscraper::Client.new
|
15
|
+
limit = options['limit'] ? options['limit'].to_i : 100
|
16
|
+
tweets = client.query_tweets(options['query'], limit: limit, start_date: options['start_date'], end_date: options['end_date'])
|
17
|
+
File.write('tweets.json', ::JSON.dump(tweets))
|
18
|
+
end
|
19
|
+
|
20
|
+
def options
|
21
|
+
@options
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_options(argv)
|
25
|
+
argv.getopts(
|
26
|
+
'h',
|
27
|
+
'query:',
|
28
|
+
'limit:',
|
29
|
+
'start_date:',
|
30
|
+
'end_date:',
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/twitterscraper/tweet.rb
CHANGED
@@ -2,7 +2,8 @@ require 'time'
|
|
2
2
|
|
3
3
|
module Twitterscraper
|
4
4
|
class Tweet
|
5
|
-
|
5
|
+
KEYS = [:screen_name, :name, :user_id, :tweet_id, :tweet_url, :created_at, :text]
|
6
|
+
attr_reader *KEYS
|
6
7
|
|
7
8
|
def initialize(attrs)
|
8
9
|
attrs.each do |key, value|
|
@@ -10,6 +11,12 @@ module Twitterscraper
|
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
14
|
+
def to_json(options = {})
|
15
|
+
KEYS.map do |key|
|
16
|
+
[key, send(key)]
|
17
|
+
end.to_h.to_json
|
18
|
+
end
|
19
|
+
|
13
20
|
class << self
|
14
21
|
def from_html(text)
|
15
22
|
html = Nokogiri::HTML(text)
|
@@ -31,7 +38,6 @@ module Twitterscraper
|
|
31
38
|
user_id: html.attr('data-user-id').to_i,
|
32
39
|
tweet_id: html.attr('data-tweet-id').to_i,
|
33
40
|
tweet_url: 'https://twitter.com' + html.attr('data-permalink-path'),
|
34
|
-
timestamp: timestamp,
|
35
41
|
created_at: Time.at(timestamp, in: '+00:00'),
|
36
42
|
text: inner_html.xpath("//div[@class[contains(., 'js-tweet-text-container')]]/p[@class[contains(., 'js-tweet-text')]]").first.text,
|
37
43
|
)
|
data/lib/version.rb
CHANGED
data/twitterscraper-ruby.gemspec
CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
23
|
end
|
24
|
-
spec.
|
25
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.executables = ["twitterscraper"]
|
26
25
|
spec.require_paths = ["lib"]
|
27
26
|
|
27
|
+
spec.required_ruby_version = ">= 2.6.4"
|
28
|
+
|
28
29
|
spec.add_dependency "nokogiri"
|
29
30
|
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitterscraper-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
@@ -27,7 +27,8 @@ dependencies:
|
|
27
27
|
description: A gem to scrape Tweets
|
28
28
|
email:
|
29
29
|
- ts_3156@yahoo.co.jp
|
30
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- twitterscraper
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
34
|
files:
|
@@ -43,8 +44,10 @@ files:
|
|
43
44
|
- Rakefile
|
44
45
|
- bin/console
|
45
46
|
- bin/setup
|
47
|
+
- bin/twitterscraper
|
46
48
|
- lib/twitterscraper-ruby.rb
|
47
49
|
- lib/twitterscraper.rb
|
50
|
+
- lib/twitterscraper/cli.rb
|
48
51
|
- lib/twitterscraper/client.rb
|
49
52
|
- lib/twitterscraper/http.rb
|
50
53
|
- lib/twitterscraper/lang.rb
|
@@ -69,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
72
|
requirements:
|
70
73
|
- - ">="
|
71
74
|
- !ruby/object:Gem::Version
|
72
|
-
version: 2.
|
75
|
+
version: 2.6.4
|
73
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
77
|
requirements:
|
75
78
|
- - ">="
|