seo-keywords-generator-ruby 0.1.9 → 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: 3fcce4a4dae84b3eea8abefcf4dce39f10f9084c2b2f1ca90c5cb5e14ee06ab5
4
- data.tar.gz: b0aa67a12d6d680e70f87793a4da42cd90f440209936aafb0e685dd049c2240b
3
+ metadata.gz: 052c7c699617cde9c463a1e9c2dc8c04e8c3529ac0e6398dce3f9b416007607a
4
+ data.tar.gz: 00ac688665e5e523d3d50df0b60498944f93eafaabf00f836cf6cfc3602d77b7
5
5
  SHA512:
6
- metadata.gz: 93c5ac9430262fbb10f3a4654595718e980f3a3941011e58404285ca6e69809a53f866e85bcc49c67837df263b75f8fc2cc12ee8e36c97e1316f1a7ac54d1f83
7
- data.tar.gz: 336d24b436d53d7c83a42fc5dd236ee6fe019286c5e324e70ce2769cdbf37b2bf2947f5b045e05ac942d413ed3ea011dbdccc260b201ad40299799fdacbab6ed
6
+ metadata.gz: c023cb016e1a0bd88e0e9536273e287c1a1f71777b3258282844c8ea09558c68392935ed69bdd11e1f68cf0b751190b2c1d9ae8a36719b0ffe909a472d6f6932
7
+ data.tar.gz: e4431b150850a7d37c99dcbb754c62e6ecc500e01dc50eeb692a772e4f2af5af31b3ee181a49a76ef4f1a1537c408cbeef881e81f34235da684d69601591414e
data/bin/seo CHANGED
@@ -3,9 +3,6 @@
3
3
  # frozen_string_literal: true
4
4
 
5
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
6
  require "seo-keywords-generator-ruby"
10
7
 
11
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.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Chukhrai
@@ -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,132 +0,0 @@
1
- require 'google_search_results'
2
- require 'json'
3
- require 'csv'
4
-
5
- module SeoKeywordsGenerator
6
- autoload :CLI, "seo-keywords-generator-ruby/cli"
7
-
8
- class Scraper
9
- attr_accessor :query, :api_key, :lang, :country, :domain
10
-
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
19
-
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
34
-
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
50
-
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
69
- end
70
- end
71
- end
72
-
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
97
-
98
- @related_questions_results
99
- end
100
-
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] }
107
- end
108
- end
109
- end
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))
114
- end
115
- end
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
124
- end
125
- end
126
- end
127
-
128
- def print_data(data)
129
- puts JSON.pretty_generate(data)
130
- end
131
- end
132
- end