<commit_before>import time
import urllib.parse

from RatS.base.base_ratings_inserter import RatingsInserter
from RatS.rottentomatoes.rottentomatoes_site import RottenTomatoes


class RottenTomatoesRatingsInserter(RatingsInserter):
    def __init__(self, args):
        super(RottenTomatoesRatingsInserter, self).__init__(RottenTomatoes(args), args)

    def _search_for_movie(self, movie):
        search_url = 'https://www.rottentomatoes.com/api/private/v2.0/search?{search_params}'.format(
            search_params=urllib.parse.urlencode({'q': movie['title'], 't': 'movie'})
        )
        self.site.browser.get(search_url)

    def _get_search_results(self, search_result_page):
        json_data = self.site.get_json_from_html()
        return json_data['movies']

    def _is_requested_movie(self, movie, search_result):
        if self._is_field_in_parsed_data_for_this_site(movie, 'url'):
            return movie[self.site.site_name.lower()]['url'] == \
                   'https://www.rottentomatoes.com' + search_result['url']
        elif search_result['year'] and movie['year'] == int(search_result['year']):
            self.site.browser.get('https://www.rottentomatoes.com' + search_result['url'])
            time.sleep(1)
            return True
        return False

    def _click_rating(self, my_rating):
        converted_rating = str(my_rating / 2)
        if 'rating-root' not in self.site.browser.page_source:
            return
        movie_id = self.site.browser.find_element_by_id('rating-root').get_attribute('data-movie-id')

        self.site.browser.execute_script("""
            return $.post({
                url: 'https://www.rottentomatoes.com/napi/user/rating',
                data: { <commit_msg>Handle movies without ratings section - refs #73<commit_after>import time
import urllib.parse

from RatS.base.base_ratings_inserter import RatingsInserter
from RatS.rottentomatoes.rottentomatoes_site import RottenTomatoes


class RottenTomatoesRatingsInserter(RatingsInserter):
    def __init__(self, args):
        super(RottenTomatoesRatingsInserter, self).__init__(RottenTomatoes(args), args)

    def _search_for_movie(self, movie):
        search_url = 'https://www.rottentomatoes.com/api/private/v2.0/search?{search_params}'.format(
            search_params=urllib.parse.urlencode({'q': movie['title'], 't': 'movie'})
        )
        self.site.browser.get(search_url)

    def _get_search_results(self, search_result_page):
        json_data = self.site.get_json_from_html()
        return json_data['movies']

    def _is_requested_movie(self, movie, search_result):
        if self._is_field_in_parsed_data_for_this_site(movie, 'url'):
            return movie[self.site.site_name.lower()]['url'] == \
                   'https://www.rottentomatoes.com' + search_result['url']
        elif search_result['year'] and movie['year'] == int(search_result['year']):
            self.site.browser.get('https://www.rottentomatoes.com' + search_result['url'])
            time.sleep(1)
            return True
        return False

    def _click_rating(self, my_rating):
        converted_rating = str(my_rating / 2)
        if len(self.site.browser.find_elements_by_id('rating-root')) > 0:
            return
        movie_id = self.site.browser.find_element_by_id('rating-root').get_attribute('data-movie-id')

        self.site.browser.execute_script("""
            return $.post({
                url: 'https://www.rottentomatoes.com/napi/user/rating',
                data: { 
{'fraction_non_alphanumeric': 0.12450368689733408, 'fraction_numerical': 0.003119682359614294, 'mean_word_length': 3.1396713615023475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 8, 'lorem ipsum': 0, 'www.': 8, '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': '5446944', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1124, 'n_words': 164}