# Process Interface file.

import os
import sys
import shutil
import glob
import time
import datetime

# Get Current Path
dir_path = os.path.dirname(os.path.realpath(__file__))

# Import VIMS .py
import default_setting
import piupload

# ---------------------------------------------------------------------------------------------------
def main():	
# get Upload Directories from company settings
	defaults = default_setting.defaultSettings()
	uploadDirs = default_setting.companySettings(defaults)
	print(uploadDirs['interfacein'])			
# process PI from upload directory
	file_path_xls = os.path.join(dir_path, '../vimsin/piupload.xlsx')
	for pi in glob.glob(uploadDirs['interfacein']+"\\pi*.xlsx"):
		print(pi)
		shutil.copy(pi, file_path_xls)
		piupload.main()
		if os.path.exists(pi):
			os.remove(pi)
#		continue
# ---------------------------------------------------------------------------------------------------						
if __name__ == '__main__':
	while True:
		main()
		for remaining in range(60, 0, -1):
			sys.stdout.write("\r")
			sys.stdout.write("{:2d} seconds remaining.".format(remaining))
			sys.stdout.flush()
			time.sleep(1)
	
