Last active
October 27, 2015 00:42
-
-
Save csima/6153387e7a9bad24ef30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run in cronjob every 15 or 30m