Revert "Merge branch 'surface' into 'master'"
This reverts merge request !1
This commit is contained in:
parent
ba0839c484
commit
a919e4d2ea
111
courses.py
111
courses.py
|
|
@ -1,7 +1,7 @@
|
||||||
# test
|
|
||||||
import json, re, requests, codecs, sys, time, funcy
|
import json, re, requests, codecs, sys, time, funcy, os
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from tabulate import tabulate
|
#from tabulate import tabulate
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from util import print_table
|
from util import print_table
|
||||||
|
|
@ -249,9 +249,7 @@ def scrape_bookstore():
|
||||||
# Input: xxxx_sched.json. Output: xxxx_latestarts.txt
|
# Input: xxxx_sched.json. Output: xxxx_latestarts.txt
|
||||||
def list_latestarts():
|
def list_latestarts():
|
||||||
#term = input("Name of current semester file? (ex: sp18) ")
|
#term = input("Name of current semester file? (ex: sp18) ")
|
||||||
term = "sp23" # sems[0]
|
term = "sp23" # sems[0]
|
||||||
|
|
||||||
dept_ignore = "JFT JLE CWE".split(" ")
|
|
||||||
|
|
||||||
term_in = "cache/" + term + "_sched.json"
|
term_in = "cache/" + term + "_sched.json"
|
||||||
term_out = "cache/" + term + "_latestarts.txt"
|
term_out = "cache/" + term + "_latestarts.txt"
|
||||||
|
|
@ -262,13 +260,12 @@ def list_latestarts():
|
||||||
#print sched
|
#print sched
|
||||||
by_date = {}
|
by_date = {}
|
||||||
for C in sched:
|
for C in sched:
|
||||||
dept = C['code'].split(" ")
|
|
||||||
dept = dept[0]
|
|
||||||
if dept in dept_ignore:
|
|
||||||
continue
|
|
||||||
print(dept)
|
|
||||||
parts = C['date'].split("-")
|
parts = C['date'].split("-")
|
||||||
start = parts[0]
|
start = parts[0]
|
||||||
|
codes = C['code'].split(' ')
|
||||||
|
dept = codes[0]
|
||||||
|
if dept in ['JLE','JFT','CWE']:
|
||||||
|
continue
|
||||||
if re.search('TBA',start): continue
|
if re.search('TBA',start): continue
|
||||||
try:
|
try:
|
||||||
startd = parser.parse(start)
|
startd = parser.parse(start)
|
||||||
|
|
@ -282,11 +279,11 @@ def list_latestarts():
|
||||||
#print "Start: " + str(X)
|
#print "Start: " + str(X)
|
||||||
if len(by_date[X]) < 200:
|
if len(by_date[X]) < 200:
|
||||||
prettydate = X.strftime("%A, %B %d")
|
prettydate = X.strftime("%A, %B %d")
|
||||||
#print(prettydate + ": " + str(len(by_date[X])) + " courses")
|
print(prettydate + ": " + str(len(by_date[X])) + " courses")
|
||||||
outfile.write(prettydate + ": " + str(len(by_date[X])) + " courses" + "\n")
|
outfile.write(prettydate + ": " + str(len(by_date[X])) + " courses" + "\n")
|
||||||
for Y in by_date[X]:
|
for Y in by_date[X]:
|
||||||
#print "\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher']
|
#print "\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher']
|
||||||
#print(Y)
|
print(Y)
|
||||||
#outfile.write("\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher'] + "\t" + Y['type'] +"\n")
|
#outfile.write("\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher'] + "\t" + Y['type'] +"\n")
|
||||||
outfile.write("\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher'] + "\t" + Y['type'] + "\t" + "\n")
|
outfile.write("\t" + Y['code'] + " " + Y['crn'] + "\t" + Y['teacher'] + "\t" + Y['type'] + "\t" + "\n")
|
||||||
|
|
||||||
|
|
@ -335,14 +332,20 @@ def users_in_depts_live(depts=[], termid='171'):
|
||||||
|
|
||||||
|
|
||||||
def course_enrollment(id=''):
|
def course_enrollment(id=''):
|
||||||
|
print("Getting enrollments for course id %s" % str(id))
|
||||||
if not id:
|
if not id:
|
||||||
id = input('Course id? ')
|
id = input('Course id? ')
|
||||||
t = url + '/api/v1/courses/%s/enrollments?role[]=StudentEnrollment' % str(id)
|
t = url + '/api/v1/courses/%s/enrollments?role[]=StudentEnrollment' % str(id)
|
||||||
|
print(t)
|
||||||
emts = fetch(t,0)
|
emts = fetch(t,0)
|
||||||
#print(emts)
|
print(emts)
|
||||||
emt_by_id = {}
|
emt_by_id = {}
|
||||||
for E in emts:
|
for E in emts:
|
||||||
emt_by_id[E['user_id']] = E
|
print(E)
|
||||||
|
try:
|
||||||
|
emt_by_id[E['user_id']] = E
|
||||||
|
except Exception as exp:
|
||||||
|
print("Skipped that class with this exception: %s" % str(exp))
|
||||||
ff = codecs.open('cache/courses/%s.json' % str(id), 'w', 'utf-8')
|
ff = codecs.open('cache/courses/%s.json' % str(id), 'w', 'utf-8')
|
||||||
ff.write(json.dumps(emt_by_id, indent=2))
|
ff.write(json.dumps(emt_by_id, indent=2))
|
||||||
print( " %i results" % len(emts) )
|
print( " %i results" % len(emts) )
|
||||||
|
|
@ -507,11 +510,18 @@ GROUP BY c.code ORDER BY c.state, c.code""" % (S['id'],S['id'])
|
||||||
outp2.write("\n\n---------\nNOT PUBLISHED\n\n" + json.dumps(notpub, indent=2))
|
outp2.write("\n\n---------\nNOT PUBLISHED\n\n" + json.dumps(notpub, indent=2))
|
||||||
|
|
||||||
# Fetch all courses in a given term
|
# Fetch all courses in a given term
|
||||||
def getCoursesInTerm(term=0,show=1,active=0): # a list
|
def getCoursesInTerm(term=0,get_fresh=1,show=0,active=0): # a list
|
||||||
# https://gavilan.instructure.com:443/api/v1/accounts/1/courses?published=true&enrollment_term_id=11
|
|
||||||
names = []
|
|
||||||
if not term:
|
if not term:
|
||||||
term = getTerms(1,1)
|
term = getTerms(1,1)
|
||||||
|
ff = 'cache/courses_in_term_%s.json' % str(term)
|
||||||
|
if not get_fresh:
|
||||||
|
if os.path.isfile(ff):
|
||||||
|
return json.loads( codecs.open(ff,'r','utf-8').read() )
|
||||||
|
else:
|
||||||
|
print(" -> couldn't find cached classes at: %s" % ff)
|
||||||
|
|
||||||
|
# https://gavilan.instructure.com:443/api/v1/accounts/1/courses?published=true&enrollment_term_id=11
|
||||||
|
names = []
|
||||||
if active:
|
if active:
|
||||||
active = "published=true&"
|
active = "published=true&"
|
||||||
else:
|
else:
|
||||||
|
|
@ -531,6 +541,7 @@ def getCoursesInTerm(term=0,show=1,active=0): # a list
|
||||||
names.append(a['name'])
|
names.append(a['name'])
|
||||||
info.append( [a['id'], a['name'], a['workflow_state'] ] )
|
info.append( [a['id'], a['name'], a['workflow_state'] ] )
|
||||||
if show: print_table(info)
|
if show: print_table(info)
|
||||||
|
codecs.open(ff, 'w', 'utf-8').write(json.dumps(results,indent=2))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -702,18 +713,32 @@ def all_semester_course_sanity_check():
|
||||||
codecs.open('cache/courses_in_term_178.json','w','utf-8').write(json.dumps(c,indent=2))
|
codecs.open('cache/courses_in_term_178.json','w','utf-8').write(json.dumps(c,indent=2))
|
||||||
output = codecs.open('cache/courses_w_sections.csv','w','utf-8')
|
output = codecs.open('cache/courses_w_sections.csv','w','utf-8')
|
||||||
output.write( ",".join(['what','id','parent_course_id','sis_course_id','name']) + "\n" )
|
output.write( ",".join(['what','id','parent_course_id','sis_course_id','name']) + "\n" )
|
||||||
|
output2 = codecs.open('cache/courses_checker.csv','w','utf-8')
|
||||||
|
output2.write( ",".join(['id','sis_course_id','name','state','students']) + "\n" )
|
||||||
i = 0
|
i = 0
|
||||||
for course in c:
|
for course in c:
|
||||||
info = [ 'course', course['id'], '', course['sis_course_id'], course['name'], ]
|
u2 = url + '/api/v1/courses/%s?include[]=total_students' % str(course['id'])
|
||||||
|
course['info'] = fetch(u2)
|
||||||
|
#print(json.dumps(course['info'],indent=2))
|
||||||
|
ts = '?'
|
||||||
|
try:
|
||||||
|
ts = course['info']['total_students']
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
info = [ 'course', course['id'], '', course['sis_course_id'], course['name'], course['workflow_state'], ts ]
|
||||||
info = list(map(str,info))
|
info = list(map(str,info))
|
||||||
print(info)
|
info2 = [ course['id'], course['sis_course_id'], course['name'], course['workflow_state'], ts ]
|
||||||
|
info2 = list(map(str,info2))
|
||||||
|
output2.write( ",".join(info2) + "\n" )
|
||||||
|
output2.flush()
|
||||||
|
print(info2)
|
||||||
output.write( ",".join(info) + "\n" )
|
output.write( ",".join(info) + "\n" )
|
||||||
uu = url + '/api/v1/courses/%s/sections' % str(course['id'])
|
#uu = url + '/api/v1/courses/%s/sections' % str(course['id'])
|
||||||
course['sections'] = fetch(uu)
|
#course['sections'] = fetch(uu)
|
||||||
s_info = [ [ 'section', y['id'], y['course_id'], y['sis_course_id'], y['name']] for y in course['sections'] ]
|
#s_info = [ [ 'section', y['id'], y['course_id'], y['sis_course_id'], y['name'], y['total_students'] ] for y in course['sections'] ]
|
||||||
for row in s_info:
|
#for row in s_info:
|
||||||
print(row)
|
# print(row)
|
||||||
output.write( ",".join( map(str,row) ) + "\n" )
|
# output.write( ",".join( map(str,row) ) + "\n" )
|
||||||
output.flush()
|
output.flush()
|
||||||
i += 1
|
i += 1
|
||||||
if i % 5 == 0:
|
if i % 5 == 0:
|
||||||
|
|
@ -839,9 +864,9 @@ def unenroll_student(courseid,enrolid):
|
||||||
|
|
||||||
|
|
||||||
def enroll_stem_students_live():
|
def enroll_stem_students_live():
|
||||||
the_term = '176'
|
the_term = '178'
|
||||||
do_removes = 0
|
do_removes = 0
|
||||||
depts = "MATH BIO CHEM CSIS PHYS GEOG ASTR ECOL ENVS ENGR".split(" ")
|
depts = "MATH BIO CHEM CSIS PHYS PSCI GEOG ASTR ECOL ENVS ENGR".split(" ")
|
||||||
users_to_enroll = users_in_depts_live(depts, the_term) # term id
|
users_to_enroll = users_in_depts_live(depts, the_term) # term id
|
||||||
|
|
||||||
stem_enrollments = course_enrollment(stem_course_id) # by user_id
|
stem_enrollments = course_enrollment(stem_course_id) # by user_id
|
||||||
|
|
@ -1018,21 +1043,21 @@ def enroll_orientation_students():
|
||||||
s = cursor.fetchall()
|
s = cursor.fetchall()
|
||||||
if s:
|
if s:
|
||||||
s = s[0]
|
s = s[0]
|
||||||
print("Enrolling: %s" % s[0])
|
print(" + Enrolling: %s" % s[0])
|
||||||
t = url + '/api/v1/courses/%s/enrollments' % ori_shell_id
|
t = url + '/api/v1/courses/%s/enrollments' % ori_shell_id
|
||||||
data = { 'enrollment[user_id]': j, 'enrollment[type]':'StudentEnrollment',
|
data = { 'enrollment[user_id]': j, 'enrollment[type]':'StudentEnrollment',
|
||||||
'enrollment[enrollment_state]': 'active' }
|
'enrollment[enrollment_state]': 'active' }
|
||||||
print(data)
|
#print(data)
|
||||||
r3 = requests.post(t, headers=header, params=data)
|
r3 = requests.post(t, headers=header, params=data)
|
||||||
eee += 1
|
eee += 1
|
||||||
print(r3.text)
|
#print(r3.text)
|
||||||
time.sleep(0.200)
|
time.sleep(0.600)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Something went wrong with id %s, %s, %s" % (j, str(s), str(e)))
|
print(" - Something went wrong with id %s, %s, %s" % (j, str(s), str(e)))
|
||||||
return (eee,uuu)
|
return (eee,uuu)
|
||||||
|
|
||||||
def enroll_o_s_students():
|
def enroll_o_s_students():
|
||||||
full_reload()
|
#full_reload()
|
||||||
|
|
||||||
(es,us) = enroll_stem_students_live()
|
(es,us) = enroll_stem_students_live()
|
||||||
(eo, uo) = enroll_orientation_students()
|
(eo, uo) = enroll_orientation_students()
|
||||||
|
|
@ -1125,20 +1150,18 @@ def instructor_list_to_activate_evals():
|
||||||
|
|
||||||
def add_evals(section=0):
|
def add_evals(section=0):
|
||||||
# show or hide?
|
# show or hide?
|
||||||
hidden = False
|
hidden = True
|
||||||
#s = [ x.strip() for x in codecs.open('cache/sp21_eval_sections.txt','r').readlines()]
|
#s = [ x.strip() for x in codecs.open('cache/sp21_eval_sections.txt','r').readlines()]
|
||||||
#s = [ x.split(',')[4].split('::') for x in codecs.open('cache/fa22_eval_sections.csv','r').readlines()]
|
#s = [ x.split(',')[4].split('::') for x in codecs.open('cache/fa22_eval_sections.csv','r').readlines()]
|
||||||
#s = [ x.strip() for x in codecs.open('cache/fa22_eval_sections.csv','r').readlines()]
|
s = [ x.strip() for x in codecs.open('cache/fa22_eval_sections.csv','r').readlines()]
|
||||||
s = [ x.strip() for x in codecs.open('cache/sp23_eval_sections.csv','r').readlines()]
|
print(s)
|
||||||
s = list(funcy.flatten(s))
|
s = list(funcy.flatten(s))
|
||||||
s.sort()
|
s.sort()
|
||||||
print(s)
|
|
||||||
xyz = input('hit return to continue')
|
xyz = input('hit return to continue')
|
||||||
|
|
||||||
#c = getCoursesInTerm(168,0,1)
|
#c = getCoursesInTerm(168,0,1)
|
||||||
#c = getCoursesInTerm(174,0,1) # sp22
|
#c = getCoursesInTerm(174,0,1) # sp22
|
||||||
#c = getCoursesInTerm(176,0,1) # fa22
|
c = getCoursesInTerm(176,0,1) # fa22
|
||||||
c = getCoursesInTerm(178,0,1) # sp23
|
|
||||||
print(c)
|
print(c)
|
||||||
ids = []
|
ids = []
|
||||||
courses = {}
|
courses = {}
|
||||||
|
|
@ -1150,7 +1173,7 @@ def add_evals(section=0):
|
||||||
courses[str(C['id'])] = C
|
courses[str(C['id'])] = C
|
||||||
ids.append(str(C['id']))
|
ids.append(str(C['id']))
|
||||||
|
|
||||||
ask = 1
|
ask = 0
|
||||||
data = {'position':2, 'hidden':hidden}
|
data = {'position':2, 'hidden':hidden}
|
||||||
|
|
||||||
for i in ids:
|
for i in ids:
|
||||||
|
|
@ -1160,7 +1183,7 @@ def add_evals(section=0):
|
||||||
if a == 'q': return
|
if a == 'q': return
|
||||||
u2 = "https://gavilan.instructure.com:443/api/v1/courses/%s/tabs/context_external_tool_1953" % i
|
u2 = "https://gavilan.instructure.com:443/api/v1/courses/%s/tabs/context_external_tool_1953" % i
|
||||||
r3 = requests.put(u2, headers=header, params=data)
|
r3 = requests.put(u2, headers=header, params=data)
|
||||||
print(r3.text)
|
print(r3)
|
||||||
time.sleep(0.600)
|
time.sleep(0.600)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1353,6 +1376,7 @@ def set_ext_tools():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
options = { 1: ['Cross check schedule with ztc responses',make_ztc_list] ,
|
options = { 1: ['Cross check schedule with ztc responses',make_ztc_list] ,
|
||||||
|
30: ['List latestart classes', list_latestarts ],
|
||||||
2: ['Add announcements to homepage', change_course_ann_homepage],
|
2: ['Add announcements to homepage', change_course_ann_homepage],
|
||||||
3: ['Cross-list classes', xlist ],
|
3: ['Cross-list classes', xlist ],
|
||||||
4: ['List students who passed quiz X', get_quiz_passers],
|
4: ['List students who passed quiz X', get_quiz_passers],
|
||||||
|
|
@ -1375,13 +1399,12 @@ if __name__ == "__main__":
|
||||||
21: ['Add announcements to homepage', change_course_ann_homepage],
|
21: ['Add announcements to homepage', change_course_ann_homepage],
|
||||||
22: ['Get a course info by id',getCourses],
|
22: ['Get a course info by id',getCourses],
|
||||||
23: ['Reset course conclude date',update_course_conclude],
|
23: ['Reset course conclude date',update_course_conclude],
|
||||||
#24: ['Add course evalse to whole semester',instructor_list_to_activate_evals],
|
#24: ['Add course evals to whole semester',instructor_list_to_activate_evals],
|
||||||
25: ['ext tools',get_ext_tools],
|
25: ['ext tools',get_ext_tools],
|
||||||
26: ['set ext tools',set_ext_tools],
|
26: ['set ext tools',set_ext_tools],
|
||||||
27: ['Fine tune term dates and winter session', course_dates_terms],
|
27: ['Fine tune term dates and winter session', course_dates_terms],
|
||||||
28: ['Cross list a semester from file', semester_cross_lister],
|
28: ['Cross list a semester from file', semester_cross_lister],
|
||||||
29: ['Check all courses & their sections in semester', all_semester_course_sanity_check],
|
29: ['Check all courses & their sections in semester', all_semester_course_sanity_check],
|
||||||
30: ['List latestart classes', list_latestarts ],
|
|
||||||
# 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....
|
||||||
#
|
#
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue