store_list_scraper 0.1.0 → 0.1.1

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: e650f3c67053a0109587387c9d12df5c945f8f9630bb8cb139f6973e053ed33f
4
- data.tar.gz: 2113ca549c70e2d5883c7b237e92b35dc5e29d0f3869866ea7efa6d67ec87afd
3
+ metadata.gz: 92ed0896efae35de12e0fdc9721b35bb4c87b10f67e41ae9b8c2c9a50c18d8c9
4
+ data.tar.gz: c149378f7140be688d5235e89938999c4b31a3c9cf99161f5f6b4abf88a74a8c
5
5
  SHA512:
6
- metadata.gz: fde8993a8073480bdf0ab341da2045cfe5fdf0f4737a2a94dfedf5ee5d25584d4eaaf12c4d25e6b4e829e67422012be642ce76e8b2006612b1da1c873e59844c
7
- data.tar.gz: a9b80284fc00ebda3b92ef44c6d3cbaafc5a11ded88858975c5ea8e1034caf59d919402c68f544c7c23424df666a121c96148756d2680ec73a8185289f356612
6
+ metadata.gz: 2c726a4590d15e8a03cdd2b1416a1db00e07a6f8a473db102d65716e63b657f317b85ed67353730e5ae736d831143c06181930fd5422831cf6a7dcadc97425ee
7
+ data.tar.gz: 866d6560cc321744cd27ed56054a6bc624dd5cefcfa499c48f08335deb9f797a11859e68245606d32a6b27b06f4f9aac7128ce1b93cdeafd3370506f05b852ca
data/.DS_Store CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- store_list_scraper (0.1.0)
4
+ store_list_scraper (0.1.1)
5
5
  csv
6
6
  nokogiri (~> 1.13)
7
7
  open-uri
data/lib/.DS_Store ADDED
Binary file
@@ -56,11 +56,11 @@ class ListScraper::CLI
56
56
  when 1
57
57
  puts "Please type letter(s) you want at the START of the business name:"
58
58
  ListScraper::CSVmanager.list_view_by_letter(gets.strip)
59
- menu
59
+ list_validation
60
60
  when 2
61
61
  puts "Please type the keyword as you expect to see it in the business name.\n(example: 'Jimmy's Pizza' contains 'Pizza'"
62
62
  ListScraper::CSVmanager.list_view_by_search(gets.strip)
63
- menu
63
+ list_validation
64
64
  when 3
65
65
  menu
66
66
  else
@@ -69,11 +69,25 @@ class ListScraper::CLI
69
69
  end
70
70
  end
71
71
 
72
+ def list_validation
73
+ puts "\nSelect the number next to the business name you want to scrape\n OR type 'menu' to return to main menu."
74
+ input = gets.strip
75
+ if input == "menu"
76
+ menu
77
+ elsif ListScraper::CSVmanager.search_results[input.to_i] != nil
78
+ puts "Confirm you want to scrape (y/n):\n#{ListScraper::CSVmanager.search_results[input.to_i][0]}"
79
+ gets.strip.downcase == 'y' ? scrape(ListScraper::CSVmanager.search_results[input.to_i][1]): list_validation
80
+ else
81
+ puts "\n(ರ_ರ)\nThat is not a valid input.."
82
+ list_validation
83
+ end
84
+ end
85
+
72
86
  def scrape(link)
73
87
  a = ListScraper::LocationScraper.new("#{ListScraper::LocationScraper.base}#{link}")
74
88
  a.page_scrape(a.link)
75
89
  a.clean_out
76
- puts "\n( ◕‿◕)\nI found #{a.loc_pages.length} locations across #{a.state_pages.length}for this business.\nWould you like to export? (y/n)"
90
+ puts "\n( ◕‿◕)\nI found #{a.loc_pages.length} locations for this business.\nWould you like to export? (y/n)"
77
91
  confirmation = gets.strip
78
92
  if confirmation == 'y'
79
93
  puts "\n(°ロ°)☝\nWhat would you like to name the file?"
@@ -1,5 +1,6 @@
1
1
 
2
2
  class ListScraper::CSVmanager
3
+ @@search_results = {}
3
4
 
4
5
  def self.locations_export(name)
5
6
  c = CSV.open("#{name}.csv", "w")
@@ -18,11 +19,25 @@ class ListScraper::CSVmanager
18
19
 
19
20
  def self.list_view_by_letter(letter)
20
21
  g = CSV.read("./lib/storeListScraper/business_list.csv").select {|row| row[0].downcase.start_with?("#{letter.downcase}")}
21
- g.each {|item| puts item[0]}
22
+ ListScraper::CSVmanager.list_view_selection(g)
22
23
  end
23
24
 
24
25
  def self.list_view_by_search(word)
25
26
  g = CSV.read("./lib/storeListScraper/business_list.csv").select {|row| row[0].downcase.include?("#{word.downcase}")}
26
- g.each {|item| puts item[0]}
27
+ ListScraper::CSVmanager.list_view_selection(g)
28
+ end
29
+
30
+ def self.list_view_selection(g)
31
+ @@search_results.clear
32
+ i = 1
33
+ g.each do |item|
34
+ puts "#{i}: #{item[0]}"
35
+ @@search_results[i] = item
36
+ i += 1
37
+ end
38
+ end
39
+
40
+ def self.search_results
41
+ @@search_results
27
42
  end
28
43
  end
@@ -6,9 +6,9 @@ class ListScraper::UpdateScraper
6
6
  def initialize
7
7
  @base = 'https://storefound.org/'
8
8
  @letters = [] #array of links for each letter group
9
- @pages = [] #array to store pages for each letter
10
- File.delete('./lib/storeListScrapper/business_list.csv') if File.exist?('./lib/storeListScrapper/business_list.csv')
11
- @list = CSV.open("./lib/storeListScrapper/business_list.csv", "w")
9
+ @@pages = [] #array to store pages for each letter
10
+ File.delete('./lib/business_list.csv') if File.exist?('./lib/business_list.csv')
11
+ @list = CSV.open("./lib/storeListScraper/business_list.csv", "w")
12
12
  @list << ["Company Name", "link"] #headers
13
13
  update
14
14
  end
@@ -32,20 +32,21 @@ class ListScraper::UpdateScraper
32
32
 
33
33
  def pages_scrape(letter_link)
34
34
  #scrape all page links for each letter group
35
- @pages.clear
35
+ @@pages.clear
36
36
  doc = Nokogiri::HTML5(URI.open("#{@base}#{letter_link}"))
37
37
  doc.css('.pagination a').each do |lk|
38
- @pages << lk.attribute('href').text
38
+ @@pages << lk.attribute('href').text
39
39
  end
40
40
  end
41
41
 
42
42
  def update_business_list
43
43
  #scrape all business names and corresponding links
44
- @pages.each do |lk|
45
- doc = Nokogiri::HTML5(URI.open("#{@base}#{lk}"))
44
+ @@pages.each do |h|
45
+ doc = Nokogiri::HTML5(URI.open("#{@base}#{h}"))
46
46
  j = doc.css('.main-block .col-half a').each do |biz|
47
47
  @list << [biz.text, biz.attribute('href').text]
48
48
  end
49
49
  end
50
+ @@pages.clear
50
51
  end
51
52
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module ListScraper
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_list_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - itsmattpaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -96,6 +96,7 @@ files:
96
96
  - LICENSE.txt
97
97
  - README.md
98
98
  - Rakefile
99
+ - lib/.DS_Store
99
100
  - lib/List_Scraper.rb
100
101
  - lib/storeListScraper/business_list.csv
101
102
  - lib/storeListScraper/cli.rb