old_contents: #!/usr/bin/env python
  """
  Read dcache log files from ./logs directory and write out processed logs to ./processed_logs directory, expects
  year for logs as first
  """
  
  import os
  import re
  import datetime
  import pytz
  
  TZ_NAME = 'US/Central'
  
  # looking for billing-YYYY.MM.DD
  date_re = re.compile(r'billing-(?:error-)?(\d{4}.\d{2}.\d{2})')
  # looking for MM.DD HH:MM:SS ...   the rest of the line is variable depending on message type
  billing_re = re.compile(r'\d{2}.\d{2}\s+(\d{2}:\d{2}:\d{2})\s+(.*)')
  timezone = pytz.timezone(TZ_NAME)
  for logfile in os.listdir('./logs'):
      output = open('./processed_logs/{0}'.format(logfile), 'w')
      date_match = date_re.match(logfile)
      if not date_match:
          print "Can't match {0}".format(logfile)
          continue
      date = date_match.group(1).split('.')
      for line in open("./logs/" + logfile,'r'):
          field_match = billing_re.search(line)
          if field_match is None:
              print "Can't match {0}".format(line)
              continue
          time = field_match.group(1).split(':')
          # datetime(year, month, day, hour, minute, sec)
          timestamp = timezone.localize(datetime.datetime(int(date[0]),
                                                          int(date[1]),
                                                          int(date[2]),
                                                          int(time[0]),
                                                          int(time[1]),
                                                          int(time[2])))
          output.write("{0} {1}\n".format(timestamp.isoformat(),
                                          field_match.group(2)))
  
new_contents: #!/usr/bin/env python
  """
  Read dcache log files from ./logs directory and write out processed logs to ./processed_logs directory, expects
  year for logs as first
  """
  
  import os
  import re
  import datetime
  import pytz
  
  TZ_NAME = 'US/Central'
  
  # looking for billing-YYYY.MM.DD
  date_re = re.compile(r'billing-(?:error-)?(\d{4}.\d{2}.\d{2})')
  # looking for MM.DD HH:MM:SS ...   the rest of the line is variable depending on message type
  billing_re = re.compile(r'\d{2}.\d{2}\s+(\d{2}:\d{2}:\d{2})\s+(.*)')
  timezone = pytz.timezone(TZ_NAME)
  for logfile in os.listdir('./logs'):
      output = open('./processed_logs/{0}'.format(logfile), 'w')
      date_match = date_re.match(logfile)
      if not date_match:
          print "Can't match {0}".format(logfile)
          continue
      date = date_match.group(1).split('.')
      previous_line = ""
      for line in open("./logs/" + logfile,'r'):
          if line.count("[") != line.count("]"):
              # line got continued
              if previous_line == "":
                  previous_line = line
                  continue
              else:
                  line = previous_line.strip() + line.strip()
                  previous_line = ""
          field_match = billing_re.search(line)
          if field_match is None:
              print "Can't match {0}".format(line)
              continue
          time = field_match.group(1).split(':')
          # datetime(year, month, day, hour, minute, sec)
          timestamp = timezone.localize(datetime.datetime(int(date[0]),
                                                          int(date[1]),
                                                          int(date[2]),
                                                          int(time[0]),
                                                          int(time[1]),
                                                          int(time[2])))
          output.write("{0} {1}\n".format(timestamp.isoformat(),
                                          field_match.group(2)))
  
subject: Handle lines that are split