Update of /cvsroot/freevo/freevo/src/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14635
Modified Files: amazon.py Log Message: Updated from upstream (http://www.josephson.org/projects/pyamazon/) Also, modified to account for recent Amazon XML changes. Works again. Index: amazon.py =================================================================== RCS file: /cvsroot/freevo/freevo/src/util/amazon.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** amazon.py 25 Jan 2004 14:52:22 -0000 1.2 --- amazon.py 21 Apr 2004 15:22:51 -0000 1.3 *************** *** 1,4 **** - # WARNING: small changes made for Freevo. Look for 'FREEVO' in the code - """Python wrapper --- 1,2 ---- *************** *** 57,61 **** __author__ = "Mark Pilgrim ([EMAIL PROTECTED])" ! __version__ = "0.61" __cvsversion__ = "$Revision$"[11:-2] __date__ = "$Date$"[7:-2] --- 55,59 ---- __author__ = "Mark Pilgrim ([EMAIL PROTECTED])" ! __version__ = "0.62" __cvsversion__ = "$Revision$"[11:-2] __date__ = "$Date$"[7:-2] *************** *** 63,69 **** __license__ = "Python" # Powersearch and return object type fix by Joseph Reagle <[EMAIL PROTECTED]> from xml.dom import minidom ! import os, sys, getopt, cgi, urllib try: import timeoutsocket # http://www.timo-tasi.org/python/timeoutsocket.py --- 61,68 ---- __license__ = "Python" # Powersearch and return object type fix by Joseph Reagle <[EMAIL PROTECTED]> + # Locale support by Michael Josephson <[EMAIL PROTECTED]> from xml.dom import minidom ! import os, sys, getopt, cgi, urllib, string try: import timeoutsocket # http://www.timo-tasi.org/python/timeoutsocket.py *************** *** 74,77 **** --- 73,77 ---- LICENSE_KEY = None HTTP_PROXY = None + LOCALE = "us" # don't touch the rest of these constants *************** *** 91,94 **** --- 91,100 ---- (lambda key: _contentsOf(_getScriptDir(), _amazonfile2), '%s in the amazon.py directory' % _amazonfile2) ) + _supportedLocales = { + "us" : (None, "xml.amazon.com"), + "uk" : ("uk", "xml-eu.amazon.com"), + "de" : ("de", "xml-eu.amazon.com"), + "jp" : ("jp", "xml.amazon.com") + } ## administrative functions *************** *** 100,103 **** --- 106,123 ---- ## utility functions + + def setLocale(locale): + """set locale""" + global LOCALE + if _supportedLocales.has_key(locale): + LOCALE = locale + else: + raise AmazonError, ("Unsupported locale. Locale must be one of: %s" % + string.join(_supportedLocales, ", ")) + + def getLocale(): + """get locale""" + return LOCALE + def setLicense(license_key): """set license key""" *************** *** 173,188 **** rc = "".join([e.data for e in element.childNodes if isinstance(e, minidom.Text)]) if element.tagName == 'SalesRank': ! # FREEVO CHANGES: add '.' as replacement ! rc = int(rc.replace(',', '').replace('.', '')) return rc ! def buildURL(search_type, keyword, product_line, type, page, license_key, lang='us'): ! if lang=='us': ! url = "http://xml.amazon.com/onca/xml?v=1.0&f=xml&t=webservices-20" ! else: ! url = "http://xml-eu.amazon.com/onca/xml?v=1.0&f=xml&t=webservices-20" ! url += "&locale=%s" % lang url += "&dev-t=%s" % license_key.strip() url += "&type=%s" % type if page: url += "&page=%s" % page --- 193,205 ---- rc = "".join([e.data for e in element.childNodes if isinstance(e, minidom.Text)]) if element.tagName == 'SalesRank': ! rc = int(rc.replace(',', '')) return rc ! def buildURL(search_type, keyword, product_line, type, page, license_key): ! url = "http://" + _supportedLocales[LOCALE][1] + "/onca/xml2?v=1.0&f=xml&t=webservices-20" url += "&dev-t=%s" % license_key.strip() url += "&type=%s" % type + if _supportedLocales[LOCALE][0]: + url += "&locale=%s" % _supportedLocales[LOCALE][0] if page: url += "&page=%s" % page *************** *** 197,201 **** def search(search_type, keyword, product_line, type="heavy", page=None, ! license_key = None, http_proxy = None, lang='us'): """search Amazon --- 214,218 ---- def search(search_type, keyword, product_line, type="heavy", page=None, ! license_key = None, http_proxy = None): """search Amazon *************** *** 243,266 **** """ license_key = getLicense(license_key) ! url = buildURL(search_type, keyword, product_line, type, page, license_key, lang=lang) proxies = getProxies(http_proxy) u = urllib.FancyURLopener(proxies) usock = u.open(url) ! try: ! xmldoc = minidom.parse(usock) ! data = unmarshal(xmldoc).ProductInfo ! except ExpatError, e: ! # FREEVO CHANGES: catch error and go on ! data = Bag() ! data.ErrorMsg = e usock.close() if hasattr(data, 'ErrorMsg'): - # FREEVO CHANGES: try other lang - # TODO: find more urls - if lang == 'us': - return search(search_type, keyword, product_line, type, page, license_key, http_proxy, 'uk') - if lang == 'uk': - return search(search_type, keyword, product_line, type, page, license_key, http_proxy, 'de') raise AmazonError, data.ErrorMsg else: --- 260,275 ---- """ license_key = getLicense(license_key) ! url = buildURL(search_type, keyword, product_line, type, page, license_key) proxies = getProxies(http_proxy) u = urllib.FancyURLopener(proxies) usock = u.open(url) ! xmldoc = minidom.parse(usock) ! ! # from xml.dom.ext import PrettyPrint ! # PrettyPrint(xmldoc) usock.close() + data = unmarshal(xmldoc).ProductInfo if hasattr(data, 'ErrorMsg'): raise AmazonError, data.ErrorMsg else: ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Freevo-cvslog mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/freevo-cvslog