import pyautogui import time from datetime import date # Gets today's date at stores it in "date" today = date.today() date = today.strftime("%B %d %Y") # Stores coordinate values for later use coordinates = { "new_doc": [455, 324], "rename_doc": [140, 135], "homepage_tab": [360, 20], "bulleted_list": [1039, 190], "course_name": [150, 145], } def type_and_enter(text): pyautogui.typewrite(text) pyautogui.press("enter") def copy_and_paste_course_name(): # Move mouse to the top left of the screen to where it says the course name (ex. History). Highlight the course name and copy it. pyautogui.moveTo(coordinates["course_name"]) pyautogui.dragTo(pyautogui.locateOnScreen("stop_highlighting.png", confidence = 0.9)[0], coordinates["course_name"][1], button = "left") copy() # Go to tab with the google doc and backspace, since the next line should be tabbed in. Paste the course name, press enter and tab to prepare the formatting to add assignmnets under the course. pyautogui.click(doc_tab, button = "left") time.sleep(0.5) pyautogui.press("backspace") time.sleep(0.3) paste() time.sleep(0.3) pyautogui.press("enter") time.sleep(0.3) pyautogui.press("tab") def copy_and_paste_assignment(i): # Highlight the assignment, copy it, go back to the doc tab, and paste it. Press enter and tab to prepare the formatting to add more assignments. pyautogui.moveTo(358, i) pyautogui.dragRel(1000, 0, button = "left") copy() pyautogui.click(doc_tab, button = "left") time.sleep(0.5) paste() pyautogui.press("enter") pyautogui.press("tab") def for_each_tab(tab): # Detect whether or not there are any upcoming assignments in a given course; if there are, locate the upcoming assignments section header upcoming_assignments = pyautogui.locateOnScreen("upcoming_assignments.png") # Locate the other sections (such as "past assignments," "undated assignments") sections = list(pyautogui.locateAllOnScreen("section_corner.png")) # If there are upcoming assignments in this course... if upcoming_assignments != None: # If there are any other section headers ("past assignments," "undated assignments," etc.), get the next one's y value so that the program knows where to stop copying and pasting assignmnets. next_section_y = sections[1][1] copy_and_paste_course_name() # The assignments are listed 66 units apart. Using this, go through all the upcoming assignments and run the copy_and_paste_assignment function. for i in range(367, next_section_y-60, 66): pyautogui.click(tab) copy_and_paste_assignment(i) def copy(): # Command + c to copy pyautogui.hotkey("command", "c") def paste(): # Command + shift + v to paste without formatting pyautogui.hotkey("command", "shift", "v") def open_chrome(): # Locate chrome logo on screen. Hold down to make options appear and click "new window." pyautogui.mouseDown(pyautogui.locateCenterOnScreen("chrome_button.png", confidence = 0.8)) pyautogui.moveRel(0, -174, duration = 0.5) pyautogui.click(button = "left") def google_docs(): # Go to google docs homepage time.sleep(2) type_and_enter("docs.google.com") def fullscreen(): # Enter fullscreen by using the keyboard shortcut command + control + f pyautogui.hotkey("command", "ctrl", "f") def create_and_rename_doc(): # Create a new doc and rename it with today's date and "To Do List" time.sleep(5) pyautogui.click(coordinates["new_doc"], button = "left") time.sleep(5) pyautogui.click(coordinates["rename_doc"], button = "left") time.sleep(1) type_and_enter(str(date) + " To Do List") def canvas(): # Open a new tab and go to Canvas pyautogui.hotkey("command", "t") time.sleep(1) type_and_enter("nuevaschool.instructure.com") def rearrange_tabs(): # Rearrange tabs so that Canvas homepage is on the far left and google doc is on the far right pyautogui.moveTo(coordinates["homepage_tab"]) pyautogui.dragRel(-188, 0, button = "left") def open_course_assignments_pages(): # Locate each of the assignments buttons for each course on the Canvas homepage assignments_buttons = list(pyautogui.locateAllOnScreen("assignments_button.png")) # Right click on each of the assignments buttons and open the assignments pages in new tabs for button_location in assignments_buttons: pyautogui.click(pyautogui.center(button_location), button = "right") pyautogui.moveRel(10, 5, duration = 0.3) pyautogui.click(button = "left") time.sleep(0.5) def close_canvas_homepage(): # Close the Canvas homepage tab pyautogui.hotkey("command", "w") def go_to_doc_tab(): # Click on the google doc tab pyautogui.click(doc_tab) def go_through_tabs(): # Locate all the Canvas assignments tabs tabs = list(pyautogui.locateAllOnScreen("course_tab.png", confidence = 0.9)) # For each Canvas assignments tab, click on the tab and run for_each_tab for i in range(0, len(tabs)): current_tab = pyautogui.center(tabs[i]) pyautogui.click(current_tab) time.sleep(0.5) for_each_tab(current_tab) def final_formatting(): # Go to the google doc, press backspace twice to get rid of the extra line since the program is done adding assignments, select everything, and turn it into a bulleted list. Press the down key to unhighlight. pyautogui.click(doc_tab, button = "left") time.sleep(0.5) pyautogui.press("backspace") pyautogui.press("backspace") time.sleep(0.1) pyautogui.hotkey("command", "a") time.sleep(0.5) pyautogui.click(coordinates["bulleted_list"], button = "left") time.sleep(0.1) pyautogui.press("down") open_chrome() google_docs() fullscreen() create_and_rename_doc() canvas() time.sleep(3) rearrange_tabs() open_course_assignments_pages() close_canvas_homepage() time.sleep(1) # Find the location of the google doc tab and store it in a variable so that it can be navigated to later doc_tab = pyautogui.locateCenterOnScreen("doc_tab.png") go_to_doc_tab() time.sleep(4) go_through_tabs() final_formatting()