diff options
Diffstat (limited to 'gsxws/parts.py')
-rw-r--r-- | gsxws/parts.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/gsxws/parts.py b/gsxws/parts.py index a371ea3..536c6aa 100644 --- a/gsxws/parts.py +++ b/gsxws/parts.py @@ -1,11 +1,19 @@ import urllib import tempfile + +from lookups import Lookup from core import GsxObject, GsxError class Part(GsxObject): + """ + A service part + + >>> Part('922-7913').lookup().stockPrice + 6.16 + """ def lookup(self): - lookup = Lookup(**self.data) + lookup = Lookup(**self._data) return lookup.parts() def fetch_image(self): @@ -15,19 +23,21 @@ class Part(GsxObject): 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 + 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) + raise GsxError("Failed to fetch part image: %s" % e) if __name__ == '__main__': + import sys import doctest + import logging from core import connect logging.basicConfig(level=logging.DEBUG) - connect(*sys.argv[1:4]) + connect(*sys.argv[1:5]) doctest.testmod() |