#!/bin/env python from csv import reader from os.path import isfile from sys import argv, exit def quit(): print "\nStiskni ENTER pro konec..." raw_input() exit() def main(): if len(argv) < 2: print "Zadej CSV soubor jako parametr." quit() csvPath = argv[1] if not isfile(csvPath): print "Soubor '%s' neexistuje." % csvPath quit() csvFile = open(csvPath, 'rb') parser = reader(csvFile, dialect='excel', delimiter=';') html = [''] for i, row in enumerate(parser): eo = 'odd' if i % 2 else 'even' html.append(' ' % (eo, i)) for j, cell in enumerate(row): cell = cell.replace('&', '&') cell = cell.replace('<', '<') html.append(' ' % (j, i, j, cell)) html.append(' ') html.append('
%s
') htmlTxt = '\n'.join(html) htmlFile = open(csvPath + '.html', 'wt') htmlFile.write(htmlTxt) htmlFile.close() print "\n\nHOTOVO" quit() try: print "Konverze csv souboru do html tabulky." print "Copyright (c) 2007, Petr Mach, gsl@seznam.cz" print "Licence: GPL v 2.0, http://www.gnu.org/licenses/gpl-2.0.html" print main() except Exception, e: print "\n\nZACHYCENA CHYBA V PROGRAMU:\n" print e quit()