<commit_before>#!/usr/bin/env python
# csv2html
# Copyright (c) 2013, 2014, 2017 dbohdan. All rights reserved.
# License: BSD-3. See the file LICENSE.
'''
This module converts CSV files to HTML tables. It can be used as a standalone
program.
'''

from __future__ import print_function

from . import __version__

import argparse
import csv
import os
import sys
import tablegen


DEFAULT_DELIMITER = ","


def convert_csv_to_html(inputstream, outputstream, title='',
                        delim=DEFAULT_DELIMITER, nstart=0, skipheader=False,
                        renum=False, completedoc=False):
    '''
    Takes CSV data from inputstream (an iterable) and outputs an HTML table to
    outputstream (anything with a write method that takes a string).
    '''

    # Read the CSV stream.
    csvreader = csv.reader(inputstream, dialect='excel',
                           delimiter=delim)
    nrow = 0 # The row number counter.

    outputstream.write(tablegen.start(completedoc, title))
    if not skipheader:
        row = csvreader.next()
        outputstream.write(tablegen.row(row, True))
    while nrow < nstart:
        csvreader.next()
        nrow += 1
    for row in csvreader:
        if renum:
            # If there is no zeroth header row, add one to the new row number to
            # correct for the rows being counted from zero. Do the same if
            # we're started from nstart.
            row[0] = str(nrow - nstart + int(skipheader or nstart > 0))
        outputstream.write(tablegen.row(row))
        nrow += 1
    outputstream.write(tablegen.end(completedoc))


def main():
    '''
    This function is called when the module is run as the main program.
    It handles command line options and opening files for convert_csv_to_html.<commit_msg>Bugfix: Increment row number after header row<commit_after>#!/usr/bin/env python
# csv2html
# Copyright (c) 2013, 2014, 2017 dbohdan. All rights reserved.
# License: BSD-3. See the file LICENSE.
'''
This module converts CSV files to HTML tables. It can be used as a standalone
program.
'''

from __future__ import print_function

from . import __version__

import argparse
import csv
import os
import sys
import tablegen


DEFAULT_DELIMITER = ","


def convert_csv_to_html(inputstream, outputstream, title='',
                        delim=DEFAULT_DELIMITER, nstart=0, skipheader=False,
                        renum=False, completedoc=False):
    '''
    Takes CSV data from inputstream (an iterable) and outputs an HTML table to
    outputstream (anything with a write method that takes a string).
    '''

    # Read the CSV stream.
    csvreader = csv.reader(inputstream, dialect='excel',
                           delimiter=delim)
    nrow = 0 # The row number counter.

    outputstream.write(tablegen.start(completedoc, title))
    if not skipheader:
        row = csvreader.next()
        outputstream.write(tablegen.row(row, True))
        nrow += 1
    while nrow < nstart:
        csvreader.next()
        nrow += 1
    for row in csvreader:
        if renum:
            # If there is no zeroth header row, add one to the new row number to
            # correct for the rows being counted from zero. Do the same if
            # we're started from nstart.
            row[0] = str(nrow - nstart + int(skipheader or nstart > 0))
        outputstream.write(tablegen.row(row))
        nrow += 1
    outputstream.write(tablegen.end(completedoc))


def main():
    '''
    This function is called when the module is run as the main program.
    It handles command line options and opening files for convert_csv_to_html.
{'fraction_non_alphanumeric': 0.08129855715871254, 'fraction_numerical': 0.011376248612652608, 'mean_word_length': 2.605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2316539', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1004, 'n_words': 379}