phenny-1/modules/imdb.py

42 lines
975 B
Python
Raw Normal View History

2012-05-22 22:47:36 -04:00
#!/usr/bin/env python
"""
imdb.py - Phenny Web Search Module
Copyright 2012, Randy Nance, randynance.info
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import json
import web
def imdb_search(query):
2013-10-05 19:20:37 -04:00
query = query.replace('!', '')
query = query.encode('utf-8')
query = web.quote(query)
uri = 'http://www.omdbapi.com/?i=&t=%s' % query
bytes = web.get(uri)
m = json.loads(bytes)
return m
2012-05-22 22:47:36 -04:00
def imdb(phenny, input):
2013-10-05 19:20:37 -04:00
""".imdb <movie> - Use the OMDB API to find a link to a movie on IMDb."""
query = input.group(2)
if not query:
return phenny.say('.imdb what?')
m = imdb_search(query)
try:
phenny.say('{0} ({1}): {2} http://imdb.com/title/{3}'.format(
m['Title'],
m['Year'],
m['Plot'],
m['imdbID']))
except:
phenny.reply("No results found for '%s'." % query)
2012-05-22 22:47:36 -04:00
imdb.commands = ['imdb']
2013-11-28 22:23:32 -05:00
imdb.example = '.imdb Promethius'