genhtml.py (1807B)
1 #!/usr/bin/env python3 2 import gt2 3 from jinja2 import Environment, PackageLoader, select_autoescape 4 import os 5 6 if __name__ == "__main__": 7 8 env = Environment( 9 loader=PackageLoader( "genhtml", package_path="templates" ), 10 autoescape=select_autoescape() 11 ) 12 13 index = env.get_template( "index.html" ) 14 con = env.get_template( "con.html" ) 15 16 headers = [ gt2.c[i][0] for i in range( len( gt2.c ) ) ] 17 18 os.makedirs( "html", exist_ok=True ) 19 for j in range( len( gt2.c ) ): 20 for k in range( len( gt2.c ) ): 21 with open( "./html/" + gt2.c[j][0] + gt2.c[k][0] + ".html", "x" ) as f: 22 source = gt2.c[j][0] 23 dest = gt2.c[k][0] 24 25 fpathe, fpathv, cpathe, cpathv = gt2.bestpaths( j, k ) 26 27 fprice = sum( [ gt2.edge_prices[i] for i in fpathe ] ) 28 ftime = sum( [ gt2.edge_times[i] for i in fpathe ] ) 29 cprice = sum( [ gt2.edge_prices[i] for i in cpathe ] ) 30 ctime = sum( [ gt2.edge_times[i] for i in cpathe ] ) 31 f.write( con.render( c=gt2.c, edge_middel=gt2.edge_middel, fastpath_verts=fpathv, fastpath_edges=fpathe, cheappath_verts=cpathv, cheappath_edges=cpathe, edge_prices=gt2.edge_prices, edge_times=gt2.edge_times, source=source, dest=dest, fprice=fprice, ftime=ftime, cprice=cprice, ctime=ctime ) ) 32 33 with open( "./html/index.html", "x" ) as f: 34 f.write( index.render( headers=headers ) ) 35 #f.write( index.render( c=gt2.c, edge_middel=gt2.edge_middel, fastpath_verts=fpathv, fastpath_edges=fpathe, cheappath_verts=cpathv, cheappath_edges=cpathe, lenf=len( fpathe ), lenc=len( cpathe ), edge_prices=gt2.edge_prices, edge_times=gt2.edge_times, source=source, dest=dest, fprice=fprice, ftime=ftime, cprice=cprice, ctime=ctime ) )