seo-keywords-generator-ruby 0.1.7 → 0.1.9

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: 38e1e355a208051529ebe28c45552e38892a134dda458b9091f6cfa9462a6aae
4
- data.tar.gz: a165029c4b762a3ad8a33524a44719d4078de62bce4edf6eeb4956502f31d287
3
+ metadata.gz: 3fcce4a4dae84b3eea8abefcf4dce39f10f9084c2b2f1ca90c5cb5e14ee06ab5
4
+ data.tar.gz: b0aa67a12d6d680e70f87793a4da42cd90f440209936aafb0e685dd049c2240b
5
5
  SHA512:
6
- metadata.gz: 8b75f6aedcb5180947dadec04fa0600b6a85da7ff657e1e239c1f85754f4cc2157c3f0522158af07e14894e492f7510009e26e44af717e8ae79d8584144dd042
7
- data.tar.gz: df6da0cae1cb8c548fd9d7242caa0934b10a54e895d199160c6ff4423e19bdf2db2fe296a19ec8b5409c28eea833ade1116663570cfa3fc038d9cf133b5fa726
6
+ metadata.gz: 93c5ac9430262fbb10f3a4654595718e980f3a3941011e58404285ca6e69809a53f866e85bcc49c67837df263b75f8fc2cc12ee8e36c97e1316f1a7ac54d1f83
7
+ data.tar.gz: 336d24b436d53d7c83a42fc5dd236ee6fe019286c5e324e70ce2769cdbf37b2bf2947f5b045e05ac942d413ed3ea011dbdccc260b201ad40299799fdacbab6ed
data/bin/seo CHANGED
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'seo-keywords-generator-ruby/cli'
3
+ # frozen_string_literal: true
4
4
 
5
- SeoKeywordsGeneratorCLI.start(ARGV)
5
+ # Enable local usage from cloned repo
6
+ root = File.expand_path("../..", __FILE__)
7
+ $LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
8
+
9
+ require "seo-keywords-generator-ruby"
10
+
11
+ SeoKeywordsGenerator::CLI.new(ARGV).run
@@ -2,128 +2,131 @@ require 'google_search_results'
2
2
  require 'json'
3
3
  require 'csv'
4
4
 
5
+ module SeoKeywordsGenerator
6
+ autoload :CLI, "seo-keywords-generator-ruby/cli"
5
7
 
6
- class SeoKeywordsGenerator
7
- attr_accessor :query, :api_key, :lang, :country, :domain
8
-
9
- def initialize(query, api_key, lang = 'en', country = 'us', domain = 'google.com')
10
- @query = query
11
- @api_key = api_key
12
- @lang = lang
13
- @country = country
14
- @domain = domain
15
- @related_questions_results = []
16
- end
17
-
18
- def get_auto_complete
19
- params = {
20
- api_key: @api_key, # https://serpapi.com/manage-api-key
21
- engine: 'google_autocomplete', # search engine
22
- q: @query, # search query
23
- gl: @country, # country of the search
24
- hl: @lang # language of the search
25
- }
26
-
27
- search = GoogleSearch.new(params) # data extraction on the SerpApi backend
28
- results = search.get_hash # JSON -> Ruby hash
8
+ class Scraper
9
+ attr_accessor :query, :api_key, :lang, :country, :domain
29
10
 
30
- results[:suggestions].map{ |result| result[:value] }.compact
31
- end
32
-
33
- def get_related_searches
34
- params = {
35
- api_key: @api_key, # https://serpapi.com/manage-api-key
36
- engine: 'google', # search engine
37
- q: @query, # search query
38
- google_domain: @domain, # Google domain to use
39
- gl: @country, # country of the search
40
- hl: @lang # language of the search
41
- }
11
+ def initialize(query, api_key, lang = 'en', country = 'us', domain = 'google.com')
12
+ @query = query
13
+ @api_key = api_key
14
+ @lang = lang
15
+ @country = country
16
+ @domain = domain
17
+ @related_questions_results = []
18
+ end
42
19
 
43
- search = GoogleSearch.new(params) # data extraction on the SerpApi backend
44
- results = search.get_hash # JSON -> Ruby hash
20
+ def get_auto_complete
21
+ params = {
22
+ api_key: @api_key, # https://serpapi.com/manage-api-key
23
+ engine: 'google_autocomplete', # search engine
24
+ q: @query, # search query
25
+ gl: @country, # country of the search
26
+ hl: @lang # language of the search
27
+ }
28
+
29
+ search = GoogleSearch.new(params) # data extraction on the SerpApi backend
30
+ results = search.get_hash # JSON -> Ruby hash
31
+
32
+ results[:suggestions].map{ |result| result[:value] }.compact
33
+ end
45
34
 
46
- results[:related_searches].map{ |result| result[:query] }.compact
47
- end
35
+ def get_related_searches
36
+ params = {
37
+ api_key: @api_key, # https://serpapi.com/manage-api-key
38
+ engine: 'google', # search engine
39
+ q: @query, # search query
40
+ google_domain: @domain, # Google domain to use
41
+ gl: @country, # country of the search
42
+ hl: @lang # language of the search
43
+ }
44
+
45
+ search = GoogleSearch.new(params) # data extraction on the SerpApi backend
46
+ results = search.get_hash # JSON -> Ruby hash
47
+
48
+ results[:related_searches].map{ |result| result[:query] }.compact
49
+ end
48
50
 
49
- def get_depth_results(token, depth)
50
- depth_params = {
51
- q: @query,
52
- api_key: @api_key,
53
- engine: 'google_related_questions',
54
- next_page_token: token
55
- }
56
-
57
- depth_search = GoogleSearch.new(depth_params)
58
- depth_results = depth_search.get_hash
59
-
60
- @related_questions_results += depth_results[:related_questions]&.map{ |result| result[:question] }
61
-
62
- if depth > 1
63
- depth_results[:related_questions]&.each do |question|
64
- if question[:next_page_token]
65
- get_depth_results(question[:next_page_token], depth - 1)
51
+ def get_depth_results(token, depth)
52
+ depth_params = {
53
+ q: @query,
54
+ api_key: @api_key,
55
+ engine: 'google_related_questions',
56
+ next_page_token: token
57
+ }
58
+
59
+ depth_search = GoogleSearch.new(depth_params)
60
+ depth_results = depth_search.get_hash
61
+
62
+ @related_questions_results += depth_results[:related_questions]&.map{ |result| result[:question] }
63
+
64
+ if depth > 1
65
+ depth_results[:related_questions]&.each do |question|
66
+ if question[:next_page_token]
67
+ get_depth_results(question[:next_page_token], depth - 1)
68
+ end
66
69
  end
67
70
  end
68
71
  end
69
- end
70
-
71
- def get_related_questions(depth_limit = 0)
72
- params = {
73
- api_key: @api_key, # https://serpapi.com/manage-api-key
74
- engine: 'google', # search engine
75
- q: @query, # search query
76
- google_domain: @domain, # Google domain to use
77
- gl: @country, # country of the search
78
- hl: @lang # language of the search
79
- }
80
-
81
- search = GoogleSearch.new(params) # data extraction on the SerpApi backend
82
- results = search.get_hash # JSON -> Ruby hash
83
72
 
84
- @related_questions_results = results[:related_questions]&.map{ |result| result[:question] }
73
+ def get_related_questions(depth_limit = 0)
74
+ params = {
75
+ api_key: @api_key, # https://serpapi.com/manage-api-key
76
+ engine: 'google', # search engine
77
+ q: @query, # search query
78
+ google_domain: @domain, # Google domain to use
79
+ gl: @country, # country of the search
80
+ hl: @lang # language of the search
81
+ }
82
+
83
+ search = GoogleSearch.new(params) # data extraction on the SerpApi backend
84
+ results = search.get_hash # JSON -> Ruby hash
85
+
86
+ @related_questions_results = results[:related_questions]&.map{ |result| result[:question] }
87
+
88
+ depth_limit = 4 if depth_limit > 4
89
+
90
+ if depth_limit > 0
91
+ results[:related_questions]&.each do |question|
92
+ if question[:next_page_token]
93
+ get_depth_results(question[:next_page_token], depth_limit)
94
+ end
95
+ end
96
+ end
85
97
 
86
- depth_limit = 4 if depth_limit > 4
98
+ @related_questions_results
99
+ end
87
100
 
88
- if depth_limit > 0
89
- results[:related_questions]&.each do |question|
90
- if question[:next_page_token]
91
- get_depth_results(question[:next_page_token], depth_limit)
101
+ def save_to_csv(data)
102
+ CSV.open("#{@query.gsub(' ', '_')}.csv", 'w') do |csv_file|
103
+ csv_file << data.keys
104
+ max_length = data.values.map(&:length).max
105
+ (0...max_length).each do |index|
106
+ csv_file << data.values.map { |value| value[index] }
92
107
  end
93
108
  end
94
109
  end
95
-
96
- @related_questions_results
97
- end
98
-
99
- def save_to_csv(data)
100
- CSV.open("#{@query.gsub(' ', '_')}.csv", 'w') do |csv_file|
101
- csv_file << data.keys
102
- max_length = data.values.map(&:length).max
103
- (0...max_length).each do |index|
104
- csv_file << data.values.map { |value| value[index] }
110
+
111
+ def save_to_json(data)
112
+ File.open("#{@query.gsub(' ', '_')}.json", 'w') do |json_file|
113
+ json_file.write(JSON.pretty_generate(data))
105
114
  end
106
115
  end
107
- end
108
-
109
- def save_to_json(data)
110
- File.open("#{@query.gsub(' ', '_')}.json", 'w') do |json_file|
111
- json_file.write(JSON.pretty_generate(data))
112
- end
113
- end
114
-
115
- def save_to_txt(data)
116
- File.open("#{@query.gsub(' ', '_')}.txt", "w") do |txt_file|
117
- data.each do |key, values|
118
- txt_file.puts("#{key}:")
119
- values.each do |value|
120
- txt_file.puts(" #{value}")
116
+
117
+ def save_to_txt(data)
118
+ File.open("#{@query.gsub(' ', '_')}.txt", "w") do |txt_file|
119
+ data.each do |key, values|
120
+ txt_file.puts("#{key}:")
121
+ values.each do |value|
122
+ txt_file.puts(" #{value}")
123
+ end
121
124
  end
122
125
  end
123
126
  end
127
+
128
+ def print_data(data)
129
+ puts JSON.pretty_generate(data)
130
+ end
124
131
  end
125
-
126
- def print_data(data)
127
- puts JSON.pretty_generate(data)
128
- end
129
- end
132
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seo-keywords-generator-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Chukhrai
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-04 00:00:00.000000000 Z
12
+ date: 2023-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google_search_results