Skip to content

Instantly share code, notes, and snippets.

@csima
Last active October 27, 2015 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csima/6153387e7a9bad24ef30 to your computer and use it in GitHub Desktop.
Save csima/6153387e7a9bad24ef30 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# You can get a sparkpost / pushbullet api token by just signing up
# Modify the @airport var with the text of the dropdown box that is on the website for choosing a location for the appointment
@username = ''
@password = ''
@months = 2
@notify_subject = 'Global Entry Dates'
@email_from = 'from@test.com'
@email_to = 'to@test.com'
@email_return = 'bounce@test.com'
@pushbullet_token = ''
@sparkpost_token = ''
@airport = 'San Francisco Global Entry Enrollment Center - San Francisco International Airport, San Francisco, CA 94128, US'
require 'watir-webdriver'
require 'nokogiri'
require 'pry'
def print_available(html)
data = Nokogiri::HTML(html)
days = data.css('div[id^="scheduleForm:schedule1_body"]')
dates = ""
days.each do |day|
if day.text == 'A'
date = day.attributes['id'].value
puts date
dates = dates + date + ', '
end
end
if dates.empty? == false
success(dates)
end
end
##################################################
# Put whatever you want to do with the dates here
##################################################
def success(dates)
puts dates
send_email(dates)
send_notification(dates)
end
# Send notification via Push Bullet for mobile
def send_notification(data)
`curl --header 'Access-Token: #{@pushbullet_token}' \
--header 'Content-Type: application/json' \
--data-binary '{"body":"#{data}","title":"#{@notify_subject}","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes`
end
# Send email using sparkpost API
def send_email(data)
payload = '{"options":{"open_tracking":true,"click_tracking":true},"return_path":"::email_return::","substitution_data":{"link":"::data::"},"recipients":[{"address":{"email":"::email_to::","tags":["learning"]}}],"content":{"from":{"name":"Alert","email":"::email_from::"},"subject":"::notify_subject::","reply_to":"Alert","text":"::notify_subject:::\r\n{{link}}"}}'
payload.gsub!("::data::",data)
payload.gsub!("::email_from::", @email_from)
payload.gsub!("::email_to::", @email_to)
payload.gsub!("::email_return::", @email_return)
payload.gsub!("::notify_subject::", @notify_subject)
output = `curl -H "Content-Type: application/json" -H "Authorization: #{@sparkpost_token}" -X POST -d '#{payload}' https://api.sparkpost.com/api/v1/transmissions`
end
b = Watir::Browser.new
b.goto 'https://goes-app.cbp.dhs.gov'
b.text_field(:id => 'user').set @username
b.text_field(:id => 'password').set @password
b.button(:id => 'SignIn').click
l = b.link :text => 'Enter'
l.exists?
l.click
b.button(:value => 'Manage Interview Appointment').click
b.button(:value => 'Reschedule Appointment').click
selection = b.select_list :id => 'selectedEnrollmentCenter'
# Grab the text of the dropdown of your selected airport and put it here
selection.select "#{@airport}"
selection.selected_options
b.button(:value => 'Next').click
b.link(:text => 'Today').click
b.link(:text => 'Monthly').click
@months.times do
print_available(b.html)
# Click on the next month
b.link(:text => '>').click
end
at_exit { b.close }
#b.send_keys [:command, :shift, 'W']
@csima
Copy link
Author

csima commented Oct 27, 2015

Run in cronjob every 15 or 30m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment