courses, first commit on delltop

This commit is contained in:
Peter Howell 2024-09-09 11:41:25 -07:00
parent cb6d9b1d5d
commit 58fb71ff4c
1 changed files with 52 additions and 6 deletions

View File

@ -230,7 +230,7 @@ def users_in_semester():
# #
# All students in STEM (or any list of depts.. match the course_code). Return SET of canvas ids. # All students (and faculty) in STEM (or any list of depts.. match the course_code). Return SET of canvas ids.
def users_in_by_depts_live(depts=[], termid='181'): def users_in_by_depts_live(depts=[], termid='181'):
courses_by_by_dept = {} courses_by_by_dept = {}
students_by_by_dept = {} students_by_by_dept = {}
@ -246,8 +246,8 @@ def users_in_by_depts_live(depts=[], termid='181'):
print("Getting enrollments for %s" % c['course_code']) print("Getting enrollments for %s" % c['course_code'])
if d in courses_by_by_dept: courses_by_by_dept[d].append(c) if d in courses_by_by_dept: courses_by_by_dept[d].append(c)
else: courses_by_by_dept[d] = [ c, ] else: courses_by_by_dept[d] = [ c, ]
for u in course_enrollment(c['id']).values(): for u in course_enrollment_with_faculty(c['id']).values():
if u['type'] != "StudentEnrollment": continue #if u['type'] != "StudentEnrollment": continue
if not (d in students_by_by_dept): if not (d in students_by_by_dept):
students_by_by_dept[d] = set() students_by_by_dept[d] = set()
students_by_by_dept[d].add(u['user_id']) students_by_by_dept[d].add(u['user_id'])
@ -259,8 +259,29 @@ def users_in_by_depts_live(depts=[], termid='181'):
codecs.open('cache/all_students_in_by_depts_in_term_%s.json' % termid,'w','utf-8').write( str(all_students) ) codecs.open('cache/all_students_in_by_depts_in_term_%s.json' % termid,'w','utf-8').write( str(all_students) )
return all_students return all_students
# Course enrollment, including teachers
def course_enrollment_with_faculty(id='', verbose=0):
if verbose: print("Getting enrollments for course id %s" % str(id))
if not id:
id = input('Course id? ')
t = url + '/api/v1/courses/%s/enrollments' % str(id)
if verbose: print(t)
emts = fetch(t,verbose)
if verbose: print(emts)
emt_by_id = {}
for E in emts:
if verbose: print(E)
try:
emt_by_id[E['user_id']] = E
except Exception as exp:
print("Skipped [%s] with this exception: %s" % (str(E), str(exp)))
ff = codecs.open('cache/courses/%s.json' % str(id), 'w', 'utf-8')
ff.write(json.dumps(emt_by_id, indent=2))
if verbose: print( " %i results" % len(emts) )
return emt_by_id
# Course enrollment list, students only
def course_enrollment(id='', verbose=0): def course_enrollment(id='', verbose=0):
if verbose: print("Getting enrollments for course id %s" % str(id)) if verbose: print("Getting enrollments for course id %s" % str(id))
if not id: if not id:
@ -1021,7 +1042,7 @@ def enroll_stem_students_live_semester(the_term, do_removes=0):
depts = "MATH BIO CHEM CSIS PHYS PSCI GEOG ASTR ECOL ENVS ENGR".split(" ") depts = "MATH BIO CHEM CSIS PHYS PSCI GEOG ASTR ECOL ENVS ENGR".split(" ")
users_to_enroll = users_in_by_depts_live(depts, the_term) # term id users_to_enroll = users_in_by_depts_live(depts, the_term) # term id
stem_enrollments = course_enrollment(stem_course_id) # by user_id stem_enrollments = course_enrollment_with_faculty(stem_course_id) # by user_id
users_in_stem_shell = set( [ x['user_id'] for x in stem_enrollments.values() ]) users_in_stem_shell = set( [ x['user_id'] for x in stem_enrollments.values() ])
@ -1233,7 +1254,31 @@ def enroll_gott_workshops():
this_id =workshop_ids[wkshp] this_id =workshop_ids[wkshp]
enroll_id_list_to_shell(to_enroll, this_id) enroll_id_list_to_shell(to_enroll, this_id)
def enroll_gnumber_list_to_courseid():
infile = codecs.open('cache/gottenrollments.txt','r','utf-8').readlines()
courseid = infile[0].strip()
glist = [ x.strip().split(',')[0] for x in infile[1:] ]
from localcache2 import user_from_goo
idlist = [user_from_goo(x)['id'] for x in glist ]
namelist = [user_from_goo(x)['name'] for x in glist ]
print(courseid)
print(glist)
print(idlist)
for i,id in enumerate(idlist):
try:
print(f"Enrolling: {id}, {namelist[i]}")
t = f"{url}/api/v1/courses/{courseid}/enrollments"
data = { 'enrollment[user_id]': id, 'enrollment[type]':'StudentEnrollment',
'enrollment[enrollment_state]': 'active' }
r3 = requests.post(t, headers=header, params=data)
print(r3.text)
time.sleep(0.600)
except Exception as e:
print(f"Something went wrong with id {id}, course {courseid}, user {namelist[i]}")
def enroll_art_students_live(): def enroll_art_students_live():
depts = "THEA ART DM MUS MCTV".split(" ") depts = "THEA ART DM MUS MCTV".split(" ")
@ -1580,7 +1625,7 @@ def create_sandboxes():
#(20600, ' Sandbox GOTT4 SU24'), #(20600, ' Sandbox GOTT4 SU24'),
#(19223, ' Sandbox GOTT5 WI24'), #(19223, ' Sandbox GOTT5 WI24'),
#(19224, ' Sandbox GOTT6 WI24') #(19224, ' Sandbox GOTT6 WI24')
(20603, ' Sandbox GOTT1 AUG SU24') (20761, ' Sandbox GOTT1 FA24')
] ]
filepath = 'cache/sandbox_courses.pkl' filepath = 'cache/sandbox_courses.pkl'
@ -2333,6 +2378,7 @@ if __name__ == "__main__":
45: ['List users who passed Plagiarism Module', get_plague_passers], 45: ['List users who passed Plagiarism Module', get_plague_passers],
46: ['make courses visible to auth users', modify_courses], 46: ['make courses visible to auth users', modify_courses],
47: ['enrollment helper', enrollment_helper], 47: ['enrollment helper', enrollment_helper],
48: ['g number list enroll to shell id', enroll_gnumber_list_to_courseid],
# 24: ['Add course evals to whole semester',instructor_list_to_activate_evals], # 24: ['Add course evals to whole semester',instructor_list_to_activate_evals],
# 21: ['Add announcements to homepage', change_course_ann_homepage], # 21: ['Add announcements to homepage', change_course_ann_homepage],
# TODO wanted: group shell for each GP (guided pathway) as a basic student services gateway.... # TODO wanted: group shell for each GP (guided pathway) as a basic student services gateway....