if anyone is interested I have a python prototype of @glarriza’s warranty ruby script that spits all keys out as a dict
I would have used his but I am writing something in python that needed this directly and I did not want to call an external command.
I really should be parsing here but I was in a hurry.
#!/usr/bin/python
import ast
import plistlib
import urllib2
import subprocess
system_profiler = "/usr/sbin/system_profiler"
# Generic system_profiler parser
def systemReport():
global spx
spx = {}
# This is our key value schema
SPHardwareDataType = {
'serial': 'serial_number',
}
_dataTypes = {
'SPHardwareDataType': SPHardwareDataType,
}
dataTypes = _dataTypes.keys()
# run the system_profiler command with data types
arguments = [system_profiler,"-xml"] + dataTypes
getspx = subprocess.Popen(arguments, stdout=subprocess.PIPE)
spxOut, err = getspx.communicate()
rootObject = plistlib.readPlistFromString(spxOut)
# Parse datatype top level keys below
for array in rootObject:
for _dataType in _dataTypes:
if array['_dataType'] == _dataType:
_dataTypeSchema = _dataTypes[_dataType]
for key in _dataTypeSchema:
for item in array['_items']:
# add a key to our dict per the schema
spx[key] = item[_dataTypeSchema[key]]
# generate a xml plist so NSPropertyListSerialization is overkill here
systemReport()
# Generate the URL by concatenating the string
url = 'http://selfsolve.apple.com/warrantyChecker.do?sn=' + spx['serial'] + '&country=USA'
request = urllib2.Request(url)
httpResult = urllib2.urlopen(request)
# remove the "^null" string to make tuple with dict inside
warranty = ast.literal_eval(httpResult.read()[4:])
# Just an example of how to parse the data
#for key in warranty: print "%s\t%s" % (key,warranty[key])
print plistlib.writePlistToString(warranty)