From 021a8ea7e9bc69267ccf34b0201b6c6c805f76de Mon Sep 17 00:00:00 2001 From: Coding with Peter Date: Wed, 30 Aug 2023 10:22:50 -0700 Subject: [PATCH] aug 2023 updates --- courses.py | 96 ++++++++++++++++++++++++++++++++++++++++----------- localcache.py | 51 +++++++++++++++++++++++++++ pipelines.py | 14 +++++--- users.py | 21 +++++++++-- 4 files changed, 154 insertions(+), 28 deletions(-) diff --git a/courses.py b/courses.py index 0aa8d49..3c0fab5 100644 --- a/courses.py +++ b/courses.py @@ -352,10 +352,10 @@ def update_course_conclude(courseid="13590",enddate='2021-12-23T01:00Z'): print('****%s' % str(e)) # Relevant stuff trying to see if its even being used or not -def course_term_summary_local(term="176",term_label="FA22"): +def course_term_summary_local(term="180",term_label="FA23"): O = "\t
  • Course: %s
    Status: %s
    Teacher: %s
    Number students: %s
  • \n" courses = get_courses_in_term_local(term) - oo = codecs.open('cache/semester_summary.html','w','utf-8') + oo = codecs.open(f'cache/semester_summary_{term_label}.html','w','utf-8') oo.write('\n') # Relevant stuff trying to see if its even being used or not -def course_term_summary(term="176",term_label="FA22"): +def course_term_summary(term="180",term_label="FA23"): print("Summary of %s" % term_label) courses = getCoursesInTerm(term,0,0) @@ -850,8 +850,8 @@ def enroll_id_list_to_shell(id_list, shell_id, v=0): def enroll_stem_students_live(): - the_term = '179' # su23 fa23 = 180 - do_removes = 1 + the_term = '180' # su23 fa23 = 180 + do_removes = 0 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 @@ -1002,13 +1002,13 @@ def enroll_gott_workshops_su23(): #print(by_email.keys()) workshop_ids = { - 'GOTT 2: Intro to Async Online Teaching and Learning2023-07-09 17:00:00': 17992, - 'GOTT 4: Assessment in Digital Learning2023-07-09 17:00:00': 17995, - 'Restricted to STEM faculty. Humanizing (STEM) Online Learning 2023-06-18 17:00:00': 17996, - 'GOTT 6: Online Live Teaching and Learning2023-06-11 17:00:00': 17986, - 'GOTT 5: Essentials of Blended Learning2023-06-25 17:00:00': 17987, - 'GOTT 5: Essentials of Blended Learning (HyFlex)2023-06-25 17:00:00': 17987, - 'GOTT 1: Intro to Teaching Online with Canvas2023-05-29 17:00:00': 17985, + #'GOTT 2: Intro to Async Online Teaching and Learning2023-07-09 17:00:00': 17992, + #'GOTT 4: Assessment in Digital Learning2023-07-09 17:00:00': 17995, + #'Restricted to STEM faculty. Humanizing (STEM) Online Learning 2023-06-18 17:00:00': 17996, + #'GOTT 6: Online Live Teaching and Learning2023-06-11 17:00:00': 17986, + #'GOTT 5: Essentials of Blended Learning2023-06-25 17:00:00': 17987, + #'GOTT 5: Essentials of Blended Learning (HyFlex)2023-06-25 17:00:00': 17987, + #'GOTT 1: Intro to Teaching Online with Canvas2023-05-29 17:00:00': 17985, 'GOTT 1: Intro to Teaching Online with Canvas2023-08-20 17:00:00': 17994 } #print(json.dumps(signups,indent=4)) @@ -1016,6 +1016,8 @@ def enroll_gott_workshops_su23(): subs = {'csalvin@gavilan.edu':'christinasalvin@gmail.com', 'karenjeansutton@gmail.com': 'ksutton@gavilan.edu', + 'elisepeeren@gmail.com': 'epeeren@gavilan.edu', + 'kjoyenderle@gmail.com': 'kenderle@gavilan.edu', 'flozana@gmail.com': 'flozano@gavilan.edu', 'fyarahmadi2191@gmail.com': 'fyarahmadi@gavilan.edu', 'jacquelinejeancollins@yahoo.com': 'jcollins@gavilan.edu', @@ -1027,6 +1029,7 @@ def enroll_gott_workshops_su23(): for wkshp,su_list in signups.items(): if wkshp not in workshop_ids: + print(f"skipping {wkshp}") continue to_enroll = [] @@ -1323,7 +1326,22 @@ def modify_courses(): print('****%s' % str(e)) - +def teacher_to_many_shells(): + for id in range(18089,18110): + #print(id) + #continue + + # Add teacher + u3 = url + f"/api/v1/courses/{id}/enrollments" + #usrid = input("id of %s? " % N) + usrid = '78' + data2 = { "enrollment[type]":"TeacherEnrollment", "enrollment[user_id]":usrid, + "enrollment[enrollment_state]":"active" } + r4 = requests.post(u3, headers=header, params=data2) + print(f"enrolled user id: {usrid} as teacher in course {id}.") + + + def create_sandboxes(): # ('ED','82'), @@ -1337,11 +1355,16 @@ def create_sandboxes(): ('OF','41897'), ('SG','115'), ('JG','37654'), ('DG','133'), ('DK','168'), ('JM','204'), ('GM', '211'), ('RM','45341'), ('CR','5655'), ('CS','272'), ('BS','19231'), ('SS', '274') ] - + sandboxes = [ ('SM','191')] + + sandboxes = [ ('KD', '2509'), ('KE', '2904'), ('SH', '144'), ('SN','60996'), ('EP', '16726'), ('PS','60938'), ('JW', '43052') ] + + sandboxes = [('HA','61620'), ('AS','61451'), ('MP', '11565'), ('AA','51276') ] + sandboxes = [('JR','61062')] report = [] for (N,usrid) in sandboxes: - coursename = f"{N} Sandbox SU23 (GOTT4)" - coursecode = f"{N} SU23 Sandbox (GOTT4)" + coursename = f"{N} Sandbox SU23 (GOTT1)" + coursecode = f"{N} SU23 Sandbox (GOTT1)" print(f"Creating course: {coursename} for {N}, id: {usrid}") u2 = url + "/api/v1/accounts/1/courses" data = { @@ -1391,6 +1414,27 @@ def create_sandboxes(): def course_term_summary_2(): + lines = codecs.open('cache/term_summary.txt','r','utf-8').readlines() + output = codecs.open('cache/term_summary.html','w','utf-8') + for L in lines: + try: + L = L.strip() + print(L) + if re.search('unpublished',L): + m = re.search(r"'id': (\d+),",L) + m2 = re.search(r"'course_code': '(.+?)',",L) + if m: + ss = "
    Course: %s
    " % ("https://ilearn.gavilan.edu/courses/"+str(m.group(1)), m2.group(1)) + output.write( ss ) + print(ss+"\n") + except Exception as e: + print(e) + + + + +def course_term_summary_3(): + # doesn't work cause of single, not double quotes?!?! lines = codecs.open('cache/term_summary.txt','r','utf-8').readlines() output = codecs.open('cache/term_summary.html','w','utf-8') for L in lines: @@ -1417,12 +1461,13 @@ def course_term_summary_2(): ## ## def do_gav_connect(): - term = 178 - sem = "202330" - get_fresh = 0 + term = 180 + sem = "202370" + get_fresh = 1 crns = [sem + "-" + x.strip() for x in open('cache/starfish.txt','r').readlines()] target = len(crns) print(crns) + print("Press enter to begin.") a = input() c = getCoursesInTerm(term, get_fresh, 0) @@ -1432,9 +1477,13 @@ def do_gav_connect(): if course['sis_course_id'] in crns: print("Adding gav connect to", course['name']) print() - add_gav_connect(course['id']) - i += 1 + result = add_gav_connect(course['id']) + if result: + i += 1 + else: + print("Something went wrong with", course['name']) print(f"Added {i} redirects out of {target}.") + def add_gav_connect(course_id): params = { "name": "GavConnect", "privacy_level": "anonymous", @@ -1715,10 +1764,12 @@ if __name__ == "__main__": 8: ['Save enrollments in a course', course_enrollment], 9: ['Simple list of course data, search by sis_id', course_search_by_sis], 10: ['Overview of a term', course_term_summary], + 11: ['Enroll ORIENTATION and STEM student shells after catching up database.', enroll_o_s_students], 12: ['Enroll stem students', enroll_stem_students_live], 13: ['Enroll orientation students (refresh local db)', enroll_orientation_students], 14: ['Enroll ART students', enroll_art_students_live], + 15: ['List users who passed GOTT 1 / Bootcamp', get_gott1_passers], 16: ['List users who passed Plagiarism Module', get_plague_passers], 18: ['Create some sandbox courses', create_sandboxes], @@ -1726,12 +1777,14 @@ if __name__ == "__main__": 20: ['process the semester overview output (10)', course_term_summary_2], 22: ['Get a course info by id',getCourses], 23: ['Reset course conclude date',update_course_conclude], + 25: ['ext tools',get_ext_tools], 26: ['set ext tools',set_ext_tools], 32: ['Get course ext tools', get_course_ext_tools], 33: ['Add GavConnect to a course', do_gav_connect], 17: ['Remove "new analytics" from all courses navs in a semester', remove_n_analytics], 21: ['Add course evals', add_evals], + 27: ['Fine tune term dates and winter session', course_dates_terms], 3: ['Cross-list classes', xlist ], 6: ['Cross list helper', eslCrosslister], @@ -1743,6 +1796,7 @@ if __name__ == "__main__": 35: ['list all assignments', list_all_assignments], 40: ['Enroll GOTT Workshops', enroll_gott_workshops_su23], + 42: ['Add teacher to many shells', teacher_to_many_shells], # 24: ['Add course evals to whole semester',instructor_list_to_activate_evals], # 21: ['Add announcements to homepage', change_course_ann_homepage], # TODO wanted: group shell for each GP (guided pathway) as a basic student services gateway.... diff --git a/localcache.py b/localcache.py index a42f256..37c5b66 100644 --- a/localcache.py +++ b/localcache.py @@ -1852,6 +1852,56 @@ WHERE connection.close() + +def add_sessions(): + j_in = json.loads( codecs.open('cache/2023sessions.json','r','utf-8').read()) + + # Function to format the starttime + def format_starttime(day, time): + day_parts = day.split() + start_time = time.split('-')[0].strip() + return f"2023-08-{day_parts[1][:2]} {start_time}:00" + + def esc(input_string): + input_string = input_string.replace(' ', ' ') + return input_string.replace("'", "''") + + def ugh(s): + return f"`{s}`" + + # Sample values for track and location + track = 1 + id = 1341 + + f = "id, title, desc, type, length, starttime, track, location, location_irl, mode, gets_survey, is_flex_approved, parent" + fields = ",".join([ ugh(x) for x in f.split(', ') ]) + + for session_data in j_in: + #print(json.dumps(session_data,indent=2)) + + location = "" + link = "" + if "link" in session_data: link = session_data['link'] + + mode = "" + if "mode" in session_data: mode = session_data['mode'] + if mode == "Zoom": mode = "online" + if mode == "Hybrid": mode = "hybrid" + if mode == "Face-to-Face": mode = "inperson" + + # Generate INSERT statement + insert_statement = f"""INSERT INTO conf_sessions +({fields}) +VALUES +({id}, '{esc(session_data["title"])}', '{esc(session_data["description"])}', 101, 1, '{format_starttime(session_data["day"], session_data["time"])}', {track}, '{location}', '{link}', '{mode}', 1, 1, 1320); + """ + + print(insert_statement) + id += 1 + + + + def test_long_running(): from time import sleep print("Starting long process...") @@ -1888,6 +1938,7 @@ if __name__ == "__main__": 21: ['Encode data', do_encoding], 22: ['all students course history', all_students_history], 23: ['test long running', test_long_running], + 24: ['add conference sessions', add_sessions], #19: ['add evals for a whole semester', instructor_list_to_activate_evals], #16: ['Upload new employees to flex app', employees_refresh_flex], } diff --git a/pipelines.py b/pipelines.py index 2ddf2e1..e7dce93 100644 --- a/pipelines.py +++ b/pipelines.py @@ -2084,23 +2084,26 @@ def expand_old_semesters(): input('press return to continue.') # Input: xxxx_sched.json. Output: xxxx_latestarts.txt -def list_latestarts(term="su23"): +def list_latestarts(term="fa23"): show_summary = 1 the_year = '20' + term[2:4] print("year: ", the_year, " semester: ", term) - term_in = "cache/%s_sched.json" % term + #term_in = "cache/%s_sched.json" % term term_out = "cache/%s_latestarts.txt" % term expanded_out = "%s_sched_expanded.json" % term print("Writing output to " + term_out) - infile = codecs.open(term_in, "r", "utf-8") + #infile = codecs.open(term_in, "r", "utf-8") outfile = codecs.open(term_out, "w", "utf-8") exoutfile = codecs.open('cache/' + expanded_out, "w", "utf-8") expanded = [] - sched = json.loads(infile.read()) - #print sched + #sched = json.loads(infile.read()) + + + sched = requests.get(f"http://gavilan.cc/schedule/{term}_sched.json").json() + #print sched by_date = {} if show_summary: print("course \t loc \t type \t time") @@ -2178,6 +2181,7 @@ def list_latestarts(term="su23"): #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'] + "\t" + "\n") + outfile.close() put_file('/home/public/schedule/', 'cache/', "%s_latestarts.txt" % term, 0) return expanded if __name__ == "__main__": diff --git a/users.py b/users.py index 692d335..e03c31a 100644 --- a/users.py +++ b/users.py @@ -2035,9 +2035,26 @@ def find_new_teachers(): for J in jj: print( J['teacher']) - - def user_db_sync(): + # currently in db + conusr = fetch("http://192.168.1.6:8080/dir_api.php?users=1") + conusr_emails = set([x.lower() for x in funcy.pluck('email',conusr)]) + + #fetch all staff from ilearn ILRN unique emails + ilrn = json.loads(codecs.open("cache/ilearn_staff.json","r","utf-8").read()) + ilrn_emails = set([x.lower() for x in funcy.pluck('email',ilrn)]) + + for e in ilrn_emails: + + if not (e in conusr_emails) and e.endswith('@gavilan.edu'): + E = funcy.first(funcy.where(ilrn,email=e)) + goo = E['login_id'][3:] + #print("not in conf_user: %s \t %s \t %s" % (e,E['short_name'], E['login_id']) ) + print("INSERT INTO conf_users (goo,email,name) VALUES ('%s', '%s', '%s');" % (goo,e,E['short_name']) ) + + + +def user_db_sync2(): #fetch all personnel dir entries from dir_api.php. PERSL unique emails persl = fetch("http://hhh.gavilan.edu/phowell/map/dir_api.php?personnel=1") persl_emails = set([x.lower() for x in funcy.pluck('email',persl)])