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.



5
6
7
8
# File 'lib/UrgentCare/Scraper.rb', line 5

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



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

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



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/UrgentCare/Scraper.rb', line 68

def get_appttime_date #retrieve waittime and add to new office model 
  sleep(5);
  if @@url[$index].url != "Not available"
    iframe_info = Nokogiri::HTML(@js_doc.html) 
    @wait_day = iframe_info.css('div.calendar').css('div.header').text
    @wait_time = iframe_info.css('div.row').css('div.time-slot')[0].text
    @@url[$index].next_available = "#{@wait_day} #{@wait_time}"
  else
    @@url[$index].next_available = "Not available"
  end
end

#get_clinic_siteObject



46
47
48
49
50
51
52
53
54
# File 'lib/UrgentCare/Scraper.rb', line 46

def get_clinic_site 
  if @@url[$index].url != "Not available"
    @@browser.goto(@@url[$index].url)
    @js_doc = @@browser.iframe.wait_until(&:present?)
    get_appttime_date
  else
    get_appttime_date
  end
end

#get_office_listObject

called first in CLI



34
35
36
37
# File 'lib/UrgentCare/Scraper.rb', line 34

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

#get_pageObject

page that lists all clinics



29
30
31
32
# File 'lib/UrgentCare/Scraper.rb', line 29

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



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

def make_office
  @off = @office.new 
  @off.name = @office_details.css('div.center-name').text
  if @office_details.css('div.center-appointment').css('a').count > 1
    @off.url = @office_details.css('div.center-appointment').css('a[href]')[1].values[1]
  else
    @off.url = "Not available"
  end
  @off.phone_number = @office_details.css('div.center-address').css('a').text
  @@url << @off
end

#office_urlObject



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

def office_url 
  @new_page.each do |office_details|  #does not create additional objects. returns original object
    @office_details = office_details
    make_office
  end
end