Created
December 18, 2014 17:02
-
-
Save stevegraham/cc43b2b41debaeb98cbe to your computer and use it in GitHub Desktop.
#20YearsOfCharacters #DealWithIt
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
require 'net/http' | |
require 'logger' | |
require 'mechanize' | |
logger = Logger.new(STDOUT) | |
req = Net::HTTP::Get.new '/' | |
drop_time = Time.local 2014, 12, 19, 12 | |
req['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10" | |
def fill_in_form(at: url) | |
agent = Mechanize.new do |a| | |
a.user_agent_alias = 'Mac Safari' | |
end | |
agent.get(at) do |p| | |
p.form_with id: 'form1994' do |f| | |
f.firstName = 'John' | |
f.lastName = 'Smith' | |
f.addressLine = '123 Main Street' | |
f.addressTown = 'Anytown' | |
f.Country = "UK" | |
f.postCode = 'AT1 LOL' | |
f.emailAddress = '[email protected]' | |
f.phoneNumber = '02071231234' | |
f.submit | |
end | |
end | |
end | |
Net::HTTP.start 'ps20.software.eu.playstation.com', 80 do |http| | |
loop do | |
if Time.now < drop_time # Don't want to submit earlier than drop time | |
seconds = drop_time - Time.now | |
logger.info "Way too early, dude. Going back to sleep for #{seconds} seconds" | |
sleep seconds | |
end | |
token = http.request(req).body.match(/(?<=config\.sp = ")\w+/)[0] | |
case token | |
when "PBD" | |
logger.info "New URL not published yet" | |
sleep 1 | |
when nil | |
logger.fatal "The jig is up" | |
exit 1 | |
else | |
url = http.get("/redirect.php?sp=#{token}").body | |
logger.info "BINGO! #{url}" | |
logger.info "Filling in form..." | |
fill_in_form at: url | |
logger.info "Done. Good luck!" | |
exit 0 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment