def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "ho:v", ["help", "output="])
        except getopt.error, msg:
            raise Usage(msg)

        # option processing
        for option, value in opts:
            if option == "-v":
                verbose = True
            if option in ("-h", "--help"):
                raise Usage(help_message)
            if option in ("-o", "--output"):
                output = value
        if len(args) == 6:
            sqlname, etcsv, func, zonetempId, windinc, comforttype = args
        if len(args) == 5:
            sqlname, etcsv, func, zonetempId, windinc = args
            comforttype = 80
        if len(args) == 4:
            sqlname, etcsv, func, zonetempId = args
            windinc, comforttype = 2, 80
        windinc, comforttype = float(windinc), float(comforttype)
        cursor = eplussql.getcursor(sqlname)
        etrows = mycsv.readcsv(etcsv)
        etrows.pop(0)
        etrows = [[float(cell) for cell in row] for row in etrows]
        if func == "hours":
            printhours(cursor, etrows, func, zonetempId, windinc, comforttype)
        if func == "alldata":
            printalldata(cursor, etrows, func, zonetempId, windinc, comforttype)
def csv2html():
    header, data = mycsv.readcsv(mycsv.getdata())
    start = "<html>\n<body>\n<table>\n"
    end = "</table>\n</body>\n</html>"
    header_row = "".join(["<th>%s</th>" % i for i in header])
    header_row = "<tr>%s</tr>\n" % header_row
    data_row_set = []
    for i in data:
        data_row = "".join(["<td>%s</td>" % j for j in i])
        data_row_set.append("<tr>%s</tr>\n" % data_row)
    data_row_set = "".join(data_row_set)
    together = start + header_row + data_row_set + end
    return together
Exemple #3
0
def csv2html(data):
    print("<html>")
    print("<body>")
    print("<table>")
    header, data = mycsv.readcsv(data)
    print("<tr>", end="")
    for head in header:
        print("<th>" + head + "</th>", end="")
    print("</tr>")    
    for row in data:
        print("<tr>", end="")
        for val in row:
            print("<td>" + val + "</td>", end="")
        print("</tr>")  
    print("</tr>" )    
    print("</body>")
    print("</table>")
    print("</html>")
Exemple #4
0
def csv2xml(data):
    print("<?xml version=\"1.0\"?>")
    print("<file>")
    header, data = mycsv.readcsv(data)
    print("<headers>", end="")
    h = []
    for head in header:
        h.append(head)
    print(",".join(h), end="")
    print("</headers>")

    print("<data>")
    for row in data:
        print("<record>")
        for h, val in zip(header, row):
            r = "<" + h + ">" + val + "</" + h + ">\n"
            r = r.replace(" ", "_")
            print(r, end="")
        print("</record>")

    print("</data>")
    print("</file>")
def csv2json():
    header, data = mycsv.readcsv(mycsv.getdata())
    start = '{\n'
    end = "\n}"

    header_element = ",\n".join(
        ['\t\t"%s"' % header[i] for i in range(len(header))])
    header_body = '\t"headers": [\n' + header_element + "\n\t],"

    data_body3 = []
    data_body4 = []

    for j in data:
        data_body2 = []
        for i in range(len(header)):
            data_body = '\n\t\t\t"%s": "%s"' % (header[i], j[i])
            data_body2.append(data_body)
            data_body3 = "\n\t\t{" + ",".join(data_body2) + "\n\t\t}"
        data_body4.append(data_body3)
    data_body_final = '\n\t"data": [' + ",".join(data_body4) + "\n\t]"

    together = start + header_body + data_body_final + end
    return together
Exemple #6
0
def csv2xml():
    header, data = mycsv.readcsv(mycsv.getdata())
    start = '<?xml version="1.0"?>\n<file>'
    end = "\n</file>"
    header2 = [i.replace(" ", "_") for i in header]
    header_body = "\n  <headers>%s</headers>" % (",".join(
        [header[i] for i in range(len(header))]))

    data_body3 = []
    data_body4 = []

    for j in data:
        data_body2 = []
        for i in range(len(header2)):
            data_body = "<%s>%s</%s>" % (header2[i], j[i], header2[i])
            data_body2.append("".join(data_body))
            data_body3 = "\n    <record>\n      %s\n    </record>" % (
                "".join(data_body2))
        data_body4.append(data_body3)
    data_body_final = "\n  <data>%s\n  </data>" % "".join(data_body4)

    together = start + header_body + data_body_final + end
    return together
Exemple #7
0
import mycsv
from jinja2 import Environment, PackageLoader, select_autoescape

#get data
header, data = mycsv.readcsv(mycsv.getdata())

#write HTML table
#get templates from app
environ = Environment(loader=PackageLoader('csv2html', 'templates'),
                      autoescape=select_autoescape(['html', 'json']))

#get template from available templates
template = environ.get_template('testJSON')

print(template.render(header=header, data=data))