Last active
December 3, 2015 19:30
-
-
Save zl4bv/3c86fee33151e669e22e to your computer and use it in GitHub Desktop.
Claim today's Wellington Advent Calendar treat
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
# Fill in the following parameters: | |
params = { | |
'name_first' => '', | |
'name_last' => '', | |
'email' => '', | |
'region' => 'Wellington City' | |
} | |
# NOTE: You need to have the `nokogiri` gem installed | |
# | |
# Add the following to your crontab to get each treat automatically emailed to you | |
# at 1 AM each day: | |
# | |
# 0 1 * * * ruby advent.rb | |
require 'date' | |
require 'json' | |
require 'nokogiri' | |
require 'open-uri' | |
exit unless Date.today.month == 12 | |
url = 'http://advent.wellingtonnz.com' | |
doc = Nokogiri.HTML(open(url)) | |
inline = doc.xpath('//script[not(@src)]').map(&:text) | |
data = inline.map{ |js| js[/window\.data = (\[.+?\]);/,1] }.compact[0] | |
json = JSON.parse(data) | |
params['terms'] = 1 | |
params['sign_up'] = 0 | |
params['offer'] = json[Time.now.mday-1]['id'] | |
Net::HTTP.post_form(URI.parse("#{url}/redeem"), params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment