#!/usr/bin/env python

# Metarace : Cycle Race Abstractions
# Copyright (C) 2012  Nathan Fraser
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Dump the content of the shared namebank to a CSV file.

Dump file has the columns of the NameBank

"""

from __future__ import print_function

import os
import sys
import metarace
from metarace import namebank
from metarace import ucsv
if len(sys.argv) != 2:
    print('Usage: dump_namebank filename')
    sys.exit(1)
with open(sys.argv[1], 'wb') as f:
    metarace.init()
    cw = ucsv.UnicodeWriter(f)
    cw.writerow([u'ID',u'First',u'Last',u'Club',u'Cat',u'State',
                 u'DoB',u'Gender', u'Nation', u'Postcode', u'Para', 'UCI ID'])
    with namebank.namebank() as n:
        for r in n:
            cw.writerow(r)
