twitterscraper-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6791ebfd82694e768350ec33a19d3a34336c26c5344e57ef92af6bf02a0dddf1
4
- data.tar.gz: 351bf02ad483c60993114a828a4a1e39b936ab8e1373237aa66de6d0a3c809a6
3
+ metadata.gz: 68f4f63474e0c165316575e8d5fc2ac8ec9cdb18218be2f084263effbdf78bb0
4
+ data.tar.gz: d91edfdbd1cc36f4bf722e5a4673238a814846066370cd6810af483d089d1768
5
5
  SHA512:
6
- metadata.gz: 236d01eaaf4ed8c5c016fff35b5794e1609e840d8d27edfba92e0fc63138dfced1a10f4e2952d919360d9cc5111bc4987422a9e709c3e798434614b734b3b029
7
- data.tar.gz: 6831c32b358651e8c75af0772afbd0f2888934e5ef314112ecaa2dab1bcaeb681dc6a350d473eab79e36a83da57059b35dd88d693cb3a2f894789cb03ceb1e8c
6
+ metadata.gz: a7b0f2ce114a2eef72be3147d9459f7b91f15813825cd65baf10b0c891a64a9911c6b4e15db72425925e287043e46ac73cc956f088eb03c5ad960d213b4b4175
7
+ data.tar.gz: 8f42a24221aebc9fa361b7dbf9bb23cc683112b03bd549456fdd6f49bf8763d5d8797c73ce1d5cfe60d534f329d649d845a741baedcefaca46a17dd194055778
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitterscraper-ruby (0.2.0)
4
+ twitterscraper-ruby (0.3.0)
5
5
  nokogiri
6
6
 
7
7
  GEM
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/twitterscraper/cli'
4
+
5
+ begin
6
+ cli = Twitterscraper::Cli.new
7
+ cli.parse
8
+ cli.run
9
+ rescue => e
10
+ STDERR.puts e.message
11
+ STDERR.puts e.backtrace.join("\n")
12
+ exit 1
13
+ end
@@ -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
@@ -2,7 +2,8 @@ require 'time'
2
2
 
3
3
  module Twitterscraper
4
4
  class Tweet
5
- attr_reader :screen_name, :name, :user_id, :tweet_id, :tweet_url, :timestamp, :created_at, :text
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
  )
@@ -1,3 +1,3 @@
1
1
  module Twitterscraper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.bindir = "exe"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ts-3156
8
8
  autorequire:
9
- bindir: exe
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.3.0
75
+ version: 2.6.4
73
76
  required_rubygems_version: !ruby/object:Gem::Requirement
74
77
  requirements:
75
78
  - - ">="