idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
34,600 | def overtime ( self ) : if self . _overtime . lower ( ) == 'ot' : return 1 if self . _overtime . lower ( ) == 'so' : return SHOOTOUT if self . _overtime == '' : return 0 num = re . findall ( r'\d+' , self . _overtime ) if len ( num ) > 0 : return num [ 0 ] return 0 | Returns an int of the number of overtimes that were played during the game or an int constant if the game went to a shootout . |
34,601 | def datetime ( self ) : date_string = '%s %s' % ( self . _date , self . _time . upper ( ) ) date_string = re . sub ( r'/.*' , '' , date_string ) date_string = re . sub ( r' ET' , '' , date_string ) date_string += 'M' date_string = re . sub ( r'PMM' , 'PM' , date_string , flags = re . IGNORECASE ) date_string = re . sub... | Returns a datetime object to indicate the month day year and time the requested game took place . |
34,602 | def type ( self ) : if self . _type . lower ( ) == 'reg' : return REGULAR_SEASON if self . _type . lower ( ) == 'ctourn' : return CONFERENCE_TOURNAMENT if self . _type . lower ( ) == 'ncaa' : return NCAA_TOURNAMENT if self . _type . lower ( ) == 'nit' : return NIT_TOURNAMENT if self . _type . lower ( ) == 'cbi' : retur... | Returns a string constant to indicate whether the game was played during the regular season or in the post season . |
34,603 | def location ( self ) : if self . _location == '' : return HOME if self . _location == 'N' : return NEUTRAL if self . _location == '@' : return AWAY | Returns a string constant to indicate whether the game was played at the team s home venue the opponent s venue or at a neutral site . |
34,604 | def opponent_name ( self ) : name = re . sub ( r'\(\d+\)' , '' , self . _opponent_name ) name = name . replace ( u'\xa0' , '' ) return name | Returns a string of the opponent s name such as the Purdue Boilermakers . |
34,605 | def opponent_rank ( self ) : rank = re . findall ( r'\d+' , self . _opponent_name ) if len ( rank ) > 0 : return int ( rank [ 0 ] ) return None | Returns a string of the opponent s rank when the game was played and None if the team was unranked . |
34,606 | def overtimes ( self ) : if self . _overtimes == '' or self . _overtimes is None : return 0 if self . _overtimes . lower ( ) == 'ot' : return 1 num_overtimes = re . findall ( r'\d+' , self . _overtimes ) try : return int ( num_overtimes [ 0 ] ) except ( ValueError , IndexError ) : return 0 | Returns an int of the number of overtimes that were played during the game and 0 if the game finished at the end of regulation time . |
34,607 | def _parse_nationality ( self , player_info ) : for span in player_info ( 'span' ) . items ( ) : if 'class="f-i' in str ( span ) : nationality = span . text ( ) nationality = NATIONALITY [ nationality ] setattr ( self , '_nationality' , nationality ) break | Parse the player s nationality . |
34,608 | def _parse_contract_headers ( self , table ) : years = [ i . text ( ) for i in table ( 'th' ) . items ( ) ] years . remove ( 'Team' ) return years | Parse the years on the contract . |
34,609 | def _parse_contract_wages ( self , table ) : wages = [ i . text ( ) if i . text ( ) . startswith ( '$' ) else '' for i in table ( 'td' ) . items ( ) ] wages . remove ( '' ) return wages | Parse the wages on the contract . |
34,610 | def _combine_contract ( self , years , wages ) : contract = { } for i in range ( len ( years ) ) : contract [ years [ i ] ] = wages [ i ] return contract | Combine the contract wages and year . |
34,611 | def _find_initial_index ( self ) : index = 0 for season in self . _season : if season == 'Career' : self . _index = index break index += 1 | Find the index of career stats . |
34,612 | def _parse_player_position ( self , player_info ) : for section in player_info ( 'div#meta p' ) . items ( ) : if 'Position' in str ( section ) : position = section . text ( ) . replace ( 'Position: ' , '' ) setattr ( self , '_position' , position ) break | Parse the player s position . |
34,613 | def _parse_conference ( self , stats ) : conference_tag = stats ( PLAYER_SCHEME [ 'conference' ] ) conference = re . sub ( r'.*/cbb/conferences/' , '' , str ( conference_tag ( 'a' ) ) ) conference = re . sub ( r'/.*' , '' , conference ) return conference | Parse the conference abbreviation for the player s team . |
34,614 | def _parse_team_abbreviation ( self , stats ) : team_tag = stats ( PLAYER_SCHEME [ 'team_abbreviation' ] ) team = re . sub ( r'.*/cbb/schools/' , '' , str ( team_tag ( 'a' ) ) ) team = re . sub ( r'/.*' , '' , team ) return team | Parse the team abbreviation . |
34,615 | def _parse_player_data ( self , player_data ) : for field in self . __dict__ : short_field = str ( field ) [ 1 : ] if short_field == 'player_id' or short_field == 'index' or short_field == 'most_recent_season' or short_field == 'name' or short_field == 'weight' or short_field == 'height' or short_field == 'season' : co... | Parse all player information and set attributes . |
34,616 | def _parse_ranking ( self , field , boxscore ) : ranking = None index = BOXSCORE_ELEMENT_INDEX [ field ] teams_boxscore = boxscore ( BOXSCORE_SCHEME [ field ] ) if str ( teams_boxscore ) == '' : return ranking team = pq ( teams_boxscore [ index ] ) if 'pollrank' in str ( team ) : rank_str = re . findall ( r'\(\d+\)' , ... | Parse each team s rank if applicable . |
34,617 | def _parse_record ( self , field , boxscore , index ) : records = boxscore ( BOXSCORE_SCHEME [ field ] ) . items ( ) records = [ x . text ( ) for x in records if x . text ( ) != '' ] return records [ index ] | Parse each team s record . |
34,618 | def winning_name ( self ) : if self . winner == HOME : if 'cbb/schools' not in str ( self . _home_name ) : return str ( self . _home_name ) return self . _home_name . text ( ) if 'cbb/schools' not in str ( self . _away_name ) : return str ( self . _away_name ) return self . _away_name . text ( ) | Returns a string of the winning team s name such as Purdue Boilermakers . |
34,619 | def losing_name ( self ) : if self . winner == HOME : if 'cbb/schools' not in str ( self . _away_name ) : return str ( self . _away_name ) return self . _away_name . text ( ) if 'cbb/schools' not in str ( self . _home_name ) : return str ( self . _home_name ) return self . _home_name . text ( ) | Returns a string of the losing team s name such as Indiana Hoosiers . |
34,620 | def away_win_percentage ( self ) : try : result = float ( self . away_wins ) / float ( self . away_wins + self . away_losses ) return round ( result , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the percentage of games the away team has won after the conclusion of the game . Percentage ranges from 0 - 1 . |
34,621 | def away_wins ( self ) : try : wins , losses = re . findall ( r'\d+' , self . _away_record ) return wins except ( ValueError , TypeError ) : return 0 | Returns an int of the number of games the team has won after the conclusion of the game . |
34,622 | def home_win_percentage ( self ) : try : result = float ( self . home_wins ) / float ( self . home_wins + self . home_losses ) return round ( result , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the percentage of games the home team has won after the conclusion of the game . Percentage ranges from 0 - 1 . |
34,623 | def _get_rank ( self , team ) : rank = None rank_field = team ( 'span[class="pollrank"]' ) if len ( rank_field ) > 0 : rank = re . findall ( r'\(\d+\)' , str ( rank_field ) ) [ 0 ] rank = int ( rank . replace ( '(' , '' ) . replace ( ')' , '' ) ) return rank | Find the team s rank when applicable . |
34,624 | def _get_team_results ( self , away_name , away_abbr , away_score , home_name , home_abbr , home_score ) : if not away_score or not home_score : return None , None if away_score > home_score : return ( away_name , away_abbr ) , ( home_name , home_abbr ) else : return ( home_name , home_abbr ) , ( away_name , away_abbr ... | Determine the winner and loser of the game . |
34,625 | def two_point_field_goal_percentage ( self ) : try : result = float ( self . two_point_field_goals ) / float ( self . two_point_field_goal_attempts ) return round ( result , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the number of two point field goals made divided by the number of two point field goal attempts . Percentage ranges from 0 - 1 . |
34,626 | def opp_two_point_field_goal_percentage ( self ) : try : result = float ( self . opp_two_point_field_goals ) / float ( self . opp_two_point_field_goal_attempts ) return round ( result , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by opponents . Percentage ranges from 0 - 1 . |
34,627 | def _add_stats_data ( self , teams_list , team_data_dict ) : for team_data in teams_list : if 'class="over_header thead"' in str ( team_data ) or 'class="thead"' in str ( team_data ) : continue abbr = utils . _parse_field ( PARSING_SCHEME , team_data , 'abbreviation' ) try : team_data_dict [ abbr ] [ 'data' ] += team_d... | Add a team s stats row to a dictionary . |
34,628 | def _get_team_abbreviation ( self , team ) : name_tag = team ( 'th[data-stat="school_name"] a' ) team_abbreviation = re . sub ( r'.*/cfb/schools/' , '' , str ( name_tag ) ) team_abbreviation = re . sub ( r'/.*' , '' , team_abbreviation ) return team_abbreviation | Retrieve team s abbreviation . |
34,629 | def _find_conference_teams ( self , conference_abbreviation , year ) : if not year : year = utils . _find_year_for_season ( 'ncaaf' ) page = self . _pull_conference_page ( conference_abbreviation , year ) if not page : url = CONFERENCE_URL % ( conference_abbreviation , year ) output = ( "Can't pull requested conference... | Retrieve the teams in the conference for the requested season . |
34,630 | def _get_conference_id ( self , conference ) : name_tag = conference ( 'td[data-stat="conf_name"] a' ) conference_id = re . sub ( r'.*/cfb/conferences/' , '' , str ( name_tag ) ) conference_id = re . sub ( r'/.*' , '' , conference_id ) return conference_id | Get the conference abbreviation such as big - 12 . |
34,631 | def _find_conferences ( self , year ) : if not year : year = utils . _find_year_for_season ( 'ncaaf' ) page = self . _pull_conference_page ( year ) if not page : output = ( "Can't pull requested conference page. Ensure the " "following URL exists: %s" % ( CONFERENCES_URL % year ) ) raise ValueError ( output ) conferenc... | Retrieve the conferences and teams for the requested season . |
34,632 | def week ( self ) : if self . _week . lower ( ) == 'wild card' : return WILD_CARD if self . _week . lower ( ) == 'division' : return DIVISION if self . _week . lower ( ) == 'conf. champ.' : return CONF_CHAMPIONSHIP if self . _week . lower ( ) == 'superbowl' : return SUPER_BOWL return self . _week | Returns an int of the week number in the season such as 1 for the first week of the regular season . |
34,633 | def datetime ( self ) : date_string = '%s %s %s' % ( self . _day , self . _date , self . _year ) return datetime . strptime ( date_string , '%a %B %d %Y' ) | Returns a datetime object representing the date the game was played . |
34,634 | def _add_games_to_schedule ( self , schedule , game_type , year ) : for item in schedule : game = Game ( item , game_type , year ) self . _games . append ( game ) | Add games instances to schedule . |
34,635 | def minutes_played ( self ) : if self . _minutes_played [ self . _index ] : minutes , seconds = self . _minutes_played [ self . _index ] . split ( ':' ) minutes = float ( minutes ) + float ( seconds ) / 60 return float ( minutes ) return None | Returns a float of the number of game minutes the player was on the court for . |
34,636 | def two_pointers ( self ) : if self . field_goals and self . three_pointers : return int ( self . field_goals - self . three_pointers ) if self . field_goals : return int ( self . field_goals ) return None | Returns an int of the total number of two point field goals the player made . |
34,637 | def two_point_attempts ( self ) : if self . field_goal_attempts and self . three_point_attempts : return int ( self . field_goal_attempts - self . three_point_attempts ) if self . field_goal_attempts : return int ( self . field_goal_attempts ) return None | Returns an int of the total number of two point field goals the player attempted during the season . |
34,638 | def two_point_percentage ( self ) : if self . two_pointers and self . two_point_attempts : perc = float ( self . two_pointers ) / float ( self . two_point_attempts ) return round ( perc , 3 ) if self . two_point_attempts : return 0.0 return None | Returns a float of the player s two point field goal percentage during the season . Percentage ranges from 0 - 1 . |
34,639 | def away_two_point_field_goal_percentage ( self ) : result = float ( self . away_two_point_field_goals ) / float ( self . away_two_point_field_goal_attempts ) return round ( float ( result ) , 3 ) | Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by the away team . Percentage ranges from 0 - 1 . |
34,640 | def home_wins ( self ) : try : wins , losses = re . findall ( r'\d+' , self . _home_record ) return wins except ValueError : return 0 | Returns an int of the number of games the home team won after the conclusion of the game . |
34,641 | def home_two_point_field_goal_percentage ( self ) : result = float ( self . home_two_point_field_goals ) / float ( self . home_two_point_field_goal_attempts ) return round ( float ( result ) , 3 ) | Returns a float of the number of two point field goals made divided by the number of two point field goal attempts by the home team . Percentage ranges from 0 - 1 . |
34,642 | def dataframe ( self ) : fields_to_include = { 'abbreviation' : self . abbreviation , 'defensive_simple_rating_system' : self . defensive_simple_rating_system , 'first_downs' : self . first_downs , 'first_downs_from_penalties' : self . first_downs_from_penalties , 'fumbles' : self . fumbles , 'games_played' : self . ga... | Returns a pandas DataFrame containing all other class properties and values . The index for the DataFrame is the string abbreviation of the team such as KAN . |
34,643 | def _parse_team_name ( self , team ) : team = team . replace ( ' ' , ' ' ) team = team . replace ( '\xa0' , ' ' ) team_html = pq ( team ) return team_html . text ( ) | Parse the team name in the contract table . |
34,644 | def _parse_value ( self , html_data , field ) : scheme = PLAYER_SCHEME [ field ] items = [ i . text ( ) for i in html_data ( scheme ) . items ( ) ] if len ( items ) == 0 : return None return items | Parse the HTML table to find the requested field s value . |
34,645 | def _get_id ( self , player ) : name_tag = player ( 'td[data-stat="player"] a' ) name = re . sub ( r'.*/players/./' , '' , str ( name_tag ) ) return re . sub ( r'\.shtml.*' , '' , name ) | Parse the player ID . |
34,646 | def dataframe ( self ) : fields_to_include = { 'assists' : self . assists , 'blocks_at_even_strength' : self . blocks_at_even_strength , 'corsi_for_percentage' : self . corsi_for_percentage , 'decision' : self . decision , 'defensive_zone_starts' : self . defensive_zone_starts , 'defensive_zone_start_percentage' : self... | Returns a pandas DataFrame containing all other relevant properties and values for the specified game . |
34,647 | def _find_player_id ( self , row ) : player_id = row ( 'th' ) . attr ( 'data-append-csv' ) if not player_id : player_id = row ( 'td' ) . attr ( 'data-append-csv' ) return player_id | Find the player s ID . |
34,648 | def dataframe ( self ) : if self . _away_goals is None and self . _home_goals is None : return None fields_to_include = { 'arena' : self . arena , 'attendance' : self . attendance , 'away_assists' : self . away_assists , 'away_even_strength_assists' : self . away_even_strength_assists , 'away_even_strength_goals' : sel... | Returns a pandas DataFrame containing all other class properties and values . The index for the DataFrame is the string URI that is used to instantiate the class such as 201806070VEG . |
34,649 | def away_save_percentage ( self ) : try : save_pct = float ( self . away_saves ) / float ( self . home_shots_on_goal ) return round ( save_pct , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the percentage of shots the away team saved . Percentage ranges from 0 - 1 . |
34,650 | def home_save_percentage ( self ) : try : save_pct = float ( self . home_saves ) / float ( self . away_shots_on_goal ) return round ( save_pct , 3 ) except ZeroDivisionError : return 0.0 | Returns a float of the percentage of shots the home team saved . Percentage ranges from 0 - 1 . |
34,651 | def location ( self ) : if self . _location . lower ( ) == 'n' : return NEUTRAL if self . _location . lower ( ) == '@' : return AWAY return HOME | Returns a string constant to indicate whether the game was played at home away or in a neutral location . |
34,652 | def rank ( self ) : rank = re . findall ( r'\d+' , self . _rank ) if len ( rank ) == 0 : return None return rank [ 0 ] | Returns an int of the team s rank at the time the game was played . |
34,653 | def datetime ( self ) : date_string = '%s %s' % ( self . _date , self . _year ) date_string = re . sub ( r' \(\d+\)' , '' , date_string ) return datetime . strptime ( date_string , '%A, %b %d %Y' ) | Returns a datetime object of the month day year and time the game was played . |
34,654 | def game_number_for_day ( self ) : game_number = re . findall ( r'\(\d+\)' , self . _date ) if len ( game_number ) == 0 : return 1 game_number = re . findall ( r'\d+' , game_number [ 0 ] ) return int ( game_number [ 0 ] ) | Returns an int denoting which game is played for the team during the given day . Default value is 1 where a team plays only one game during the day but can be higher for double headers etc . For example if a team has a double header one day the first game of the day will return 1 while the second game will return 2 . |
34,655 | def games_behind ( self ) : if 'up' in self . _games_behind . lower ( ) : games_behind = re . sub ( 'up *' , '' , self . _games_behind . lower ( ) ) try : return float ( games_behind ) * - 1.0 except ValueError : return None if 'tied' in self . _games_behind . lower ( ) : return 0.0 try : return float ( self . _games_b... | Returns a float of the number of games behind the leader the team is . 0 . 0 indicates the team is tied for first . Negative numbers indicate the number of games a team is ahead of the second place team . |
34,656 | def _parse_name ( self , team_data ) : name = team_data ( 'td[data-stat="team_ID"]:first' ) name = re . sub ( r'.*title="' , '' , str ( name ) ) name = re . sub ( r'".*' , '' , name ) setattr ( self , '_name' , name ) | Parses the team s name . |
34,657 | def _parse_opponent_abbr ( self , game_data ) : opponent = game_data ( 'td[data-stat="opp_name"]:first' ) opponent = re . sub ( r'.*/teams/' , '' , str ( opponent ) ) opponent = re . sub ( r'\/.*.html.*' , '' , opponent ) setattr ( self , '_opponent_abbr' , opponent ) | Parses the opponent s abbreviation for the game . |
34,658 | def _add_games_to_schedule ( self , schedule ) : for item in schedule : if 'class="thead"' in str ( item ) or 'class="over_header thead"' in str ( item ) : continue game = Game ( item ) self . _games . append ( game ) | Add game information to list of games . |
34,659 | def dataframe ( self ) : fields_to_include = { 'completed_passes' : self . completed_passes , 'attempted_passes' : self . attempted_passes , 'passing_completion' : self . passing_completion , 'passing_yards' : self . passing_yards , 'pass_yards_per_attempt' : self . pass_yards_per_attempt , 'adjusted_yards_per_attempt'... | Returns a pandas DataFrame containing all other relevant class properties and value for the specified game . |
34,660 | def dataframe ( self ) : if self . _away_points is None and self . _home_points is None : return None fields_to_include = { 'away_first_downs' : self . away_first_downs , 'away_fumbles' : self . away_fumbles , 'away_fumbles_lost' : self . away_fumbles_lost , 'away_interceptions' : self . away_interceptions , 'away_pass... | Returns a pandas DataFrame containing all other class properties and values . The index for the DataFrame is the string URI that is used to instantiate the class such as 2018 - 01 - 08 - georgia . |
34,661 | def winning_abbr ( self ) : if self . winner == HOME : if 'cfb/schools' not in str ( self . _home_name ) : return self . _home_name . text ( ) return utils . _parse_abbreviation ( self . _home_name ) if 'cfb/schools' not in str ( self . _away_name ) : return self . _away_name . text ( ) return utils . _parse_abbreviati... | Returns a string of the winning team s abbreviation such as ALABAMA for the Alabama Crimson Tide . |
34,662 | def _combine_all_stats ( self , player_info ) : all_stats_dict = { } for table_id in [ 'passing' , 'rushing' , 'defense' , 'scoring' ] : table_items = utils . _get_stats_table ( player_info , 'table#%s' % table_id ) career_items = utils . _get_stats_table ( player_info , 'table#%s' % table_id , footer = True ) all_stat... | Pull stats from all tables into a single data structure . |
34,663 | def _pull_player_data ( self ) : player_info = self . _retrieve_html_page ( ) if not player_info : return self . _parse_player_information ( player_info ) all_stats = self . _combine_all_stats ( player_info ) setattr ( self , '_season' , list ( all_stats . keys ( ) ) ) return all_stats | Pull and aggregate all player information . |
34,664 | def team_abbreviation ( self ) : if self . _season [ self . _index ] . lower ( ) == 'career' : return None return self . _team_abbreviation [ self . _index ] | Returns a string of the team s abbreviation such as DET for the Detroit Red Wings . |
34,665 | def add_cell_footer ( self ) : logging . info ( 'Adding footer cell' ) for cell in self . nb [ 'cells' ] : if cell . cell_type == 'markdown' : if 'pynb_footer_tag' in cell . source : logging . debug ( 'Footer cell already present' ) return m = self . add_cell_markdown ( m . format ( exec_time = self . exec_time , exec_... | Add footer cell |
34,666 | def get_kernelspec ( self , name ) : ksm = KernelSpecManager ( ) kernelspec = ksm . get_kernel_spec ( name ) . to_dict ( ) kernelspec [ 'name' ] = name kernelspec . pop ( 'argv' ) return kernelspec | Get a kernel specification dictionary given a kernel name |
34,667 | def docker_start ( develop = True ) : curr_dir = os . path . dirname ( os . path . realpath ( __file__ ) ) local ( 'docker run --rm --name pynb -d -ti -p 127.0.0.1:8889:8888 -v {}:/code -t pynb' . format ( curr_dir ) ) if develop : docker_exec ( 'python3 setup.py develop' ) print ( 'Jupyter available at http://127.0.0... | Start docker container |
34,668 | def read ( self , file ) : content = self . _read_content ( file ) self . _validate ( content ) self . _parse ( content ) return self | Reads the captions file . |
34,669 | def _parse_timeframe_line ( self , line ) : tf = self . _validate_timeframe_line ( line ) if not tf : raise MalformedCaptionError ( 'Invalid time format' ) return tf . group ( 1 ) , tf . group ( 2 ) | Parse timeframe line and return start and end timestamps . |
34,670 | def main ( ) : options = docopt ( __doc__ , version = __version__ ) if options [ 'segment' ] : segment ( options [ '<file>' ] , options [ '--output' ] , options [ '--target-duration' ] , options [ '--mpegts' ] , ) | Main entry point for CLI commands . |
34,671 | def segment ( f , output , target_duration , mpegts ) : try : target_duration = int ( target_duration ) except ValueError : exit ( 'Error: Invalid target duration.' ) try : mpegts = int ( mpegts ) except ValueError : exit ( 'Error: Invalid MPEGTS value.' ) WebVTTSegmenter ( ) . segment ( f , output , target_duration , ... | Segment command . |
34,672 | def from_srt ( cls , file ) : parser = SRTParser ( ) . read ( file ) return cls ( file = file , captions = parser . captions ) | Reads captions from a file in SubRip format . |
34,673 | def from_sbv ( cls , file ) : parser = SBVParser ( ) . read ( file ) return cls ( file = file , captions = parser . captions ) | Reads captions from a file in YouTube SBV format . |
34,674 | def read ( cls , file ) : parser = WebVTTParser ( ) . read ( file ) return cls ( file = file , captions = parser . captions , styles = parser . styles ) | Reads a WebVTT captions file . |
34,675 | def save ( self , output = '' ) : self . file = self . _get_output_file ( output ) with open ( self . file , 'w' , encoding = 'utf-8' ) as f : self . write ( f ) | Save the document . If no output is provided the file will be saved in the same location . Otherwise output can determine a target directory or file . |
34,676 | def total_length ( self ) : if not self . _captions : return 0 return int ( self . _captions [ - 1 ] . end_in_seconds ) - int ( self . _captions [ 0 ] . start_in_seconds ) | Returns the total length of the captions . |
34,677 | def segment ( self , webvtt , output = '' , seconds = SECONDS , mpegts = MPEGTS ) : if isinstance ( webvtt , str ) : captions = WebVTT ( ) . read ( webvtt ) . captions elif not self . _validate_webvtt ( webvtt ) : raise InvalidCaptionsError ( 'The captions provided are invalid' ) else : captions = webvtt . captions sel... | Segments the captions based on a number of seconds . |
34,678 | def best_fts_version ( ) : "Discovers the most advanced supported SQLite FTS version" conn = sqlite3 . connect ( ":memory:" ) for fts in ( "FTS5" , "FTS4" , "FTS3" ) : try : conn . execute ( "CREATE VIRTUAL TABLE v USING {} (t TEXT);" . format ( fts ) ) return fts except sqlite3 . OperationalError : continue return Non... | Discovers the most advanced supported SQLite FTS version |
34,679 | def add_click_commands ( module , cli , command_dict , namespaced ) : module_commands = [ item for item in getmembers ( module ) if isinstance ( item [ 1 ] , BaseCommand ) ] options = command_dict . get ( 'config' , { } ) namespace = command_dict . get ( 'namespace' ) for name , function in module_commands : f_options ... | Loads all click commands |
34,680 | def load_commands ( cli , manage_dict ) : namespaced = manage_dict . get ( 'namespaced' ) commands = manage_dict . get ( 'click_commands' , [ ] ) for command_dict in commands : root_module = import_string ( command_dict [ 'module' ] ) group = cli . manage_groups . get ( command_dict . get ( 'group' ) , cli ) if getattr... | Loads the commands defined in manage file |
34,681 | def debug ( version = False ) : if version : print ( __version__ ) return print ( json . dumps ( MANAGE_DICT , indent = 2 ) ) | Shows the parsed manage file - V shows version |
34,682 | def create_shell ( console , manage_dict = None , extra_vars = None , exit_hooks = None ) : manage_dict = manage_dict or MANAGE_DICT _vars = globals ( ) _vars . update ( locals ( ) ) auto_imported = import_objects ( manage_dict ) if extra_vars : auto_imported . update ( extra_vars ) _vars . update ( auto_imported ) msg... | Creates the shell |
34,683 | def find_invalid_filenames ( filenames , repository_root ) : errors = [ ] for filename in filenames : if not os . path . abspath ( filename ) . startswith ( repository_root ) : errors . append ( ( filename , 'Error: File %s does not belong to ' 'repository %s' % ( filename , repository_root ) ) ) if not os . path . exi... | Find files that does not exist are not in the repo or are directories . |
34,684 | def get_config ( repo_root ) : config = os . path . join ( os . path . dirname ( __file__ ) , 'configs' , 'config.yaml' ) if repo_root : repo_config = os . path . join ( repo_root , '.gitlint.yaml' ) if os . path . exists ( repo_config ) : config = repo_config with open ( config ) as f : content = f . read ( ) if not c... | Gets the configuration file either from the repository or the default . |
34,685 | def format_comment ( comment_data ) : format_pieces = [ ] if 'line' in comment_data : format_pieces . append ( 'line {line}' ) if 'column' in comment_data : if format_pieces : format_pieces . append ( ', ' ) format_pieces . append ( 'col {column}' ) if format_pieces : format_pieces . append ( ': ' ) if 'severity' in co... | Formats the data returned by the linters . |
34,686 | def get_vcs_root ( ) : for vcs in ( git , hg ) : repo_root = vcs . repository_root ( ) if repo_root : return vcs , repo_root return ( None , None ) | Returns the vcs module and the root of the repo . |
34,687 | def process_file ( vcs , commit , force , gitlint_config , file_data ) : filename , extra_data = file_data if force : modified_lines = None else : modified_lines = vcs . modified_lines ( filename , extra_data , commit = commit ) result = linters . lint ( filename , modified_lines , gitlint_config ) result = result [ fi... | Lint the file |
34,688 | def last_commit ( ) : try : root = subprocess . check_output ( [ 'hg' , 'parent' , '--template={node}' ] , stderr = subprocess . STDOUT ) . strip ( ) return root . decode ( 'utf-8' ) except subprocess . CalledProcessError : return None | Returns the SHA1 of the last commit . |
34,689 | def modified_files ( root , tracked_only = False , commit = None ) : assert os . path . isabs ( root ) , "Root has to be absolute, got: %s" % root command = [ 'hg' , 'status' ] if commit : command . append ( '--change=%s' % commit ) status_lines = subprocess . check_output ( command ) . decode ( 'utf-8' ) . split ( os ... | Returns a list of files that has been modified since the last commit . |
34,690 | def lint ( filename ) : config = ConfigParser . ConfigParser ( ) try : config . read ( filename ) return 0 except ConfigParser . Error as error : print ( 'Error: %s' % error ) return 1 except : print ( 'Unexpected Error' ) return 2 | Lints an INI file returning 0 in case of success . |
34,691 | def missing_requirements_command ( missing_programs , installation_string , filename , unused_lines ) : verb = 'is' if len ( missing_programs ) > 1 : verb = 'are' return { filename : { 'skipped' : [ '%s %s not installed. %s' % ( ', ' . join ( missing_programs ) , verb , installation_string ) ] } } | Pseudo - command to be used when requirements are missing . |
34,692 | def lint_command ( name , program , arguments , filter_regex , filename , lines ) : output = utils . get_output_from_cache ( name , filename ) if output is None : call_arguments = [ program ] + arguments + [ filename ] try : output = subprocess . check_output ( call_arguments , stderr = subprocess . STDOUT ) except sub... | Executes a lint program and filter the output . |
34,693 | def _replace_variables ( data , variables ) : formatter = string . Formatter ( ) return [ formatter . vformat ( item , [ ] , variables ) for item in data ] | Replace the format variables in all items of data . |
34,694 | def lint ( filename , lines , config ) : _ , ext = os . path . splitext ( filename ) if ext in config : output = collections . defaultdict ( list ) for linter in config [ ext ] : linter_output = linter ( filename , lines ) for category , values in linter_output [ filename ] . items ( ) : output [ category ] . extend ( ... | Lints a file . |
34,695 | def filter_lines ( lines , filter_regex , groups = None ) : pattern = re . compile ( filter_regex ) for line in lines : match = pattern . search ( line ) if match : if groups is None : yield line elif len ( groups ) == 1 : yield match . group ( groups [ 0 ] ) else : matched_groups = match . groupdict ( ) yield tuple ( ... | Filters out the lines not matching the pattern . |
34,696 | def which ( program ) : if ( os . path . isabs ( program ) and os . path . isfile ( program ) and os . access ( program , os . X_OK ) ) : return [ program ] candidates = [ ] locations = os . environ . get ( "PATH" ) . split ( os . pathsep ) for location in locations : candidate = os . path . join ( location , program )... | Returns a list of paths where the program is found . |
34,697 | def _open_for_write ( filename ) : dirname = os . path . dirname ( filename ) pathlib . Path ( dirname ) . mkdir ( parents = True , exist_ok = True ) return io . open ( filename , 'w' ) | Opens filename for writing creating the directories if needed . |
34,698 | def _get_cache_filename ( name , filename ) : filename = os . path . abspath ( filename ) [ 1 : ] home_folder = os . path . expanduser ( '~' ) base_cache_dir = os . path . join ( home_folder , '.git-lint' , 'cache' ) return os . path . join ( base_cache_dir , name , filename ) | Returns the cache location for filename and linter name . |
34,699 | def get_output_from_cache ( name , filename ) : cache_filename = _get_cache_filename ( name , filename ) if ( os . path . exists ( cache_filename ) and os . path . getmtime ( filename ) < os . path . getmtime ( cache_filename ) ) : with io . open ( cache_filename ) as f : return f . read ( ) return None | Returns the output from the cache if still valid . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.