# Append to a text file

import os
import sys
from datetime import datetime

# Get Current Path
dir_path = os.path.dirname(os.path.realpath(__file__))

def main():
    logFile = "vimslogfile.txt"
    if (len(sys.argv) > 1 and (sys.argv[1] != '' and sys.argv[1] != "''")):
        logFile = sys.argv[1].replace("'","")
    if (len(sys.argv) > 2 and (sys.argv[2] != '' and sys.argv[2] != "''")):
        textFile = sys.argv[2].replace("'","")
        fileappend(logFile,textFile)
    
def fileappend(logFile,textFile):
# timestamp
    now = datetime.now()
# opening first file in append mode and second file in read mode
    f1 = open(logFile, 'a+')
    f2 = open(textFile, 'r') 
# appending the contents of the second file to the first file
    f1.write('\n')
    f1.write(str(now)+'\n')
    f1.write(f2.read())
    f1.write('\n')
    f1.close()
    f2.close()
    
if __name__ == '__main__':
    main()