import v3_Full_Auto_case_Generator
import v3_Full_Auto_case_Checker
import os
import time
import threading
import json

order_folder = r'W:\LBS\OC\To Be processes\_General\Data Registration\Case Order'

def main_start():
    
    '''
        This is a Script to Automate daily testing. It takes input from a user as  json file
        and generates a Client Case Batch file as xlsx, uploads them to specified location, and
        monitors systems upload process. After successful or on unsuccessful upload, user is notified
        by directly by email. Users json file is generated by AHK(AutoHotKey) script which contains all
        possible case variations and all possible instance uploads by country and environment (TEST/UAT).
        Sqlite3 database is used to track every users order number and case number, it also tracks amount
        of unsuccessful upload orders and cases. Every orders monitoring is executed by individual thread.
    '''

    while True:

        for file in os.listdir(order_folder):
            data = v3_Full_Auto_case_Generator.start_work(f'{order_folder}\\{file}')
            print(json.dumps(data, indent = 2))
            print(time.strftime("%d_%H:%M", time.localtime()))
            os.remove(f'{order_folder}\\{file}')
            thread = threading.Thread(target=v3_Full_Auto_case_Checker.one_thread, args=(data,))
            thread.start()
            
        time.sleep(60)
               
main_start()
