<commit_before>#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
imdb.py - Jenni IMDB Module
Copyright © 2012, <NAME>, <<EMAIL>>
Licensed under the Eiffel Forum License 2.

This module relies on imdbapi.com
"""
try:
    import json
except ImportError:
    import simplejson as json
except ImportError:
    print("Either update to python 2.6+ or install simplejson")
import web

def imdb(jenni, input):
    if not input.group(2):
        return
    word=input.group(2).rstrip()
    word=word.replace(" ", "+")
    uri="http://www.imdbapi.com/?t="+word
    try: u = web.get_urllib_object(uri, 30)
    except:
        jenni.say('IMDB is too slow at the moment :(')
        return 'err'
    data = json.load(u) #data is a Dict containing all the information we need
    u.close()
    message = '[IMDB] Title: ' +data['Title']+ \
              ' | Year: ' +data['Year']+ \
              ' | Rating: ' +data['imdbRating']+ \
              ' | Genre: ' +data['Genre']+ \
              ' | Link: http://imdb.com/title/' + data['imdbID']
    jenni.say(message)

imdb.commands = ['imdb', 'movie']
imdb.example = '.imdb Movie Title'

if __name__ == '__main__':
    print __doc__.strip()<commit_msg>[imdb] some error handling in the imdb module<commit_after>#!/usr/bin/env python
# -*- coding: utf8 -*-
"""
imdb.py - Jenni IMDB Module
Copyright © 2012, <NAME>, <<EMAIL>>
Licensed under the Eiffel Forum License 2.

This module relies on imdbapi.com
"""
try:
    import json
except ImportError:
    import simplejson as json
except ImportError:
    print("Either update to python 2.6+ or install simplejson")
import web

def imdb(jenni, input):
    if not input.group(2):
        return
    word=input.group(2).rstrip()
    word=word.replace(" ", "+")
    uri="http://www.imdbapi.com/?t="+word
    try: u = web.get_urllib_object(uri, 30)
    except:
        jenni.say('IMDB is too slow at the moment :(')
        return 'err'
    data = json.load(u) #data is a Dict containing all the information we need
    u.close()
    if data['Response'] == 'False':
        if 'Error' in data:
            message = '[IMDB] %s' % data['Error']
        else:
            jenni.debug('imdb', 'Got an error from the imdb api, search phrase was %s' % word, 'warning')
            jenni.debug('imdb', str(data), 'warning')
            message = '[IMDB] Got an error from the IMDB api'
    else:
        message = '[IMDB] Title: ' +data['Title']+ \
                  ' | Year: ' +data['Year']+ \
                  ' | Rating: ' +data['imdbRating']+ \
                  ' | Genre: ' +data['Genre']+ \
                  ' | Link: http://imdb.com/title/' + data['imdbID']
    jenni.say(message)

imdb.commands = ['imdb', 'movie']
imdb.example = '.imdb Movie Title'

if __name__ == '__main__':
    print __doc__.strip()
{'fraction_non_alphanumeric': 0.15768678160919541, 'fraction_numerical': 0.008620689655172414, 'mean_word_length': 2.552295918367347, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '604305', 'n_tokens_mistral': 965, 'n_tokens_neox': 933, 'n_words': 263}