pointmd_comments 0.1.0 → 0.1.5

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: b3f84ad7c180458bae9b8d07589647dae11825d3580bbbec79602fb22cafcb8a
4
- data.tar.gz: 060d0ce0518fb48dbd105ca9c3084e687ced21d08c8e1ee1458e8a47eea8f7d7
3
+ metadata.gz: a24b7ec9ac474cb157789d03ddb9c41270eb58d96578c6c6dca1ad6d68ed7f24
4
+ data.tar.gz: ea9984f5c43eca94286344ec7ebc83fcac9dba399e7ab13b06a9cc80f88e7083
5
5
  SHA512:
6
- metadata.gz: 77a227fd2f38df75955f865350451a8a905bdeaa2a7ed959822c8c0322499923e4e20ab1ea17e1fe19a1c974190d565150617c288a29dca5bc9326bb645bb686
7
- data.tar.gz: b8584558d781b6cd09c566d3e2c6b1455686f40efe22edb7745867f6ece79de6b13f2b7ae6719010efb1bb22785e8070ebd703545d43bb12b588ab4ddf1a4b45
6
+ metadata.gz: 28e1ff1042ee11284ae1c2bd87dcc41fbb77b2bc033debb92df912499253977dc83ee17e132febfdfae6aeb71e9e2f664c37864c3e50e8e9243e32668fa20565
7
+ data.tar.gz: 03f40f717c3919eddfe850e5aa4381b1a90b9053a6f2ae847eec605cb3713ae93410083b38f2d9e28e6e8d85dfcf8ffbb4026c90fa6ce1fb9a2e27c336c7f170
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'pointmd_comments'
3
3
 
4
- PointmdComments.collect
4
+ PointmdComments.collect_from_shell
@@ -13,15 +13,15 @@ require 'pointmd_comments/aggregators/comments'
13
13
  require 'pointmd_comments/errors/not_implemented'
14
14
  require 'pointmd_comments/errors/unknown_source'
15
15
 
16
- require 'pry'
17
-
18
16
  module PointmdComments
19
17
  class Error < StandardError; end
20
18
 
21
- def self.collect
22
- # DOESN'T WORK!!
19
+ def self.collect(options = {})
20
+ Aggregators::Main.new(options).call
21
+ end
22
+
23
+ def self.collect_from_shell
23
24
  args = ARGV.dup
24
- puts args
25
25
  options = OptParser.new.parse
26
26
  Aggregators::Main.new(options).call
27
27
  rescue StandardError => e
@@ -1,11 +1,13 @@
1
1
  module PointmdComments
2
2
  module Aggregators
3
3
  class Main
4
- attr_reader :posts_aggregator, :browser, :comments_aggregator, :all_comments, :posts, :source, :path
4
+ attr_reader :posts_aggregator, :browser, :comments_aggregator, :all_comments, :posts, :source, :output, :path
5
5
 
6
6
  def initialize(options)
7
- @path = options[:path]
8
- @source = options[:source]
7
+ # Currently 'path' is not supported
8
+ @path = nil
9
+ @output = options[:output] || default_output_path
10
+ @source = options[:source] || Aggregators::Posts::DEFAULT_SOURCE
9
11
  @posts_aggregator = Aggregators::Posts.new(source: source, path: path)
10
12
  @comments_aggregator = Aggregators::Comments.new
11
13
  @browser = ::Watir::Browser.new :chrome, headless: true
@@ -44,10 +46,21 @@ module PointmdComments
44
46
  end
45
47
 
46
48
  def write_to_csv
47
- CSV.open('output.csv', 'w') do |csv|
49
+ # File#expand_path is needed to process paths like '~/test.txt' => '/Users/me/test.txt'
50
+ file_path = File.expand_path(output)
51
+
52
+ CSV.open(file_path, 'w') do |csv|
48
53
  all_comments.each { |c| csv << c }
49
54
  end
50
55
  end
56
+
57
+ def default_output_path
58
+ "pointmd_comments_#{current_time}.csv"
59
+ end
60
+
61
+ def current_time
62
+ Time.now.strftime('%Y%m%d_%H%M')
63
+ end
51
64
  end
52
65
  end
53
66
  end
@@ -3,6 +3,7 @@ module PointmdComments
3
3
  class Posts
4
4
  # NOTE: This array may be populated with other website sections in the future.
5
5
  ALLOWED_SOURCES = %i[news today].freeze
6
+ DEFAULT_SOURCE = :news
6
7
  MAIN_PAGE = 'https://point.md/ru/'.freeze
7
8
 
8
9
  attr_reader :source, :urls
@@ -26,11 +26,11 @@ module PointmdComments
26
26
  options[:source] = s.to_sym
27
27
  end
28
28
  opts.on(
29
- '-p PATH',
30
- '--path=PATH',
31
- 'A file path to pull links from.'
32
- ) do |s|
33
- options[:source] = s.to_sym
29
+ '-o OUTPUT_PATH',
30
+ '--output=OUTPUT_PATH',
31
+ 'A custom file path for the CSV.'
32
+ ) do |p|
33
+ options[:output] = p
34
34
  end
35
35
  opts.on('-V', '--version', 'Version') do
36
36
  puts PointmdComments::VERSION
@@ -1,3 +1,3 @@
1
1
  module PointmdComments
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pointmd_comments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolai Stoianov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2020-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry