Advertisement
Guest User

Untitled

a guest
Sep 11th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #!/usr/bin/python
  2. import datetime
  3. import ConfigParser
  4. import csv
  5. import os
  6. from mako.template import Template
  7.  
  8. # variables
  9. config = ConfigParser.ConfigParser()
  10. rconfig = ConfigParser.RawConfigParser()
  11. template = Template(filename='worklog.html')
  12.  
  13. # load total time from .ini
  14. config.read("worklog.ini")
  15. rconfig.read("worklog.ini")
  16. total_time = config.get("time", "total")
  17.  
  18. # calculate and write new total time
  19. new_total_time = int(total_time)
  20. total_time_human = str(datetime.timedelta(seconds=new_total_time))
  21. print "Your work total time is %s" % total_time_human
  22.  
  23. # convert csv to dictionary
  24. input_file = csv.DictReader(open("worklog.csv"))
  25.  
  26. # prepare lists
  27. work_start_var = []
  28. work_stop_var = []
  29. work_time_var = []
  30. work_note_var = []
  31.  
  32. # prepare variables for mako
  33. for row in input_file:
  34.     work_start_var.append(row["date_start"])
  35.     work_stop_var.append(row["date_stop"])
  36.     work_time_var.append(row["work_time"])
  37.     work_note_var.append(row["note"])
  38.  
  39. # create html with mako
  40. with open('index.html','w+') as webdesign:
  41.     webdesign.write(template.render(total_time_html = total_time_human,date_start_html = '<br>'.join(map(str, work_start_var)),date_stop_html = '<br>'.join(map(str, work_stop_var)),work_time_html = '<br>'.join(map(str, work_time_var)),work_note_html = '<br>'.join(map(str, work_note_var))))
  42.  
  43. os.system("cp index.html /home/jin/swl/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement