aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws/parts.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
committerFilipp Lepalaan <f@230.to>2013-05-12 22:34:53 +0300
commitaaacaebb861beaf2ef39b6bc54db2d12262e9b0d (patch)
tree2d373fc7d04ab03f87bfe5e4d13f36d6d7bc81a5 /gsxws/parts.py
parent452005bbb83059913d4c8b7648d9e368936e53da (diff)
downloadpy-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.gz
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.tar.bz2
py-gsxws-aaacaebb861beaf2ef39b6bc54db2d12262e9b0d.zip
More speed, more power, less suds, WIP
Diffstat (limited to 'gsxws/parts.py')
-rw-r--r--gsxws/parts.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/gsxws/parts.py b/gsxws/parts.py
new file mode 100644
index 0000000..8240096
--- /dev/null
+++ b/gsxws/parts.py
@@ -0,0 +1,25 @@
+import urllib
+import tempfile
+from core import GsxObject, GsxError
+
+
+class Part(GsxObject):
+ def lookup(self):
+ lookup = Lookup(**self.data)
+ return lookup.parts()
+
+ def fetch_image(self):
+ """
+ Tries the fetch the product image for this service part
+ """
+ if self.partNumber is None:
+ raise GsxError("Cannot fetch part image without part number")
+
+ image = '%s_350_350.gif' % self.partNumber
+ url = 'https://km.support.apple.com.edgekey.net/kb/imageService.jsp?image=%s' % image
+ tmpfile = tempfile.mkstemp(suffix=image)
+
+ try:
+ return urllib.urlretrieve(url, tmpfile[1])[0]
+ except Exception, e:
+ raise GsxError('Failed to fetch part image: %s' % e)