diff --git a/AssignerPal.py b/AssignerPal.py index f287354..bb757eb 100644 --- a/AssignerPal.py +++ b/AssignerPal.py @@ -49,7 +49,7 @@ def choice(urls,users,driver): if "ti" in user_choice.lower(): AutoTicket.auto_ticket(urls,users,driver) if "di" in user_choice.lower(): - AutoColor.tag_assist(urls,driver) + AutoColor.tag_assist(urls,driver,users) print("Go back to Directly or Tickets choice?") if input("y/n : ") == "y": choice(urls,users,driver) diff --git a/AutoColor.py b/AutoColor.py index 4e33127..8b9e861 100644 --- a/AutoColor.py +++ b/AutoColor.py @@ -5,6 +5,7 @@ from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains import datetime +import random # Condensed string finder for lists of strings def found_string(string_list, main_string): @@ -187,7 +188,7 @@ def automation_picker(queues,tags,driver): print("Skip : Don't assign workflows today :)") choice = input() if choice.lower() == "smart": - print("Okay, I'll make you proud (> ͡⎚ ω ͡⎚)>✎") + print("Okay, I'll make you proud (> O ω O)>✎") smart_make_tags(queues,tags,driver) elif choice.lower() == "guided": print("Okay, you get to do all the work now (-ω-) zzZ") @@ -198,25 +199,17 @@ def automation_picker(queues,tags,driver): else: print("Skipping...") -def get_queues(): - user_list = [] - print("What queues are we working with today?") - while True: - user_input = input("Add to queue list (Press Enter to finish): ") - if user_input: - user_list.append(user_input.lower()) - else: - break - print("I'm working with these queues:", user_list) +def get_queues(users): + print("I'm working with these users:") + print (users) print("") print("This look good? y/n") answer = input() if "n" in answer: - print("Let's try that again...") - print("") - get_queues() + raise Exception("Please rerun AssignerPal init") else: - return user_list + random.shuffle(users) + return users def get_value_from_dictionary(dictionary): keys = list(dictionary.keys()) @@ -234,7 +227,7 @@ def get_value_from_dictionary(dictionary): else: print("Invalid choice. Please enter a valid letter.") -def tag_assist(urls,driver): +def tag_assist(urls,driver,users): print("This is someone's automation tool. If you don't know what you're doing, please abort.") print("Choose URL please:") url = get_value_from_dictionary(urls) @@ -248,13 +241,15 @@ def tag_assist(urls,driver): finally: future_tag_manip(driver) filter_steps_manip(driver) - queues = get_queues() + queues = get_queues(users) tags = driver.find_elements(By.CSS_SELECTOR, "td.tag") automation_picker(queues,tags,driver) - print("Done! ✧⋆٩(ˊ ᗜ ˋ )و ♡✧") + print("Done! ✧⋆٩(ᵔ ᗜ ᵔ )و ♡✧") print("Wanna do another queue? y/n") answer = input() if answer == "y": tag_assist(urls,driver) else: - print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)") \ No newline at end of file + print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)") + + \ No newline at end of file diff --git a/AutoRecolor.py b/AutoRecolor.py new file mode 100644 index 0000000..c3e1270 --- /dev/null +++ b/AutoRecolor.py @@ -0,0 +1,136 @@ +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.by import By +from selenium.webdriver.support.wait import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.common.action_chains import ActionChains +import datetime +import json + +with open('team.json', 'r') as file: + users = json.load(file) + +#Grab usernames +def grab_users(users,driver): + user_count = {} + for user in users: + count = 0 + steps = driver.find_elements(By.CLASS_NAME, "stepHeader") + for step in steps: + child_elements = step.find_elements(By.XPATH, ".//*") + for element in child_elements: + if user in element.text.lower(): + count = +1 + edits = driver.find_elements(By.TAG_NAME, "dt") + for edit in edits: + if user in edit.text.lower(): + count = +1 + user_count[user] = count + if all(value == 0 for value in user_count.values()): + biggest_user = "" + print("I got nothing") + else: + biggest_user = max(user_count, key=user_count.get) + print(biggest_user) + return biggest_user + +# Condensed string finder for lists of strings +def found_string(string_list, main_string): + for string in string_list: + if string in main_string: + return True + return False + +# Get tag_count dictionary +def count_tags(queues,tags): + tag_count = {} + for queue in queues: + count = 0 + for tag in tags: + if queue in tag.text.lower(): + count += 1 + tag_count[queue] = count + return tag_count + +# Assign steps in order of queue list without checking tag_count +def reassign(queues,tags,driver): + ac = ActionChains(driver) + original_window = driver.current_window_handle + for tag in tags: + if found_string(queues, tag.text.lower()) == True and found_string(users, tag.text.lower()) == False: + driver.execute_script("arguments[0].scrollIntoView(true);", tag) + ac.context_click(tag).perform() + WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2)) + for window_handle in driver.window_handles: + if window_handle != original_window: + driver.switch_to.window(window_handle) + break + WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'h2'))) + biggest_user = grab_users(users,driver) + driver.find_element(By.CSS_SELECTOR, "a.edit").click() + try: + element = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.ID, "tag_id")) + ) + finally: + tag_field = driver.find_element(By.ID, "tag_id") + tag_field.send_keys(Keys.END) + if found_string(users,tag_field.get_attribute('value').lower()) == False and biggest_user != "": + tag_field.send_keys("/",biggest_user) + tag_field.send_keys(Keys.ENTER) + WebDriverWait(driver,5).until(EC.presence_of_element_located((By.ID,'stepListHeader'))) + driver.close() + driver.switch_to.window(original_window) + +# Tool to create a menu based on a list. +def select_list_item(list_of_strings): + for i, item in enumerate(list_of_strings): + print(f"{chr(97 + i)}) {item}") + + while True: + choice = input("Please select an option (a, b, c, etc.): ").lower() + if choice.isalpha() and ord(choice) - 97 in range(len(list_of_strings)): + return list_of_strings[ord(choice) - 97] + else: + print("Invalid choice. Please select a valid option.") + +def get_queues(): + user_list = [] + print("What queues are we working with today?") + while True: + user_input = input("Add to queue list (Press Enter to finish): ") + if user_input: + user_list.append(user_input.lower()) + else: + break + print("I'm working with these queues:", user_list) + print("") + print("This look good? y/n") + answer = input() + if "n" in answer: + print("Let's try that again...") + print("") + get_queues() + else: + return user_list + +def tag_assist(): + driver = webdriver.Firefox() + print("This is someone's automation tool. If you don't know what you're doing, please abort.") + url = input("Gimme url plox: ") + driver.get(url) + print("") + print("Please use the browser to log in. I won't look (づ_ど)") + try: + element = WebDriverWait(driver, 500).until( + EC.presence_of_element_located((By.ID, "dueWorkflowSteps_wrapper")) + ) + finally: + queues = get_queues() + tags = driver.find_elements(By.CSS_SELECTOR, "td.tag") + reassign(queues,tags,driver) + print("Done! ✧⋆٩(ˊ ᗜ ˋ )و ♡✧") + print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)") + driver.close() + +tag_assist() \ No newline at end of file