Skip to content

Commit

Permalink
Merge pull request #19 from guyhoffman/main
Browse files Browse the repository at this point in the history
Adding "Available from" and "until" to due dates from CSV
  • Loading branch information
dsavransky authored Mar 15, 2021
2 parents 47ed7c3 + 75fb8b6 commit 7b2b5ae
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions scripts/dueDatesFromCSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,45 @@ def getArgs():


def chooseCourse(c):
"""Interactively choose courses from Canvas
Args:
c (cornellGrading): The cornellGrading object initialized by the user
Returns:
int: Course ID
"""
strs, ids = c.listCourses()
cli = Bullet("Choose course", strs, margin=3, return_index=True)
_, idx = cli.launch()
return ids[idx]


def chooseAssignment(c):
"""Interactively choose assignment from course
Args:
c (cornellGrading): The cornellGrading object initialized after selecting a course
Returns:
int: Assignment ID
"""
strs, ids = c.listAssignments()
cli = Bullet("Choose assignment", strs, margin=3, return_index=True)
_, idx = cli.launch()
return ids[idx]


def getAssignment(c, args):
"""General assignment chooser, taking into account command line arguments and complementing with interactive menus
Args:
c (cornellGrading): The cornellGrading object initialized by the user
args (argparser args): Argument list parsed by argparse
Returns:
canvasapi.Assignment: The assignment object selected
"""

if args.courseNum:
coursenum = args.courseNum
Expand Down Expand Up @@ -85,27 +110,41 @@ def getAssignment(c, args):
secs = c.course.get_sections()

with open(args.csvFileName) as csvfile:
reader = csv.reader(csvfile)

# Skip first row
header = next(reader)
reader = csv.DictReader(csvfile)

# Scan CSV file
for row in reader:
print(f"Section {row[0]}: due at {row[1]} {row[2]}")
print(f"Section {row['section']}:")
print(f"| Due at {row['due_date']} {row['due_time']}")
if "from_date" in reader.fieldnames:
print(f"| Available from {row['from_date']} {row['from_time']}")
if "until_date" in reader.fieldnames:
print(f"| Available until {row['until_date']} {row['until_time']}")

sectionid = -1
for s in secs:
if s.name == row[0]:
if s.name == row['section']:
sectionid = s.id

assert sectionid > -1, f"Course doesn't have section {row[0]}"
assert sectionid > -1, f"Course doesn't have section {row['section']}"

# Set override for due dates
duedate = c.localizeTime(row[1], row[2])
due_date = c.localizeTime(row['due_date'], row['due_time'])
overridedef = {
"course_section_id": sectionid,
"due_at": duedate.strftime("%Y-%m-%dT%H:%M:%SZ"), # must be UTC
"due_at": due_date.strftime("%Y-%m-%dT%H:%M:%SZ"), # must be UTC
}

# Add optional override for "available from" dates
if "from_date" in reader.fieldnames:
from_date = c.localizeTime(row['from_date'], row['from_time'])
overridedef["unlock_at"] = from_date.strftime("%Y-%m-%dT%H:%M:%SZ") # UTC

# Add optional override for "available until" dates
if "until_date" in reader.fieldnames:
until_date = c.localizeTime(row['until_date'], row['until_time'])
overridedef["lock_at"] = until_date.strftime("%Y-%m-%dT%H:%M:%SZ") # UTC

try:
asgn.create_override(assignment_override=overridedef)
except:
Expand Down

0 comments on commit 7b2b5ae

Please sign in to comment.