import json, time
from copy import deepcopy

# CAD comment log Watcher
# Look for changes in the CAD comment log
# jdalbey  7/6/2019

lastLineNum = 0

# Utility functions
def isEmpty(cmsitem):
    return cmsitem == ",,,,,"
def isFull(cmsitem):
    return not isEmpty(cmsitem)

# Read the cms message file
def readFile():     
    text_file = open("../../CADcomments.log", "r")
    lines = text_file.read().split('\n')
    return lines
    
def setup():
    # nothing needed for setup
    return

# Retrieve new messages from CAD comment log 
def getLogEntries():
    global lastLineNum
    msgList = readFile()
    currList = []
    currList = msgList[lastLineNum:]    # new items since last file read
    lastLineNum = len(msgList)-1
    return currList

def main():
    setup()
    # Loop Forever
    while True:
        # Look for changed messages
        answer = getLogEntries()
        # Output results
        for item in answer:
            print item
        # wait 
        time.sleep(5)

if __name__ == "__main__":
    main()
