seo-keywords-generator-ruby 0.1.8 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f023fbe483a818c79c848dee63d29fc67e15fb3e87001285f6983ddcb76d551a
4
- data.tar.gz: ec7220b1bc1578d519f0cbbeedd6569b45c40d3eac048641dbbcae5b71fb8c4c
3
+ metadata.gz: 052c7c699617cde9c463a1e9c2dc8c04e8c3529ac0e6398dce3f9b416007607a
4
+ data.tar.gz: 00ac688665e5e523d3d50df0b60498944f93eafaabf00f836cf6cfc3602d77b7
5
5
  SHA512:
6
- metadata.gz: a9ee14090eef76a2361944ea291f6b263ce9adc49d53f53d3a2ebc354dc5bed91acff3c6baac428312cc4e4164648e1d4b63d2f2305e978c141fee3ce32d82a6
7
- data.tar.gz: 893a08ae04971c4f1f61562ccb3f65480cfe106dee5d4d0fa71f3bd5aa80413b34889df6cc46b4c2294dea03e8d80af6d73c102d4d1326c7eec530493084f32b
6
+ metadata.gz: c023cb016e1a0bd88e0e9536273e287c1a1f71777b3258282844c8ea09558c68392935ed69bdd11e1f68cf0b751190b2c1d9ae8a36719b0ffe909a472d6f6932
7
+ data.tar.gz: e4431b150850a7d37c99dcbb754c62e6ecc500e01dc50eeb692a772e4f2af5af31b3ee181a49a76ef4f1a1537c408cbeef881e81f34235da684d69601591414e
data/bin/seo CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'seo-keywords-generator-ruby/cli'
3
+ # frozen_string_literal: true
4
4
 
5
- SeoKeywordsGeneratorCLI::CLI.start(ARGV)
5
+ # Enable local usage from cloned repo
6
+ require "seo-keywords-generator-ruby"
7
+
8
+ SeoKeywordsGenerator::CLI.new(ARGV).run
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.8
4
+ version: 0.1.10
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
@@ -36,7 +36,6 @@ extensions: []
36
36
  extra_rdoc_files: []
37
37
  files:
38
38
  - bin/seo
39
- - lib/seo-keywords-generator-ruby.rb
40
39
  homepage: https://github.com/chukhraiartur/seo-keywords-generator-ruby
41
40
  licenses:
42
41
  - MIT
@@ -1,129 +0,0 @@
1
- require 'google_search_results'
2
- require 'json'
3
- require 'csv'
4
-
5
-
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
29
-
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
- }
42
-
43
- search = GoogleSearch.new(params) # data extraction on the SerpApi backend
44
- results = search.get_hash # JSON -> Ruby hash
45
-
46
- results[:related_searches].map{ |result| result[:query] }.compact
47
- end
48
-
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)
66
- end
67
- end
68
- 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
-
84
- @related_questions_results = results[:related_questions]&.map{ |result| result[:question] }
85
-
86
- depth_limit = 4 if depth_limit > 4
87
-
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)
92
- end
93
- end
94
- 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] }
105
- end
106
- 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}")
121
- end
122
- end
123
- end
124
- end
125
-
126
- def print_data(data)
127
- puts JSON.pretty_generate(data)
128
- end
129
- end