diff --git a/AssignerPal.py b/AssignerPal.py index fbb7aac..8ab63fb 100644 --- a/AssignerPal.py +++ b/AssignerPal.py @@ -5,8 +5,10 @@ import json import os import datetime import time +import random +import traceback -urls = {"NOC-PROV": "", "NOC-PROV-ADV" : "", "PROV-DSL" : "", "PROV-FIBER":"", "PROV-IPBB":"","PROV-MISC":"","FUS-PROV":"","TICKETS":""} +urls = {"NOC-PROV":"","NOC-PROV-ADV":"","CONSUMER-PROV":"","TICKETS":""} tickets_sorted = False @@ -47,25 +49,63 @@ def first_time_setup(): with open('team.json', 'w') as file: json.dump(users, file) +def show_loading_bar(duration): + start_time = time.time() + while True: + elapsed_time = time.time() - start_time + progress = elapsed_time / duration + bar_length = 30 + filled_length = int(progress * bar_length) + bar = '#' * filled_length + '-' * (bar_length - filled_length) + percent = round(progress * 100, 2) + remaining_time = round(duration - elapsed_time, 2) + remaining_hours = int(remaining_time / 3600) + remaining_minutes = int((remaining_time % 3600) / 60) + remaining_seconds = int(remaining_time % 60) + print(f"Waiting: [{bar}] {percent}% | Remaining Time: {remaining_hours}h {remaining_minutes}m {remaining_seconds}s", end='\r') + if elapsed_time >= duration: + break + time.sleep(0.5) + print("\nWait time complete!") + def main(): if os.path.exists('urls.json'): print("Skipping first time setup") else: first_time_setup() driver = webdriver.Firefox() - with open('urls.json', 'r') as file: - urls = json.load(file) - with open('team.json', 'r') as file: - users = json.load(file) while True: + with open('urls.json', 'r') as file: + urls = json.load(file) + with open('team.json', 'r') as file: + users = json.load(file) current_time = datetime.datetime.now().time() - start_time = datetime.time(9, 0, 0) + start_time = datetime.time(7, 0, 0) end_time = datetime.time(17, 0, 0) - if start_time <= current_time <= end_time: - AutoTicket.auto_ticket(urls, users, driver, tickets_sorted) - AutoColor2.tag_assist(urls, driver, users) + weekday = datetime.datetime.now().weekday() + if start_time <= current_time <= end_time and weekday < 5: + try: + AutoTicket.auto_ticket(urls, users, driver) + except Exception as e: + print("An error occurred in AutoTicket.py") + print(e) + print(traceback.format_exc()) + try: + AutoColor2.tag_assist(urls, driver, users) + except Exception as e: + print("An error occurred in AutoColor2.py") + print(e) else: - print("It's after hours. I'm not doing anything.") - time.sleep(7200) # Sleep for 2 hours + print("It's after hours or on the weekend. I'm not doing anything.") + current_time = datetime.datetime.now().time() + weekday = datetime.datetime.now().weekday() + if start_time <= current_time <= end_time and weekday < 5: + sleep_duration = random.uniform(5400, 7200) # Random amount of time between 1.5 hours and 2 hours + else: + next_start_time = datetime.datetime.combine(datetime.date.today(), start_time) + if current_time > end_time or weekday >= 5: + next_start_time += datetime.timedelta(days=1) + sleep_duration = (next_start_time - datetime.datetime.now()).total_seconds() + random.uniform(0, 5400) # Time until next start time + random amount between 0 and 1.5 hours + show_loading_bar(sleep_duration) #driver.close() main() \ No newline at end of file diff --git a/AutoColor2.py b/AutoColor2.py index 1fe4649..8f4fd83 100644 --- a/AutoColor2.py +++ b/AutoColor2.py @@ -203,6 +203,7 @@ def tag_assist(urls,driver,users): future_tag_manip(driver) #filter_steps_manip(driver) tags = driver.find_elements(By.CSS_SELECTOR, "td.tag") + random.shuffle(users) if "NOC" in key: automation_picker(users,tags,driver,"smart") else: diff --git a/AutoTicket.py b/AutoTicket.py index fcf70b7..ca1e201 100644 --- a/AutoTicket.py +++ b/AutoTicket.py @@ -7,18 +7,29 @@ from selenium.webdriver.common.action_chains import ActionChains import datetime import json import time +import traceback def get_filters(driver): print("Setting up filters...") driver.find_element(By.CLASS_NAME, "select2-selection__clear").click() group_fields = search_fields = driver.find_elements(By.CLASS_NAME, "select2-search__field") + print("Group Fields Length: ", len(group_fields)) group_fields[1].send_keys("noc-prov") group_fields[1].send_keys(Keys.ENTER) group_fields[1].send_keys("provisioning") group_fields[1].send_keys(Keys.ENTER) - driver.find_element(By.CSS_SELECTOR, ".fa-cogs").click() - clear_buttons = driver.find_elements(By.CLASS_NAME, "select2-selection__clear") - clear_buttons[1].click() + addtl_opts = driver.find_element(By.CLASS_NAME, "addtl_opts") + addtl_opts.click() + addtl_opts.click() + if "collapsed" in addtl_opts.get_attribute("class"): + addtl_opts.click() + try: + clear_buttons = driver.find_elements(By.CLASS_NAME, "select2-selection__clear") + print("Found Clear Buttons") + clear_buttons[1].click() + print("Clicked Clear Button [1]") + except: + print("No Clear Button [1]") driver.find_element(By.CLASS_NAME, "control-label").click() driver.find_element(By.CSS_SELECTOR, ".search-btn").click() WebDriverWait(driver, 3) @@ -77,7 +88,7 @@ def assign_tickets(namecount,driver): #assigned_json = {} -def auto_ticket(urls,users,driver,tickets_sorted): +def auto_ticket(urls,users,driver): #for user in users: # assigned_json[user] = 0 driver.get(urls['TICKETS']) @@ -88,8 +99,8 @@ def auto_ticket(urls,users,driver,tickets_sorted): EC.presence_of_element_located((By.CLASS_NAME, "select2-selection__clear")) ) finally: - if tickets_sorted == False: - get_filters(driver) + time.sleep(2.5) + get_filters(driver) time.sleep(2.5) namecount = get_names(users,driver) print(namecount)