<commit_before>#!/usr/bin/env python
from video_listings import VideoListings
from search_results_page import SearchResultsPage


class WatchPage(VideoListings):
    """
     Unisubs page contains common web elements found across
     all Universal Subtitles pages. Every new page class is derived from
     UnisubsPage so that every child class can have access to common web
     elements and methods that pertain to those elements.
    """

    _URL = "videos/watch"
    _SEARCH = "form.search-form div#watch_search input#id_q"
    _SEARCH_PULLDOWN = "a#advanced_search"
    _SEARCH_ORIG_LANG = "select#id_video_lang"
    _SEARCH_TRANS_LANG = "select#id_langs"
    _SEARCH_SUBMIT = "div#advanced_menu button"
    _VIDEO_SECTION = "div#%s_videos"
    _SECTION_VIDEOS = "div#%s_videos ul.video_list li.Video_list_item"  
    _MORE_VIDEOS = ".btn_more_videos"

    #Popular Sort
    _POPULAR_SORT = "a#popular_sort"
    _CURRENT_SORT = "span.current-sort"

    def open_watch_page(self):
        self.open_page(self._URL)

    def basic_search(self, search_term):
        self.submit_form_text_by_css(self._SEARCH, search_term)
        return SearchResultsPage(self)

    def advanced_search(self, search_term=None, orig_lang=None, trans_lang=None):
        if search_term:
            self.type_by_css(self._SEARCH, search_term)
            time.sleep(1)

        self.click_by_css(self._SEARCH_PULLDOWN)
        if orig_lang:
            self.select_option_by_text(self._SEARCH_ORIG_LANG, orig_lang)
        if trans_lang:
            self.select_option_by_text(self._SEARCH_TRANS_LANG, trans_lang)
        
        self.click_by_css(self._SEARCH_SUBMIT)
        
        return SearchResultsPage(self)

       
    def _valid_section_name(self, section):
        sections = ['popular', 'latest', 'featured']
        if section not in sections:
            raise ValueError('%s is not a valid section name')


    def section_empty(self, section):
        self._valid_section_name(section)
        el = (self._VIDEO_SECTION + ' ' + p.empty) % section
        if self.is_element_present(el):
            return True

    def _videos_in_section(self, section):
        self._valid_section_name(section)
        section_css = self._SECTION_VIDEOS % section
        video_els = self.get_elements_list(section_css)
        return video_els


    def _video_list_item(self, title, section='latest'):
        """Return the element of video by title in the given section.

        """
        video_elements = self._videos_in_section(section)
        try:
            for el in video_elements:
                vid_title = el.find_element_by_css_selector("a").get_attribute(
                    'title')
                if title == vid_title:
                    return el
                else:
                    self.record_error("title %s not found on the page" % title)
        except Exception as e:
            self.record_error(e)

    def section_has_video(self, title, section='latest'):
        if self._video_list_item(title, section):
            return True

    def section_videos(self, section):
        video_els = self._videos_in_section(section)
        title_list = []
        for el in video_els:
            vid_title = el.find_element_by_css_selector("a").get_attribute(
                    'title')
            title_list.append(vid_title)
        if 'About Amara' in title_list:
            title_list.remove('About Amara') #Video isn't always present in index.
        return title_list

    def display_more(self, section):
        more_css = (self._VIDEO_SECTION + ' ' + self._MORE_VIDEOS) % section
        self.click_by_css(more_css)
        self.search_complete()

    def popular_current_sort(self):
        return self.get_text_by_css(self._CURRENT_SORT)

    def popular_sort(self, sort_param):
        """Sort the popular videos by date parameter.

        valid values are: today, week, month, year, total.
        """
        sort_el_css = "div#sort_menu ul li[val='%s']" % sort_param
        self.click_item_from_pulldown(self._CURRENT_SORT, sort_el_css)

    def popular_more_link(self):
        more_css = (self._VIDEO_SECTION + ' ' + self._MORE_VIDEOS) % 'popular'
        more_link = self.get_element_attribute(more_css, 'href')
        return more_link




        
    

        
        
<commit_msg>can not sleep without time.<commit_after>#!/usr/bin/env python
from video_listings import VideoListings
from search_results_page import SearchResultsPage
import time

class WatchPage(VideoListings):
    """
     Unisubs page contains common web elements found across
     all Universal Subtitles pages. Every new page class is derived from
     UnisubsPage so that every child class can have access to common web
     elements and methods that pertain to those elements.
    """

    _URL = "videos/watch"
    _SEARCH = "form.search-form div#watch_search input#id_q"
    _SEARCH_PULLDOWN = "a#advanced_search"
    _SEARCH_ORIG_LANG = "select#id_video_lang"
    _SEARCH_TRANS_LANG = "select#id_langs"
    _SEARCH_SUBMIT = "div#advanced_menu button"
    _VIDEO_SECTION = "div#%s_videos"
    _SECTION_VIDEOS = "div#%s_videos ul.video_list li.Video_list_item"  
    _MORE_VIDEOS = ".btn_more_videos"

    #Popular Sort
    _POPULAR_SORT = "a#popular_sort"
    _CURRENT_SORT = "span.current-sort"

    def open_watch_page(self):
        self.open_page(self._URL)

    def basic_search(self, search_term):
        self.submit_form_text_by_css(self._SEARCH, search_term)
        return SearchResultsPage(self)

    def advanced_search(self, search_term=None, orig_lang=None, trans_lang=None):
        if search_term:
            self.type_by_css(self._SEARCH, search_term)
            time.sleep(1)

        self.click_by_css(self._SEARCH_PULLDOWN)
        if orig_lang:
            self.select_option_by_text(self._SEARCH_ORIG_LANG, orig_lang)
        if trans_lang:
            self.select_option_by_text(self._SEARCH_TRANS_LANG, trans_lang)
        
        self.click_by_css(self._SEARCH_SUBMIT)
        
        return SearchResultsPage(self)

       
    def _valid_section_name(self, section):
        sections = ['popular', 'latest', 'featured']
        if section not in sections:
            raise ValueError('%s is not a valid section name')


    def section_empty(self, section):
        self._valid_section_name(section)
        el = (self._VIDEO_SECTION + ' ' + p.empty) % section
        if self.is_element_present(el):
            return True

    def _videos_in_section(self, section):
        self._valid_section_name(section)
        section_css = self._SECTION_VIDEOS % section
        video_els = self.get_elements_list(section_css)
        return video_els


    def _video_list_item(self, title, section='latest'):
        """Return the element of video by title in the given section.

        """
        video_elements = self._videos_in_section(section)
        try:
            for el in video_elements:
                vid_title = el.find_element_by_css_selector("a").get_attribute(
                    'title')
                if title == vid_title:
                    return el
                else:
                    self.record_error("title %s not found on the page" % title)
        except Exception as e:
            self.record_error(e)

    def section_has_video(self, title, section='latest'):
        if self._video_list_item(title, section):
            return True

    def section_videos(self, section):
        video_els = self._videos_in_section(section)
        title_list = []
        for el in video_els:
            vid_title = el.find_element_by_css_selector("a").get_attribute(
                    'title')
            title_list.append(vid_title)
        if 'About Amara' in title_list:
            title_list.remove('About Amara') #Video isn't always present in index.
        return title_list

    def display_more(self, section):
        more_css = (self._VIDEO_SECTION + ' ' + self._MORE_VIDEOS) % section
        self.click_by_css(more_css)
        self.search_complete()

    def popular_current_sort(self):
        return self.get_text_by_css(self._CURRENT_SORT)

    def popular_sort(self, sort_param):
        """Sort the popular videos by date parameter.

        valid values are: today, week, month, year, total.
        """
        sort_el_css = "div#sort_menu ul li[val='%s']" % sort_param
        self.click_item_from_pulldown(self._CURRENT_SORT, sort_el_css)

    def popular_more_link(self):
        more_css = (self._VIDEO_SECTION + ' ' + self._MORE_VIDEOS) % 'popular'
        more_link = self.get_element_attribute(more_css, 'href')
        return more_link




        
    

        
        

{'fraction_non_alphanumeric': 0.08403264743073917, 'fraction_numerical': 0.00022991148407862974, 'mean_word_length': 2.584672435105068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7479262', 'n_tokens_mistral': 2755, 'n_tokens_neox': 2665, 'n_words': 578}