Esempio n. 1
0
def pathLines(value):
    """ Splits path string into lines, discarding comments.

    @param value unparsed path
    @return yields non-empty string value for each valid line
    """
    value = rxsub(',?\s+and\s+', ', ', value)
    for line in value.split('\n'):
        if rxmatch(Rx.fullBcv, line):
            yield rxsplit(Rx.comment, line.strip())[0]
Esempio n. 2
0
def bookRefs(value):
    """ Generates book, chapter and verse reference.


    @param value
    @return yields verse range quad-tuple for each reference
    """
    ref = value[1] if value[1:] else ''
    bookpart = (value[0], )
    for chap in rxsplit(Rx.chapterSeparator, ref):
        match = rxmatch(Rx.verseReference, chap)
        if match:
            vals = tuple((int(v) if v else None) for v in match.groups())
        else:
            vals = ()
        yield bookpart + vals
Esempio n. 3
0
def matchBCV(s):
    try:
        return rxmatch(oneBcvRefPattern, s.strip()).groups()
    except (AttributeError, ):
        return (None, None, None)
import csv
from sys import stdout
from re import match as rxmatch

HEADERS = ['year', 'employee_name', 'status', 'salary', 'pay_basis', 'position']



if __name__ == '__main__':
    parser = ArgumentParser("Compile CSV files with years as names (e.g. 2017.csv)")
    parser.add_argument('paths', type=str, nargs="+", help="Path CSV files with a year as name")
    args = parser.parse_args()
    filenames = args.paths
    # check to see if filenames have a proper year in them

    if not all(rxmatch(r'^\d{4}\.csv$', basename(fn)) for fn in filenames):
        raise InputError("Not all filenames are in YYYY.csv format: %s" % '\n'.join(filenames))


    # set up the CSV
    csvout = csv.writer(stdout)
    csvout.writerow(HEADERS)

    for fname in filenames:
        year = basename(fname)[0:4]
        with open(fname, 'r') as rf:
            csvin = csv.reader(rf)
            next(csvin) # skip header
            for row in csvin:
                csvout.writerow([year] + row)