; = Dc @s6dZdZdZddd!Zddd!ZdZd Zd klZd k Z d k Z d k Z d k Z d k Z d kZyd kZeid Wnej onXead aeadadefdYZdefdYZdZdZddfddfddfddefddefddefd defd!d"efd#d"eff Zhded$f<d%d%d&f<d'd'd&f<d(d(d)f<d*d*d+f<d,d,d-fZ-d?eeeeed@Z.dAd?dBeeeedCZ/dAd?dBeeeedDZ0d?eeeedEZ1d?eeeedFZ2d?dBeeeedGZ3dHd?dBeeeedIZ4dJd?dBeeeedKZ5dJd?dBeeeedLZ6dMd?dBeeeedNZ7d?dBeeeedOZ8d?dBeeeedPZ9d?dBeeeedQZ:dAd?dBeeeedRZ;d?dBeeeedSZ<d S(TsPython wrapper for Amazon web APIs This module allows you to access Amazon's web APIs, to do things like search Amazon and get the results programmatically. Described here: http://www.amazon.com/webservices You need a Amazon-provided license key to use these services. Follow the link above to get one. These functions will look in several places (in this order) for the license key: - the "license_key" argument of each function - the module-level LICENSE_KEY variable (call setLicense once to set it) - an environment variable called AMAZON_LICENSE_KEY - a file called ".amazonkey" in the current directory - a file called "amazonkey.txt" in the current directory - a file called ".amazonkey" in your home directory - a file called "amazonkey.txt" in your home directory - a file called ".amazonkey" in the same directory as amazon.py - a file called "amazonkey.txt" in the same directory as amazon.py Sample usage: >>> import amazon >>> amazon.setLicense('...') # must get your own key! >>> pythonBooks = amazon.searchByKeyword('Python') >>> pythonBooks[0].ProductName u'Learning Python (Help for Programmers)' >>> pythonBooks[0].URL ... >>> pythonBooks[0].OurPrice ... Other available functions: - browseBestSellers - searchByASIN - searchByUPC - searchByAuthor - searchByArtist - searchByActor - searchByDirector - searchByManufacturer - searchByListMania - searchSimilar - searchByWishlist Other usage notes: - Most functions can take product_line as well, see source for possible values - All functions can take type="lite" to get less detail in results - All functions can take page=N to get second, third, fourth page of results - All functions can take license_key="XYZ", instead of setting it globally - All functions can take http_proxy="http://x/y/z" which overrides your system setting s$Mark Pilgrim (f8dy@diveintomark.org)s0.64.1s$Revision: 1.7 $i is$Date: 2004/09/25 16:59:23 $isCopyright (c) 2002 Mark PilgrimsPython(sminidomNi swebservices-20suss AmazonErrorcBstZRS(N(s__name__s __module__(((s./Amazon/amazon.pys AmazonErrorYss NoLicenseKeycBstZRS(N(s__name__s __module__(((s./Amazon/amazon.pys NoLicenseKeyZss .amazonkeys amazonkey.txtcCs|S(N(skey(skey((s./Amazon/amazon.pys^ss.passed to the function in license_key variablecCstS(N(s LICENSE_KEY(skey((s./Amazon/amazon.pys_ss=module-level LICENSE_KEY variable (call setLicense to set it)cCstiidtS(NsAMAZON_LICENSE_KEY(sossenvironsgetsNone(skey((s./Amazon/amazon.pys`ss1an environment variable called AMAZON_LICENSE_KEYcCsttitS(N(s _contentsOfsossgetcwds _amazonfile1(skey((s./Amazon/amazon.pysass%s in the current directorycCsttitS(N(s _contentsOfsossgetcwds _amazonfile2(skey((s./Amazon/amazon.pysbscCsttiiddtS(NsHOMEs(s _contentsOfsossenvironsgets _amazonfile1(skey((s./Amazon/amazon.pyscss%s in your home directorycCsttiiddtS(NsHOMEs(s _contentsOfsossenvironsgets _amazonfile2(skey((s./Amazon/amazon.pysdscCstttS(N(s _contentsOfs _getScriptDirs _amazonfile1(skey((s./Amazon/amazon.pysess%s in the amazon.py directorycCstttS(N(s _contentsOfs _getScriptDirs _amazonfile2(skey((s./Amazon/amazon.pysfssxml.amazon.comsuksxml-eu.amazon.comsdesjpsxml.amazon.co.jpsfrs xml.amazon.frscas xml.amazon.cacCsdtGHdS(NsAPyAmazon %(__version__)s %(__copyright__)s released %(__date__)s (sglobals(((s./Amazon/amazon.pysversionrscCs |adS(N(s associates ASSOCIATE(s associate((s./Amazon/amazon.pys setAssociatexscCs|ptSdS(N(soverrides ASSOCIATE(soverride((s./Amazon/amazon.pys getAssociate|scCs2ti| otdtitdndS(Ns-Unsupported locale. Locale must be one of: %ss, (s_supportedLocalesshas_keyslocales AmazonErrorsstringsjoin(slocale((s./Amazon/amazon.pys_checkLocaleSupportedscCst||adS(s set localeN(s_checkLocaleSupportedslocalesLOCALE(slocale((s./Amazon/amazon.pys setLocales cCs|ptSdS(s get localeN(slocalesLOCALE(slocale((s./Amazon/amazon.pys getLocalescCs |adS(sset license keyN(s license_keys LICENSE_KEY(s license_key((s./Amazon/amazon.pys setLicensescCs?x/tD]'\}}||}|o|SqqWtddS(slget license key license key can come from any number of locations; see module docs for search orders6get a license key at http://www.amazon.com/webservicesN(s_licenseLocationssgetslocations license_keysrcs NoLicenseKey(s license_keysgetslocationsrc((s./Amazon/amazon.pys getLicenses   cCs |adS(sset HTTP proxyN(s http_proxys HTTP_PROXY(s http_proxy((s./Amazon/amazon.pyssetProxyscCs|ptSdS(sget HTTP proxyN(s http_proxys HTTP_PROXY(s http_proxy((s./Amazon/amazon.pysgetProxyscCs4t|}|ohd|<}nt}|SdS(Nshttp(sgetProxys http_proxysproxiessNone(s http_proxysproxies((s./Amazon/amazon.pys getProxiess  cCsatii||}tii| otSnt|}|i i }|i |SdS(N( sosspathsjoinsdirnamesfilenamesexistssNonesopensfsocksreadsstripscontentssclose(sdirnamesfilenamesfsockscontents((s./Amazon/amazon.pys _contentsOfs  cCs^tdjo'tiitiitidSn'tiitiititiSdS(Ns__main__i( s__name__sosspathsabspathsdirnamessyssargvsmoduless__file__(((s./Amazon/amazon.pys _getScriptDirs 'sBagcBstZRS(N(s__name__s __module__(((s./Amazon/amazon.pysBagscCs&t}t|tio |idjo|idi|_ ngi }|i D]'}t|tio||qTqT~}|ox|D]}|i}t||oltt||tgjo t||t||gnt||t||t|gqt|tio |idjot||t|gqt||t|qWndigi }|i D]*}t|tio||iqq~}|idjoF|idd}|idd}|idd}t|}n|SdS(NsDetailssurlss SalesRanks.s,s (sBagsrcs isinstanceselementsminidomsElementstagNames attributessvaluesURLsappends_[1]s childNodesses childElementsschildskeyshasattrstypesgetattrssetattrs unmarshalsjoinsTextsdatasreplacesint(selements childElementsseschilds_[1]skeysrc((s./Amazon/amazon.pys unmarshals, #A " *#Mc Cst|dt|dd}|d|7}|d|i7}|d|7}t|do|dt|d7}n|o|d |7}n|o|d |7}n|d |t i |f7}|SdS( Nshttp://is/onca/xml3?f=xmls&t=%ss &dev-t=%ss&type=%sis &locale=%ss&page=%ss&mode=%ss&%s=%s(s_checkLocaleSupportedslocales_supportedLocalessurls associates license_keysstripstypespages product_lines search_typesurllibsquoteskeyword( s search_typeskeywords product_linestypespages license_keyslocales associatesurl((s./Amazon/amazon.pysbuildURLs sheavyc  Cst|}t|}t|}t||||||||} t |} ti| }|i| } ti| } | i|djot| i} nt| i} t| dot| in|djo| Sn| i SdS(ssearch Amazon You need a license key to call this function; see http://www.amazon.com/webservices to get one. Then you can either pass it to this function every time, or set it globally; see the module docs for details. Parameters: keyword - keyword to search search_type - in (KeywordSearch, BrowseNodeSearch, AsinSearch, UpcSearch, AuthorSearch, ArtistSearch, ActorSearch, DirectorSearch, ManufacturerSearch, ListManiaSearch, SimilaritySearch) product_line - type of product to search for. restrictions based on search_type UpcSearch - in (music, classical) AuthorSearch - must be "books" ArtistSearch - in (music, classical) ActorSearch - in (dvd, vhs, video) DirectorSearch - in (dvd, vhs, video) ManufacturerSearch - in (electronics, kitchen, videogames, software, photo, pc-hardware) http_proxy (optional) - address of HTTP proxy to use for sending and receiving SOAP messages Returns: list of Bags, each Bag may contain the following attributes: Asin - Amazon ID ("ASIN" number) of this item Authors - list of authors Availability - "available", etc. BrowseList - list of related categories Catalog - catalog type ("Book", etc) CollectiblePrice - ?, format "$34.95" ImageUrlLarge - URL of large image of this item ImageUrlMedium - URL of medium image of this item ImageUrlSmall - URL of small image of this item Isbn - ISBN number ListPrice - list price, format "$34.95" Lists - list of ListMania lists that include this item Manufacturer - manufacturer Media - media ("Paperback", "Audio CD", etc) NumMedia - number of different media types in which this item is available OurPrice - Amazon price, format "$24.47" ProductName - name of this item ReleaseDate - release date, format "09 April, 1999" Reviews - reviews (AvgCustomerRating, plus list of CustomerReview with Rating, Summary, Content) SalesRank - sales rank (integer) SimilarProducts - list of Product, which is ASIN number ThirdPartyNewPrice - ?, format "$34.95" URL - URL of this item s BlendedSearchsErrorMsgN(!s getLicenses license_keys getLocaleslocales getAssociates associatesbuildURLs search_typeskeywords product_linestypespagesurls getProxiess http_proxysproxiessurllibsFancyURLopenersusopensusocksminidomsparsesxmldocscloses unmarshals BlendedSearchsdatas ProductInfoshasattrs AmazonErrorsErrorMsgsDetails(s search_typeskeywords product_linestypespages license_keys http_proxyslocales associatesusocksxmldocsproxiessdatasurlsu((s./Amazon/amazon.pyssearchs&-       sbooksic Cs&td|||||||| SdS(Ns KeywordSearch( ssearchskeywords product_linestypespages license_keys http_proxyslocales associate(skeywords product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByKeyword=sc Cs&td|||||||| SdS(NsBrowseNodeSearch( ssearchs browse_nodes product_linestypespages license_keys http_proxyslocales associate(s browse_nodes product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pysbrowseBestSellers@sc Cs&td|t|t|||| SdS(Ns AsinSearch(ssearchsASINsNonestypes license_keys http_proxyslocales associate(sASINstypes license_keys http_proxyslocales associate((s./Amazon/amazon.pys searchByASINCsc Cs&td|t|t|||| SdS(Ns UpcSearch(ssearchsUPCsNonestypes license_keys http_proxyslocales associate(sUPCstypes license_keys http_proxyslocales associate((s./Amazon/amazon.pys searchByUPCFsc Cs&td|d|||||| SdS(Ns AuthorSearchsbooks(ssearchsauthorstypespages license_keys http_proxyslocales associate(sauthorstypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByAuthorIssmusicc CsF|ddfjo tdntd|||||||| SdS(Nsmusics classicals.product_line must be in ('music', 'classical')s ArtistSearch( s product_lines AmazonErrorssearchsartiststypespages license_keys http_proxyslocales associate(sartists product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByArtistLs sdvdc CsI|dddfjo tdntd|||||||| SdS(Nsdvdsvhssvideos/product_line must be in ('dvd', 'vhs', 'video')s ActorSearch( s product_lines AmazonErrorssearchsactorstypespages license_keys http_proxyslocales associate(sactors product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pys searchByActorQs c CsI|dddfjo tdntd|||||||| SdS(Nsdvdsvhssvideos/product_line must be in ('dvd', 'vhs', 'video')sDirectorSearch( s product_lines AmazonErrorssearchsdirectorstypespages license_keys http_proxyslocales associate(sdirectors product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByDirectorVs s pc-hardwarec CsR|ddddddfjo tdntd|||||||| SdS( Ns electronicsskitchens videogamesssoftwaresphotos pc-hardwaresdproduct_line must be in ('electronics', 'kitchen', 'videogames', 'software', 'photo', 'pc-hardware')sManufacturerSearch( s product_lines AmazonErrorssearchs manufacturerstypespages license_keys http_proxyslocales associate(s manufacturers product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByManufacturer[s c Cs&td|t|||||| SdS(NsListManiaSearch( ssearchs listManiaIDsNonestypespages license_keys http_proxyslocales associate(s listManiaIDstypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByListMania`sc Cs&td|t|||||| SdS(NsSimilaritySearch( ssearchsASINsNonestypespages license_keys http_proxyslocales associate(sASINstypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pys searchSimilarcsc Cs&td|t|||||| SdS(NsWishlistSearch( ssearchs wishlistIDsNonestypespages license_keys http_proxyslocales associate(s wishlistIDstypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByWishlistfsc Cs&td|||||||| SdS(Ns PowerSearch( ssearchskeywords product_linestypespages license_keys http_proxyslocales associate(skeywords product_linestypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pys searchByPowerisc Cs&td|t|||||| SdS(Ns BlendedSearch( ssearchskeywordsNonestypespages license_keys http_proxyslocales associate(skeywordstypespages license_keys http_proxyslocales associate((s./Amazon/amazon.pyssearchByBlendedns(=s__doc__s __author__s __version__s__cvsversion__s__date__s __copyright__s __license__sxml.domsminidomsosssyssgetoptscgisurllibsstrings timeoutsocketssetDefaultSocketTimeouts ImportErrorsNones LICENSE_KEYs ASSOCIATEs HTTP_PROXYsLOCALEs Exceptions AmazonErrors NoLicenseKeys _amazonfile1s _amazonfile2s_licenseLocationss_supportedLocalessversions setAssociates getAssociates_checkLocaleSupporteds setLocales getLocales setLicenses getLicensessetProxysgetProxys getProxiess _contentsOfs _getScriptDirsBags unmarshalsbuildURLssearchssearchByKeywordsbrowseBestSellerss searchByASINs searchByUPCssearchByAuthorssearchByArtists searchByActorssearchByDirectorssearchByManufacturerssearchByListManias searchSimilarssearchByWishlists searchByPowerssearchByBlended(3s_supportedLocalesssearchs timeoutsocketsbuildURLs searchByUPCs getAssociatessearchByBlendedssearchByAuthors getProxiess unmarshals__cvsversion__s _contentsOfs setAssociates searchSimilars getLocales setLocalesurllibssearchByKeywordsversions getLicensessetProxysgetopts __version__scgisbrowseBestSellerssstrings __license__ssearchByDirectors searchByASINs setLicenses _amazonfile2s _amazonfile1s __author__ssyssBagssearchByListManias searchByPowers AmazonErrors_licenseLocationssminidoms __copyright__ssearchByManufacturerssearchByArtistsgetProxys searchByActors__date__s_checkLocaleSupporteds NoLicenseKeys _getScriptDirssearchByWishlistsos((s./Amazon/amazon.pys?6sl   6  `              K