Compare commits
10 Commits
bcbf20ef25
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bb0793669 | |||
| 3426ca535b | |||
| 3a619ee08f | |||
| 76669872ae | |||
| 58fa818128 | |||
| b761fccd69 | |||
| 4f9b35ef7d | |||
| 1bcdc234c1 | |||
| 37c1c75053 | |||
| b9cebe8f5b |
103
AssignerPal.py
103
AssignerPal.py
@@ -1,24 +1,25 @@
|
||||
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 AutoTicket
|
||||
import AutoColor
|
||||
import AutoColor2
|
||||
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
|
||||
|
||||
def assign_urls(dictionary):
|
||||
for key in dictionary:
|
||||
value = input(f"Enter url for '{key}': ")
|
||||
dictionary[key] = value
|
||||
|
||||
def get_team():
|
||||
def get_team(name):
|
||||
user_list = []
|
||||
print("What are the usernames?")
|
||||
print(f"List {name} members.")
|
||||
while True:
|
||||
user_input = input("Add to list (Press Enter to finish): ")
|
||||
if user_input:
|
||||
@@ -44,32 +45,78 @@ def first_time_setup():
|
||||
assign_urls(urls)
|
||||
with open('urls.json', 'w') as file:
|
||||
json.dump(urls, file)
|
||||
users = get_team()
|
||||
users = get_team("users")
|
||||
leads = get_team("leads")
|
||||
with open('team.json', 'w') as file:
|
||||
json.dump(users, file)
|
||||
with open('leads.json', 'w') as file:
|
||||
json.dump(leads, file)
|
||||
|
||||
def choice(urls,users,driver):
|
||||
print("Tickets or Directly?")
|
||||
user_choice = input()
|
||||
if "ti" in user_choice.lower():
|
||||
AutoTicket.auto_ticket(urls,users,driver)
|
||||
if "di" in user_choice.lower():
|
||||
AutoColor.tag_assist(urls,driver)
|
||||
print("More?")
|
||||
if input("y/n : ") == "y":
|
||||
choice(urls,users,driver)
|
||||
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("Do first time set up?")
|
||||
if input("y/n : ") == "y":
|
||||
first_time_setup()
|
||||
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)
|
||||
choice(urls,users,driver)
|
||||
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(7, 0, 0)
|
||||
end_time = datetime.time(17, 0, 0)
|
||||
weekday = datetime.datetime.now().weekday()
|
||||
if start_time <= current_time <= end_time and weekday < 5:
|
||||
while len(driver.window_handles) > 1:
|
||||
driver.switch_to.window(driver.window_handles[1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
try:
|
||||
AutoTicket.auto_ticket(urls, users, driver)
|
||||
except Exception as e:
|
||||
print("An error occurred in AutoTicket.py")
|
||||
print(e)
|
||||
print(traceback.format_exc())
|
||||
while len(driver.window_handles) > 1:
|
||||
driver.switch_to.window(driver.window_handles[1])
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
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 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()
|
||||
61
AutoColor.py
61
AutoColor.py
@@ -4,6 +4,8 @@ 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 random
|
||||
|
||||
# Condensed string finder for lists of strings
|
||||
def found_string(string_list, main_string):
|
||||
@@ -33,11 +35,13 @@ def next_string(list_of_strings):
|
||||
|
||||
# Assign steps in order of queue list without checking tag_count
|
||||
def dumb_make_tags(queues,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
next_queue = next_string(queues)
|
||||
for tag in tags:
|
||||
if found_string(queues, tag.text.lower()) == False:
|
||||
tag.send_keys(Keys.CONTROL + Keys.ENTER)
|
||||
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:
|
||||
@@ -53,9 +57,8 @@ def dumb_make_tags(queues,tags,driver):
|
||||
tag_field = driver.find_element(By.ID, "tag_id")
|
||||
tag_field.send_keys(Keys.END)
|
||||
tag_field.send_keys("/",next(next_queue))
|
||||
print("Please verify tag looks correct. Press enter to continue.")
|
||||
input()
|
||||
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)
|
||||
|
||||
@@ -73,10 +76,12 @@ def select_list_item(list_of_strings):
|
||||
|
||||
# Select every unassigned tag, print queue count, print step name, use user input to choose what tag to assign
|
||||
def guided_make_tags(queues,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
for tag in tags:
|
||||
if found_string(queues, tag.text.lower()) == False:
|
||||
tag.send_keys(Keys.CONTROL + Keys.ENTER)
|
||||
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:
|
||||
@@ -94,9 +99,8 @@ def guided_make_tags(queues,tags,driver):
|
||||
tag_field = driver.find_element(By.ID, "tag_id")
|
||||
tag_field.send_keys(Keys.END)
|
||||
tag_field.send_keys("/",guided_tag)
|
||||
print("Please verify tag looks correct. Press enter to continue.")
|
||||
input()
|
||||
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)
|
||||
|
||||
@@ -116,12 +120,14 @@ def find_lowest_and_increment(dictionary):
|
||||
|
||||
# Check which queue has the least number of assigned workflows.
|
||||
def smart_make_tags(queues,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
tag_count = count_tags(queues,tags)
|
||||
for tag in tags:
|
||||
if found_string(queues, tag.text.lower()) == False:
|
||||
lowest_queue = find_lowest_and_increment(tag_count)
|
||||
tag.send_keys(Keys.CONTROL + Keys.ENTER)
|
||||
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:
|
||||
@@ -137,9 +143,8 @@ def smart_make_tags(queues,tags,driver):
|
||||
tag_field = driver.find_element(By.ID, "tag_id")
|
||||
tag_field.send_keys(Keys.END)
|
||||
tag_field.send_keys("/",lowest_queue)
|
||||
print("Please verify tag looks correct.")
|
||||
input()
|
||||
tag_field.send_keys(Keys.ENTER)
|
||||
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)
|
||||
|
||||
@@ -183,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")
|
||||
@@ -194,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())
|
||||
@@ -230,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)
|
||||
@@ -244,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("Wanna do another? y/n")
|
||||
print("Done! ✧⋆٩(ᵔ ᗜ ᵔ )و ♡✧")
|
||||
print("Wanna do another queue? y/n")
|
||||
answer = input()
|
||||
if answer == "y":
|
||||
tag_assist(queues)
|
||||
tag_assist(urls,driver,users)
|
||||
else:
|
||||
print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)")
|
||||
print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)")
|
||||
|
||||
|
||||
222
AutoColor2.py
Normal file
222
AutoColor2.py
Normal file
@@ -0,0 +1,222 @@
|
||||
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 json
|
||||
import random
|
||||
|
||||
# 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
|
||||
|
||||
def next_string(list_of_strings):
|
||||
index = 0
|
||||
while True:
|
||||
yield list_of_strings[index]
|
||||
index = (index + 1) % len(list_of_strings)
|
||||
|
||||
|
||||
|
||||
# Assign steps in order of queue list without checking tag_count
|
||||
def dumb_make_tags(queues,users,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
next_queue = next_string(queues)
|
||||
for tag in tags:
|
||||
if found_string(users, tag.text.lower()) == False:
|
||||
driver.execute_script("arguments[0].scrollIntoView(true);", tag)
|
||||
tag_href = tag.find_element(By.TAG_NAME, "a").get_attribute("href")
|
||||
driver.execute_script("window.open(arguments[0]);", tag_href)
|
||||
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')))
|
||||
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)
|
||||
tag_field.send_keys("/",next(next_queue))
|
||||
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.")
|
||||
|
||||
# Select every unassigned tag, print queue count, print step name, use user input to choose what tag to assign
|
||||
def guided_make_tags(queues,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
for tag in tags:
|
||||
if found_string(queues, tag.text.lower()) == False:
|
||||
driver.execute_script("arguments[0].scrollIntoView(true);", tag)
|
||||
tag_href = tag.find_element(By.TAG_NAME, "a").get_attribute("href")
|
||||
driver.execute_script("window.open(arguments[0]);", tag_href)
|
||||
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')))
|
||||
print("What should we tag this workflow? ", driver.find_element(By.TAG_NAME, 'h2').text)
|
||||
guided_tag = select_list_item(queues)
|
||||
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)
|
||||
tag_field.send_keys("/",guided_tag)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
# Get lowest_queue string, and increment tag_count for the value for that queue by one.
|
||||
def find_lowest_and_increment(dictionary):
|
||||
if not dictionary:
|
||||
return None
|
||||
|
||||
min_key = min(dictionary, key=dictionary.get)
|
||||
|
||||
dictionary[min_key] += 1
|
||||
|
||||
return min_key
|
||||
|
||||
# Check which queue has the least number of assigned workflows.
|
||||
def smart_make_tags(queues,users,tags,driver):
|
||||
ac = ActionChains(driver)
|
||||
original_window = driver.current_window_handle
|
||||
tag_count = count_tags(queues,tags)
|
||||
for tag in tags:
|
||||
if not found_string(users, tag.text.lower()):
|
||||
driver.execute_script("arguments[0].scrollIntoView(true);", tag)
|
||||
tag_href = tag.find_element(By.TAG_NAME, "a").get_attribute("href")
|
||||
driver.execute_script("window.open(arguments[0]);", tag_href)
|
||||
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')))
|
||||
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")
|
||||
current_tag_value = tag_field.get_attribute("value")
|
||||
if not found_string(users, current_tag_value):
|
||||
lowest_queue = find_lowest_and_increment(tag_count)
|
||||
tag_field.send_keys(Keys.END)
|
||||
tag_field.send_keys("/",lowest_queue)
|
||||
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)
|
||||
|
||||
# Ignore future steps.
|
||||
def future_tag_manip(driver):
|
||||
future_tag_field = driver.find_element(By.ID, "cf-future-tag")
|
||||
future_tag_field.clear()
|
||||
future_tag_field.send_keys("Automation In Progress")
|
||||
|
||||
def filter_steps_manip(driver):
|
||||
step_field = driver.find_element(By.ID, "cf-due-step")
|
||||
step_field.clear()
|
||||
print("")
|
||||
print("Wanna avoid touching a step?")
|
||||
print("Take a look at what's in the queue.")
|
||||
print("If there's anything in there you don't want to tag,")
|
||||
print("copy the step name here, with | to seperate steps.")
|
||||
print("e.g. 'Confirm Disconnect Date Has Passed|Reserve Numbers'")
|
||||
print("or, press Enter to skip")
|
||||
filters = input()
|
||||
if filters != "":
|
||||
step_field.send_keys("^(?!.*(",filters,")).*$")
|
||||
print("")
|
||||
print("This look good? y/n")
|
||||
answer = input()
|
||||
if "n" in answer:
|
||||
print("Let's try that again...")
|
||||
print("")
|
||||
filter_steps_manip()
|
||||
|
||||
|
||||
def automation_picker(queues,users,tags,driver,choice):
|
||||
if choice.lower() == "smart":
|
||||
print("Okay, I'll make you proud (> O ω O)>✎")
|
||||
smart_make_tags(queues,users,tags,driver)
|
||||
elif choice.lower() == "dumb":
|
||||
print("Okay, I make thing go now ─=≡Σ((( つ><)つ")
|
||||
dumb_make_tags(queues,users,tags,driver)
|
||||
else:
|
||||
print("Skipping...")
|
||||
|
||||
def tag_assist(urls,driver,users):
|
||||
print("This is someone's automation tool. If you don't know what you're doing, please abort.")
|
||||
urllist = urls
|
||||
urllist.popitem()
|
||||
with open('leads.json', 'r') as file:
|
||||
leads = json.load(file)
|
||||
#create a list that includes both users and leads
|
||||
elevatedusers = users + leads
|
||||
for key, url in urllist.items():
|
||||
print("Working on ",key)
|
||||
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:
|
||||
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,elevatedusers,tags,driver,"smart")
|
||||
else:
|
||||
automation_picker(users,elevatedusers,tags,driver,"dumb")
|
||||
print("Done! ✧⋆٩(ᵔ ᗜ ᵔ )و ♡✧")
|
||||
print("Goodbye! ヾ(˶ᵔ ᗜ ᵔ˶)")
|
||||
|
||||
136
AutoRecolor.py
Normal file
136
AutoRecolor.py
Normal file
@@ -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()
|
||||
@@ -4,18 +4,33 @@ 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
|
||||
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)
|
||||
|
||||
@@ -57,21 +72,25 @@ def assign_tickets(namecount,driver):
|
||||
driver.switch_to.window(window_handle)
|
||||
break
|
||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "owner")))
|
||||
time.sleep(1)
|
||||
controls = driver.find_element(By.ID, 'ticket-controls').find_elements(By.CLASS_NAME, "ticket-control")
|
||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'select2-container')))
|
||||
owner_button = controls[3].find_element(By.CLASS_NAME, 'select2-container')
|
||||
owner_button.click()
|
||||
search_fields = driver.find_elements(By.CLASS_NAME, 'select2-search__field')
|
||||
owner_field = search_fields[3]
|
||||
owner_field.send_keys(lowest_name)
|
||||
owner_field.send_keys(Keys.ENTER)
|
||||
print("Check to see if this worked, then press enter")
|
||||
input()
|
||||
#assigned_json[lowest_name] +=
|
||||
driver.find_element(By.CLASS_NAME, 'update').click()
|
||||
driver.close()
|
||||
driver.switch_to.window(original_window)
|
||||
|
||||
#assigned_json = {}
|
||||
|
||||
def auto_ticket(urls,users,driver):
|
||||
#for user in users:
|
||||
# assigned_json[user] = 0
|
||||
driver.get(urls['TICKETS'])
|
||||
print("")
|
||||
print("Please use the browser to log in. I won't look (づ_ど)")
|
||||
@@ -80,8 +99,11 @@ def auto_ticket(urls,users,driver):
|
||||
EC.presence_of_element_located((By.CLASS_NAME, "select2-selection__clear"))
|
||||
)
|
||||
finally:
|
||||
time.sleep(2.5)
|
||||
get_filters(driver)
|
||||
time.sleep(2.5)
|
||||
namecount = get_names(users,driver)
|
||||
print(namecount)
|
||||
assign_tickets(namecount,driver)
|
||||
#print(assigned_json)
|
||||
print("Done! ✧⋆٩(ˊ ᗜ ˋ )و ♡✧")
|
||||
@@ -6,3 +6,5 @@ If you're not one of those three people, this will do nothing for you.
|
||||
Clone this repository into an accessible folder, cd into the folder, run pip install Selenium, and then run python AssignerPal.py
|
||||
|
||||
It will prompt you asking for information, and then open a browser. Follow the command line instructions.
|
||||
|
||||
If you ever need to change some of the initial information, you can delete the .json files and rerun the script.
|
||||
|
||||
Reference in New Issue
Block a user