mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added Amazon.books and Amazon.videos so that users can search those products
by keywords. Added tests to match.
This commit is contained in:
parent
946d9b234c
commit
607793b6b4
@ -136,6 +136,76 @@ class Amazon(callbacks.Privmsg):
|
|||||||
pass
|
pass
|
||||||
irc.error(msg, 'No book was found with that ISBN.')
|
irc.error(msg, 'No book was found with that ISBN.')
|
||||||
|
|
||||||
|
def books(self, irc, msg, args):
|
||||||
|
"""[--url] <keywords>
|
||||||
|
|
||||||
|
Returns the books matching the given <keywords> search. If --url is
|
||||||
|
specified, a link to amazon.com's page for the book will also be
|
||||||
|
returned.
|
||||||
|
"""
|
||||||
|
opts = ['url']
|
||||||
|
(optlist, rest) = getopt.getopt(args, '', opts)
|
||||||
|
url = False
|
||||||
|
for (option, argument) in optlist:
|
||||||
|
option = option.lstrip('-')
|
||||||
|
if option == 'url':
|
||||||
|
url = True
|
||||||
|
keyword = privmsgs.getArgs(rest)
|
||||||
|
attribs = {'ProductName' : 'title',
|
||||||
|
'Manufacturer' : 'publisher',
|
||||||
|
'Authors' : 'author',
|
||||||
|
'URL' : 'url'
|
||||||
|
}
|
||||||
|
s = '"%(title)s", written by %(author)s; published by '\
|
||||||
|
'%(publisher)s%(url)s'
|
||||||
|
try:
|
||||||
|
books = amazon.searchByKeyword(keyword)
|
||||||
|
res = self._genResults(s, attribs, books, url)
|
||||||
|
if res:
|
||||||
|
irc.reply(msg, utils.commaAndify(res))
|
||||||
|
return
|
||||||
|
except amazon.AmazonError, e:
|
||||||
|
pass
|
||||||
|
irc.error(msg, 'No books were found with that keyword search.')
|
||||||
|
|
||||||
|
def videos(self, irc, msg, args):
|
||||||
|
"""[--url] [--{dvd,vhs}] <keywords>
|
||||||
|
|
||||||
|
Returns the videos matching the given <keyword> search. If --url is
|
||||||
|
specified, a link to amazon.com's page for the video will also be
|
||||||
|
returned. Search defaults to using --dvd.
|
||||||
|
"""
|
||||||
|
opts = ['url']
|
||||||
|
products = ['dvd', 'vhs']
|
||||||
|
(optlist, rest) = getopt.getopt(args, '', opts + products)
|
||||||
|
url = False
|
||||||
|
product = 'dvd'
|
||||||
|
for (option, argument) in optlist:
|
||||||
|
option = option.lstrip('-')
|
||||||
|
if option == 'url':
|
||||||
|
url = True
|
||||||
|
if option in products:
|
||||||
|
product = option
|
||||||
|
keyword = privmsgs.getArgs(rest)
|
||||||
|
attribs = {'ProductName' : 'title',
|
||||||
|
'Manufacturer' : 'publisher',
|
||||||
|
'MpaaRating' : 'mpaa',
|
||||||
|
'Media' : 'media',
|
||||||
|
'ReleaseDate' : 'date',
|
||||||
|
'URL' : 'url'
|
||||||
|
}
|
||||||
|
s = '"%(title)s" (%(media)s), rated %(mpaa)s; released '\
|
||||||
|
'%(date)s; published by %(publisher)s%(url)s'
|
||||||
|
try:
|
||||||
|
videos = amazon.searchByKeyword(keyword, product_line=product)
|
||||||
|
res = self._genResults(s, attribs, videos, url)
|
||||||
|
if res:
|
||||||
|
irc.reply(msg, utils.commaAndify(res))
|
||||||
|
return
|
||||||
|
except amazon.AmazonError, e:
|
||||||
|
pass
|
||||||
|
irc.error(msg, 'No videos were found with that keyword search.')
|
||||||
|
|
||||||
def asin(self, irc, msg, args):
|
def asin(self, irc, msg, args):
|
||||||
"""[--url] <asin>
|
"""[--url] <asin>
|
||||||
|
|
||||||
|
@ -90,5 +90,14 @@ class AmazonTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertRegexp('manufacturer --software adobe', r'Photoshop')
|
self.assertRegexp('manufacturer --software adobe', r'Photoshop')
|
||||||
self.assertRegexp('manufacturer --photo kodak', r'Kodak')
|
self.assertRegexp('manufacturer --photo kodak', r'Kodak')
|
||||||
|
|
||||||
|
def testBooks(self):
|
||||||
|
self.assertHelp('books')
|
||||||
|
self.assertRegexp('books linux', r'Linux Kernel Development')
|
||||||
|
|
||||||
|
def testVideos(self):
|
||||||
|
self.assertHelp('videos')
|
||||||
|
self.assertRegexp('videos zim', r'Demystifying the Devil.*DVD')
|
||||||
|
self.assertRegexp('videos --vhs samuel jackson', r'VHS Tape')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user