def parseConfig():
  #print 'parseConfig method'
  config = read("config.xml")
  #print config
  changes = config.split('<change>')
  for s in changes[1:]:
    print 'found change'
    
    # Extract timestamp and convert to id
    time = re.search(r'\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}', s)
    #print 'time = ' + time.group()
    id = getID(time.group())
    #print 'id = ' + id

    # Extract level
    level = re.search(r'<level>([\w.:]+)</level>', s)
    #print 'level = [' + level.group(1) + ']'

    # add to history file
    addIfNotPresent(id, time.group(), level.group(1))

  # Now deal with the pre-defined levels
  levels = config.split('<level ')
  for s in levels[1:]:
    # Extract Level a value
    level = re.search(r'id=\"([\w.:]+)\"', s)
    #print 'level = ' + level.group(1)

    # Get thread count
    threads = re.search(r'<threads>(\d+)</threads>', s)
    if threads:  
      #print 'threads = [' + threads.group(1) + ']'

      #Now add threads value to dict
      threadDict[level.group(1).upper()] = threads.group(1)
def checkHistory():
    print "checkHistory method"
    history = read("history.csv")
    entries = history.split("\n")

    # Now define a Timestamp string for the last hour
    now = datetime.datetime.now()
    lastHour = now - timedelta(hours=1)
    print "Last hour: " + str(lastHour)

    for entry in entries[1:]:  # Ignore headers

        # Extract values -> values[0]=id, values[1]=time, values[2]=level
        values = entry.split(",")

        # If current entry was in the last hour but less than now
        if values[1] > str(lastHour):
            if values[1] < str(now):
                print "Entry " + values[0] + " in the last hour"
                return entry

    # If we have found no entry in the last hour
    # return a signal
    print "No entries in the last hour"
    return "current"
def addIfNotPresent(id, time, level):
  #print 'Checking history for ID:' + id

  if id not in changeDict:
    #print 'Not found. Addding'
    tuple = (id, time, level)
    #print tuple
    changeDict[id] = tuple

    # Now add to history file
    csv = read("history.csv")
    #print csv
    line = id + ',' + time + ',' + level.upper()
    #print line
    csv = csv + '\n' + line
    write("history.csv", csv)

  #print changeDict.items()
  return changeDict # Can pass current changeDict back to Client