from selenium import webdriver import AutoTicket import AutoColor2 import json import os import datetime import time import random import traceback 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(): user_list = [] print("What are the usernames?") while True: user_input = input("Add to list (Press Enter to finish): ") if user_input: user_list.append(user_input.lower()) else: break print("I'm working with these users:", user_list) print("") print("This look good? y/n") answer = input() if "n" in answer: print("Let's try that again...") print("") get_team() else: return user_list def first_time_setup(): print("Initiating first time set up") print("To ensure internal security, you will need to provide urls for each location,") print("As well as employee usernames (first.last)") print("If you don't know, you shouldn't be using this script.") assign_urls(urls) with open('urls.json', 'w') as file: json.dump(urls, file) users = get_team() 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() 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: 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 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()