UrgentcareCLI 0.2.1 → 0.2.4

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: 1d62d9e62ebcc0e1b2318252471997712e2f515b1144ae192cb464fe4b496307
4
- data.tar.gz: a62a1ad60b8fbb783cb8bc21eb5d93a5d53665db357af52368b5f5795e4edb1d
3
+ metadata.gz: d08c3a8550ac9e5303232d496a6b848c5b55693e2156c1de8ddafb2287553baf
4
+ data.tar.gz: f1e3cd49f0e54c41d4918ada94e8b12ee9a2faa4fbd6856470247ad5bb3da242
5
5
  SHA512:
6
- metadata.gz: 3637e6bd4dd19d26d5d71945d589883f3f5a65d999fd9f81fc184a84e884e1f2ea8f23286a85a0698e2cab51d6b7a8ed70f7b73c45899fbd684d6e3674589c1b
7
- data.tar.gz: 76793ffbfcac85d94cc8e23a89814eb625a0f7419727436796aae16b9cebc6dc1559db607f08635d491b9d61f4c23b25b3d9e7f98da22586349f8cbc1c8bb5ab
6
+ metadata.gz: cb72119f5bdb980fd1351abff64b7fdc91b3f6230b335608c4c39a65a5f73934a5f41746fe8dbcba4c88cd2e74162e7ed35877db0a1fc6267f1d9cb553591397
7
+ data.tar.gz: ce10f3ef928361056eef160b2fc5d729c655ced8ce787646cdc486822c36fbbeea603e80f152c45805484b7d045b88bdd6984c7caf25aa4bf2a3c25fd6710d45
@@ -1,4 +1,14 @@
1
+ require_relative "./Office"
2
+ require_relative "./Scraper"
3
+
1
4
  class Urgentcare::CLI
5
+ #dependency injection to make code more testable
6
+ #remove strict dependency on other classes
7
+
8
+ def initialize(scraper: Urgentcare::Scraper.new, offices: Urgentcare::Office.all)
9
+ @scraper = scraper
10
+ @offices = offices
11
+ end
2
12
 
3
13
  def call
4
14
  welcome
@@ -6,55 +16,81 @@ class Urgentcare::CLI
6
16
 
7
17
  def welcome
8
18
  #puts displays with a new line
19
+ puts " "
20
+ puts " "
9
21
  puts "Welcome to the Urgent Care CLI"
10
22
  puts " "
11
23
  puts " "
24
+ puts " "
25
+ loading_message
26
+ office_list
27
+ end
28
+
29
+ def office_list
30
+ @scraper.get_office_list
12
31
  puts "Please choose a number from the following list for details on
13
32
  an Urgent Care location."
14
- puts " "
15
-
16
- Urgentcare::Scraper.new.get_clinics
17
- @clinics = Urgentcare::Office.all
18
- @clinics.each_with_index do |office, i|
33
+ puts " "
34
+ @offices.each_with_index do |office, i|
19
35
  puts "#{i + 1}. #{office.name}"
20
36
  end
21
- list
22
- end
37
+ list
38
+ end
23
39
 
24
40
  def list
25
41
  puts " "
26
- location = gets.chomp
42
+ location = $stdin.gets.chomp
27
43
  if location == "Exit" ||location == "exit"
28
44
  puts "Thank you and Goodbye!"
29
- else
30
- @index = location.to_i - 1
45
+ elsif location != "Exit" || location != "exit"
46
+ location = location.to_i
47
+ $index = location - 1
48
+ loading_message
49
+ @scraper.get_clinic_site
31
50
  office_details
51
+ else
52
+ puts "Invalid response"
32
53
  end
33
54
  end
34
55
 
35
56
  def office_details
36
- the_office = Urgentcare::Office.all
37
- if @index != "Exit" ||@index != "exit"
57
+ if $index != "Exit" || $index != "exit"
58
+ puts " "
59
+ puts " "
38
60
  puts " "
39
61
  puts "---"
40
- puts "Office Name: #{the_office[@index].name}"
41
- puts "Office Number: #{the_office[@index].phone_number}"
42
- puts "Office URL: #{the_office[@index].url}"
43
- puts "Office Next Available Appointment: #{the_office[@index].next_available}"
62
+ puts "Office Name: #{@offices[$index].name}"
63
+ puts "Office Number: #{@offices[$index].phone_number}"
64
+ puts "Office URL: #{@offices[$index].url}"
65
+ puts "Office Next Available Appointment: #{@offices[$index].next_available}"
44
66
  puts "---"
45
67
  puts " "
68
+ puts " "
69
+ puts " "
46
70
 
47
71
  else
48
72
  puts "No results found. Please try again."
49
73
  end
74
+ puts " "
75
+ puts " "
76
+ puts " "
50
77
  puts "Would you like to select another office from the list?"
51
78
  puts " "
52
- @clinics.each_with_index do |office, i|
53
- puts "#{i + 1}. #{office.name}"
54
- end
79
+ @offices.each_with_index do |office, i|
80
+ puts "#{i + 1}. #{office.name}"
81
+ end
55
82
  puts " "
56
83
  puts "If not, please type exit."
57
84
  puts " "
58
- list
85
+ list
59
86
  end
87
+
88
+ def loading_message
89
+ puts " "
90
+ puts "Retrieving data...."
91
+ puts "Loading......"
92
+ puts "............."
93
+ puts " "
94
+ end
95
+
60
96
  end
@@ -9,15 +9,11 @@ class Urgentcare::Office
9
9
  @url = url
10
10
  @next_available = next_available
11
11
  @phone_number = phone_number
12
- @@all << self
12
+ self.class.all << self #the class of this instance. abstracted away use of variable.
13
13
  end
14
14
 
15
15
  def self.all
16
16
  @@all
17
17
  end
18
18
 
19
- def self.clear
20
- @@all.clear
21
- end
22
-
23
19
  end
@@ -1,5 +1,12 @@
1
+ require 'webdrivers'
2
+
1
3
  class Urgentcare::Scraper
2
4
 
5
+ def initialize(office = Urgentcare::Office, scraper: Urgentcare::Scraper)
6
+ @office = office
7
+ @scraper = scraper
8
+ end
9
+
3
10
  def self.send_cmd(driver, cmd, params={}) #method by Hernando Torres- Rocca
4
11
  bridge = driver.send(:bridge)
5
12
  resource = "session/#{bridge.session_id}/chromium/send_command_and_get_result"
@@ -8,58 +15,59 @@ class Urgentcare::Scraper
8
15
  return response[:value]
9
16
  end
10
17
 
11
- #@ instance variable
12
18
  @@client = Selenium::WebDriver::Remote::Http::Default.new #class variable
13
19
  @@client.read_timeout = 3000 # seconds – default is 60
14
20
 
15
21
  @@browser = Watir::Browser.new :chrome, headless: true, http_client: @@client
16
22
  send_cmd(@@browser.driver, "Network.setBlockedURLs", {'urls': ["*careuc.netmng.com*"]}) #url pending when page loads
17
- send_cmd(@@browser.driver, "Network.enable")
23
+ send_cmd(@@browser.driver, "Network.enable")
18
24
 
25
+ @@clinic_page = @@browser.goto('https://www.carewellurgentcare.com/centers/')
19
26
 
20
- @@clinic_page = @@browser.goto('https://www.carewellurgentcare.com/centers/')
27
+ @@url = []
21
28
 
22
29
  def get_page # page that lists all clinics
23
30
  doc = @@browser.div(id: 'et-main-area').wait_until(&:present?)
24
31
  inner = Nokogiri::HTML(doc.inner_html) #return value of the method
25
32
  end
26
33
 
27
- def get_clinics #called first in CLI
28
- new_page = get_page.css('.centers-list')
29
- new_page.each_with_index do |office_details, index|
30
- make_office(office_details, index)
31
- if office_details.css('a').length > 3
32
- url = office_details.css('a')[3][name="href"]
33
- else
34
- url = office_details.css('a')[2][name="href"]
35
- end
36
- get_waittime(url)
37
- end
34
+ def get_office_list #called first in CLI
35
+ @new_page = get_page.css('.centers-list')
36
+ office_url
38
37
  end
39
-
40
- def get_waittime(url) #retrieve waittime and add to new office model
41
- @@browser.goto(url)
42
- js_doc = @@browser.iframe.wait_until(&:present?)
43
- if js_doc.button(data_id: "timeSelector").exists?
44
- @wait_time = js_doc.button(data_id: "timeSelector").text.gsub("\n", " ")
45
- Urgentcare::Office.all.last.next_available = @wait_time
46
- elsif js_doc.element(tag_name: 'h3').exists?
47
- @wait_time = js_doc.element(tag_name: 'h3').text
48
- Urgentcare::Office.all.last.next_available = @wait_time
49
- else
50
- @wait_time = "No time available"
51
- Urgentcare::Office.all.last.next_available = @wait_time
38
+
39
+ def office_url
40
+ @new_page.each do |office_details| #does not create additional objects. returns original object
41
+ @@url << office_details.css('a')[2][name="href"]
42
+ @office_details = office_details
43
+ make_office
52
44
  end
53
45
  end
54
46
 
55
- def make_office(office_details, index)
56
- office = Urgentcare::Office.new
57
- office.name = office_details.css('h2').text
58
- if office_details.css('a').length > 3
59
- office.url = office_details.css('a')[3][name="href"]
60
- else
61
- office.url = office_details.css('a')[2][name="href"]
47
+ def get_clinic_site
48
+ @@browser.goto(@@url[$index])
49
+ @js_doc = @@browser.iframe.wait_until(&:present?)
50
+ get_appttime_date
51
+ end
52
+
53
+ def make_office
54
+ @off = @office.new
55
+ @off.name = @office_details.css('h2').text
56
+ @off.url = @office_details.css('a')[2][name="href"]
57
+ @off.phone_number = @office_details.css('a[href]').text.gsub("Get DirectionsSave Your Spot in Line", "")
58
+ end
59
+
60
+ def get_appttime_date #retrieve waittime and add to new office model
61
+ sleep(1);
62
+ iframe_info = Nokogiri::HTML(@js_doc.html)
63
+ if !iframe_info.css('div.time-slots').empty?
64
+ @wait_day = iframe_info.css('div.d-flex.d-md-none.header').text
65
+ @wait_time = iframe_info.css('div.time-slot.selected').text
66
+ @office.all[$index].next_available = "#{@wait_day} #{@wait_time}"
67
+ else
68
+ @wait_time = "Walk-in only due to staffing shortages"
69
+ @office.all[$index].next_available = "#{@wait_time}"
62
70
  end
63
- office.phone_number = office_details.css('a[href]').text.gsub("Get DirectionsBook Urgent Care Appointment", " ")
64
71
  end
72
+
65
73
  end
@@ -1,3 +1,3 @@
1
1
  module Urgentcare
2
- VERSION = "0.2.1" #increment a version with each release
2
+ VERSION = "0.2.4" #increment a version with each release
3
3
  end #semantic versioning
data/lib/UrgentCare.rb CHANGED
@@ -7,7 +7,7 @@ require 'capybara'
7
7
 
8
8
 
9
9
  require_relative "./Urgentcare/CLI"
10
- require_relative "./Urgentcare/version" #why was this not a relative path?
10
+ require_relative "./Urgentcare/version"
11
11
  require_relative "./Urgentcare/Office"
12
12
  require_relative "./Urgentcare/Scraper"
13
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: UrgentcareCLI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PamelaTorres-Rocca
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: gem-release
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: nokogiri
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,10 +94,11 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: 1.11.4
83
- description:
97
+ description: Current Urgent Care wait times in Massachusetts based on location
84
98
  email:
85
- - pfrieze@gmail.com
86
- executables: []
99
+ - pamela@torres-rocca.com
100
+ executables:
101
+ - Urgentcare
87
102
  extensions: []
88
103
  extra_rdoc_files: []
89
104
  files:
@@ -95,10 +110,11 @@ files:
95
110
  - lib/UrgentCare/Office.rb
96
111
  - lib/UrgentCare/Scraper.rb
97
112
  - lib/UrgentCare/version.rb
98
- homepage: https://github.com/Pamela454/Pamela-cli-app.git
113
+ homepage: https://github.com/Pamela454/Pamela-cli-app
99
114
  licenses:
100
115
  - MIT
101
- metadata: {}
116
+ metadata:
117
+ source_code_uri: https://github.com/Pamela454/Pamela-cli-app
102
118
  post_install_message:
103
119
  rdoc_options: []
104
120
  require_paths:
@@ -114,8 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
130
  - !ruby/object:Gem::Version
115
131
  version: '0'
116
132
  requirements: []
117
- rubygems_version: 3.1.3
133
+ rubygems_version: 3.0.1
118
134
  signing_key:
119
135
  specification_version: 4
120
- summary: Current Urgent Care wait times in Massachusetts based on location.
136
+ summary: UrgentCareCLI Gem
121
137
  test_files: []