Class: Urgentcare::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/UrgentCare/Scraper.rb

Constant Summary collapse

@@client =

class variable

Selenium::WebDriver::Remote::Http::Default.new
@@browser =
Watir::Browser.new :chrome, headless: true, http_client: @@client
@@clinic_page =
@@browser.goto('https://www.carewellurgentcare.com/centers/')
@@url =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper) ⇒ Scraper

Returns a new instance of Scraper.



3
4
5
6
# File 'lib/UrgentCare/Scraper.rb', line 3

def initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper)
  @office = office 
  @scraper = scraper 
end

Class Method Details

.send_cmd(driver, cmd, params = {}) ⇒ Object

method by Hernando Torres- Rocca



8
9
10
11
12
13
14
# File 'lib/UrgentCare/Scraper.rb', line 8

def self.send_cmd(driver, cmd, params={})  #method by Hernando Torres- Rocca
  bridge = driver.send(:bridge)
  resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result"
  response = bridge.http.call(:post, resource, {'cmd':cmd, 'params': params})
  raise response[:value] if response[:status]
  return response[:value]
end

Instance Method Details

#get_appttime_dateObject

retrieve waittime and add to new office model



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/UrgentCare/Scraper.rb', line 58

def get_appttime_date #retrieve waittime and add to new office model 
  sleep(1);
  iframe_info = Nokogiri::HTML(@js_doc.html) 
  if iframe_info.css('div.time-slots')
    @wait_day = iframe_info.css('div.d-flex.d-md-none.header').text
    @wait_time = iframe_info.css('div.time-slot.selected').text
    @office.all[$index].next_available = "#{@wait_day} #{@wait_time}"
  else   
    @wait_time = "No time available"
    @office.all[$index].next_available = "#{@wait_time}"
  end
end

#get_clinic_siteObject



45
46
47
48
49
# File 'lib/UrgentCare/Scraper.rb', line 45

def get_clinic_site 
  @@browser.goto(@@url[$index]) 
  @js_doc = @@browser.iframe.wait_until(&:present?) 
  get_appttime_date
end

#get_office_listObject

called first in CLI



32
33
34
35
# File 'lib/UrgentCare/Scraper.rb', line 32

def get_office_list #called first in CLI
  @new_page = get_page.css('.centers-list')
  office_url
end

#get_pageObject

page that lists all clinics



27
28
29
30
# File 'lib/UrgentCare/Scraper.rb', line 27

def get_page # page that lists all clinics 
  doc = @@browser.div(id: 'et-main-area').wait_until(&:present?)
  inner = Nokogiri::HTML(doc.inner_html)  #return value of the method 
end

#make_officeObject



51
52
53
54
55
56
# File 'lib/UrgentCare/Scraper.rb', line 51

def make_office
  @off = @office.new 
  @off.name = @office_details.css('h2').text
  @off.url = @office_details.css('a')[2][name="href"]
  @off.phone_number = @office_details.css('a[href]').text.gsub("Get DirectionsBook Urgent Care Appointment", " ")
end

#office_urlObject



37
38
39
40
41
42
43
# File 'lib/UrgentCare/Scraper.rb', line 37

def office_url 
  @new_page.each do |office_details|  #does not create additional objects. returns original object
    @@url << office_details.css('a')[2][name="href"]
    @office_details = office_details
    make_office
  end
end