Last active
October 22, 2019 18:17
-
-
Save sunoru/0e94842c89ac79e8d6643f2a204aefd7 to your computer and use it in GitHub Desktop.
Automatically input grading on canvas..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
# Data file format (CSV): | |
# Name,Score | |
# Name should be first name first. | |
import csv | |
import sys | |
import time | |
import pyautogui as ag | |
def main(): | |
if len(sys.argv) < 2: | |
print("Usage: ./auto_canvas_grade.py scores.csv", file=sys.stderr) | |
exit(1) | |
print("Press enter for input box position... ", end="") | |
input() | |
input_box = ag.position() | |
print(input_box) | |
print("Press enter for score box position... ", end="") | |
input() | |
score_box = ag.position() | |
print(score_box) | |
print("Loading data...") | |
with open(sys.argv[1], newline="", encoding="utf-8") as fi: | |
reader = csv.reader(fi) | |
data = list(reader) | |
for line in data: | |
name, score = line | |
print("%s: %s" % (name, score)) | |
ag.click(input_box) | |
time.sleep(0.4) | |
ag.hotkey("ctrl", "a") | |
ag.typewrite(name) | |
time.sleep(0.5) | |
ag.doubleClick(score_box) | |
time.sleep(0.4) | |
ag.typewrite(score) | |
ag.press("enter") | |
time.sleep(0.5) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import sys | |
import time | |
import openpyxl | |
import pyautogui as ag | |
def main(): | |
if len(sys.argv) < 2: | |
print("Usage: ./auto_canvas_grade.py scores.xlsx", file=sys.stderr) | |
exit(1) | |
workbook = openpyxl.load_workbook(sys.argv[1]) | |
for i, name in enumerate(workbook.sheetnames): | |
print("%-3d: %s" % (i, name)) | |
sheet_index = len(workbook.sheetnames) - 1 | |
input_index = input("Select a worksheet (%d): " % sheet_index) | |
if input_index != "": | |
sheet_index = int(input_index) | |
worksheet = workbook.worksheets[sheet_index] | |
print("Selected: ", worksheet) | |
print("Press enter for input box position... ", end="") | |
input() | |
input_box = ag.position() | |
print(input_box) | |
print("Press enter for score box position... ", end="") | |
input() | |
score_box = ag.position() | |
print(score_box) | |
print("Loading data...") | |
for row in worksheet.values: | |
name, score = map(str, row) | |
print("%s: %s" % (name, score)) | |
ag.click(input_box) | |
time.sleep(0.4) | |
ag.hotkey("ctrl", "a") | |
ag.typewrite(name) | |
time.sleep(0.5) | |
ag.doubleClick(score_box) | |
time.sleep(0.4) | |
ag.typewrite(score) | |
ag.press("enter") | |
time.sleep(0.5) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated a version for xlsx.