<commit_before>import requests


def fetch_movie_rating(name):
    """Fetches movie rating from OMDB API"""
    query = {'t': name, 'y': 'plot', 'r': 'json'}
    r = requests.get("http://www.omdbapi.com/", params=query).json()

    if 'imdbRating' in r:
        rating = r['imdbRating']
    else:
        rating = None

    return rating<commit_msg>Improves OMDB hit rate - Removes extra info from movie name when trying to search from OMDB - Retry with simpler name in case first time fails<commit_after>import requests


def sanitize_movie_name(name):
    """Removes any extra info from movie name added by Finnkino"""
    name = name.rstrip()
    # Remove dub and 2D / 3D from the end of name and remove trailing space
    if name.endswith('(dub)'):
        name = name[:-5].rstrip()

    if name.endswith('(2D)') or name.endswith('(3D)'):
        name = name[:-4].rstrip()

    if name.endswith('2D') or name.endswith('3D'):
        name = name[:-2].rstrip()

    print(name)
    return name


def query_movie_rating(name):
    """Queries movie rating form OMDB API"""
    query = {'t': name, 'y': 'plot', 'r': 'json'}
    return requests.get("http://www.omdbapi.com/", params=query).json()


def fetch_movie_rating(name):
    """Fetches movie rating from OMDB API"""
    name = sanitize_movie_name(name)
    r = query_movie_rating(name)

    if r['Response'] == 'False':
        # Try again by splitting extra part out
        print('Not found')
        r = query_movie_rating(name.split('-')[0])
        print(name.split('-')[0])

    if 'imdbRating' in r:
        rating = r['imdbRating']
    else:
        rating = None

    return rating
{'fraction_non_alphanumeric': 0.14580801944106925, 'fraction_numerical': 0.006682867557715674, 'mean_word_length': 2.9975728155339807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6392550', 'n_tokens_mistral': 564, 'n_tokens_neox': 533, 'n_words': 159}