Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created March 8, 2010 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rubysolo/325458 to your computer and use it in GitHub Desktop.
Save rubysolo/325458 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
require 'nokogiri'
require 'time'
receipt_file = ARGV.shift || ''
if receipt_file.empty?
puts "please point me to your receipt file"
exit 1
end
doc = Nokogiri.HTML(IO.read(receipt_file))
def write_keypair(filehandle, name, value, type='string')
filehandle.puts "\t\t<key>#{name}</key>"
filehandle.puts "\t\t<#{type}>#{value}</#{type}>"
end
purchasedDate = Time.now.utc.iso8601
File.open("nano-bundle-3.appshelf", "w") do |out|
out.puts %Q{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
}
(doc / "div.license").each do |license|
link = (license / "h4 a").first
next unless link
out.puts "\t<dict>"
write_keypair(out, :appName, link.text)
write_keypair(out, :details, '')
# directoryName
write_keypair(out, :homepage, link.attribute('href'))
write_keypair(out, :price, '$19.95 (Bundle)')
write_keypair(out, :purchasedDate, purchasedDate, 'date')
# purchasedVersion
labels = (license / "dl dt").map{|e| e.text }
values = (license / "dl dd").map{|e| e.text }
registrationData = Hash[*labels.zip(values).flatten]
write_keypair(out, :registrationEmail, registrationData['Email:'])
write_keypair(out, :registrationName, registrationData['Name:'])
write_keypair(out, :registrationSerialKey, registrationData['Serial:'])
write_keypair(out, :wherePurchased, 'http://www.macheist.com')
out.puts "\t</dict>"
end
out.puts %Q{</array>\n</plist>}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment