Class: BuergerBot::Robot
- Inherits:
-
Object
- Object
- BuergerBot::Robot
- Defined in:
- lib/buergerbot/bot/robot.rb
Overview
Robot is the main class of the Buerger::Bot gem.
Instance Method Summary collapse
- #found_appointment?(browser, service_url) ⇒ Boolean
-
#initialize ⇒ Robot
constructor
A new instance of Robot.
- #make_url(service = BLAUE_KARTE) ⇒ Object
- #promt_user ⇒ Object
- #run ⇒ Object
Constructor Details
Instance Method Details
#found_appointment?(browser, service_url) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/buergerbot/bot/robot.rb', line 44 def found_appointment?(browser, service_url) browser.goto service_url link = browser.element css: '.calendar-month-table:first-child td.buchbar a' if link.exists? link.click promt_user end false rescue StandardError => e Logger.fail(e.inspect) false end |
#make_url(service = BLAUE_KARTE) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/buergerbot/bot/robot.rb', line 28 def make_url(service = BLAUE_KARTE) init_params = PERM_PARAMS with_location_params = DIENSTLEISTER.reduce(init_params) do |query, dl| query + "&dienstleister[]=#{dl}" end BASE_URL + with_location_params + "&anliegen[]=#{service}" end |
#promt_user ⇒ Object
38 39 40 41 42 |
# File 'lib/buergerbot/bot/robot.rb', line 38 def promt_user Notifications.notify 'Appointment found!', open_chrome: true Logger.log 'Press y to keep looking for appointments, any other key to exit' gets.chomp.downcase != 'y' end |
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/buergerbot/bot/robot.rb', line 57 def run Logger.log "Starting #{@name}..." browser = Watir::Browser.new :chrome # Logger.log "Enter Service ID or 0 for default (#{BLAUE_KARTE}):" # service = gets.chomp.to_i # service = BLAUE_KARTE if service.zero? || service.nil? service_url = make_url BLAUE_KARTE until found_appointment?(browser, service_url) Logger.log 'No appointment found, retrying in 25 seconds...' sleep 25 Logger.log "#{'-' * 80}\nTrying again" end end |