def render(wd, htmlFilename, dataFilename): template = open(os.path.join(options.mainDir, "template.html")).read() open(htmlFilename, "w").write(template) workUnits = serialization_json.fromFile(options.dbFile) def dateToUnixTime(w): ww = copy.deepcopy(w) dd = time.mktime(ww.date.timetuple()) ww.date = dd return ww workUnits = list(map(dateToUnixTime, workUnits)) filenameOut = dataFilename ser = json.dumps(workUnits, cls=serialization_json.Encoder, indent=4) # Need to dump as javascript object... lines = ser.split("\n") out = ["var data ="] for l in lines: l = re.sub(r'"(\w+)":', r"\1:", l) l = re.sub(r'comment.*?".*?"', r'comment:"anon"', l) out.append(l) open(filenameOut, "w").write("\n".join(out))
def commandLineEnterWorkDone(dbFile): type = input("What category of work did you do?\n") length = float(input("How long did you work for (hours)?\n")) if length < 0: raise Exception("Invalid len: %f." % length) comment = input("Comment?\n") workUnit = work_unit.WorkDone(type, length, comment) if os.path.isfile(dbFile): W = serialization_json.fromFile(dbFile) else: W = [] W.append(workUnit) serialization_json.toFile(dbFile, W)
if os.path.isfile(dbFile): W = serialization_json.fromFile(dbFile) else: W = [] W.append(workUnit) serialization_json.toFile(dbFile, W) if __name__ == "__main__": dbFile = options.dbFile htmlFile = options.htmlFile args = getArgs() if args.edit_db is True: cmd = "vim %s" % options.dbFile print(cmd) os.system(cmd) exit(0) if args.open_browser is True: webbrowser.open_new_tab(htmlFile) exit(0) if not args.regen_html: commandLineEnterWorkDone(dbFile) wd = serialization_json.fromFile(dbFile) render_html.render(wd, htmlFile, options.dataFile)