#!/usr/bin/env python # -*- coding: utf-8 -*- # Import the code needed to manage files. import os #...for parsing the arguments. import argparse #...for the logging. import logging as lg # Import the JSON library. import json if __name__ == "__main__": print("*") print("*==================================*") print("* CERN@school - cluster page maker *") print("*==================================*") # Get the datafile path from the command line parser = argparse.ArgumentParser() parser.add_argument("inputPath", help="Path to the JSON file describing the clusters.") #parser.add_argument("outputPath", help="The path for the output files.") parser.add_argument("-v", "--verbose", help="Increase output verbosity", action="store_true") args = parser.parse_args() ## The path to the data file. inputpath = args.inputPath # Set the logging level to DEBUG. if args.verbose: level=lg.DEBUG else: level=lg.INFO # Configure the logging. lg.basicConfig(filename='log_pagemaker.txt', filemode='w', level=level) print("*") print("* Input path : '%s'" % (inputpath)) print("*") ## The kluster JSON filename. jfname = inputpath + "/klusters.json" if not os.path.exists(jfname): raise IOError("NO_EXIST") exit() ## The JSON filename. jf = open(jfname, "r") ## The JSON data. jd = json.load(jf) jf.close() #print json.dumps(jd, indent=4) s = "" s += "\n" s += "\n" s += " \n" s += " CERN@school clusters\n" s += " \n" s += " \n" # Loop over the contents of the JSON (i.e. the klusters). for kl in jd: lg.info(" * Found kluster with ID: '%s'." % (kl['id'])) imgname = "%s.png" % (kl['id']) s += "

%s

\n" % (kl['id']) s += " \n" s += " \n" % (imgname) s += " \n" % (kl['radius_uw']) s += " \n" % (kl['size']) s += " \n" % (kl['isedgekluster']) s += "
Radius%6.2f
Size%d
On the edge?%s
\n" lg.info(" *") s += " \n" s += "" # Write the html file (test of the JSON and images). with open(inputpath + "/index.html", "w") as wpf: wpf.write(s)