Skip to content

Instantly share code, notes, and snippets.

@amolloy
Forked from rubysolo/generate-appshelf-import.rb
Created October 17, 2012 15:29
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 amolloy/3906160 to your computer and use it in GitHub Desktop.
Save amolloy/3906160 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
outfile = receipt_file + ".appshelf"
File.open(outfile, "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 / "div[@class='appname'] / 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 / "table tr th").map{|e| e.text }
values = (license / "table tr td").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