Hacker News new | past | comments | ask | show | jobs | submit login

In case it's useful to anyone (or they want to pick at my code), here's a quick and dirty python thing I use to automate timestamps on journal entries. It just accepts strings of text and saves them in a file named with today's date and a time above each entry.

  import time

  user_input = ""
  date_string = '-'.join([str(n).zfill(2) for n in time.localtime(time.time())[0:3]])
  while user_input != "q":
   user_input = raw_input("Log entry (q to quit): ")
   with open("time_log_"+date_string+".txt","a") as timelog:
    #timelog.write(time.asctime(time.localtime(time.time()))+'\n')
    timelog.write(
    '-'.join([str(n).zfill(2) for n in time.localtime(time.time())[0:3]])
    + ' '
    + ':'.join([str(n).zfill(2) for n in time.localtime(time.time())[3:5]])
    + ' | '
    + user_input
    + '\n')



Thanks - this is cleaner than what I was using for something similar. Here's my version:

  import datetime
  user_input = raw_input("Log entry: ")
  with open("did.log", "a") as timelog:
      timelog.write('\n')
      timelog.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M (%a)"))
      timelog.write(': ')
      timelog.write(user_input)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: