From 2c42225f8bdfdaf196cacbb0e6633684a4d7d41f Mon Sep 17 00:00:00 2001 From: Peter Howell Date: Thu, 16 Jan 2025 11:20:03 -0800 Subject: [PATCH] updates sp25 --- courses.py | 6 +++--- curric2022.py | 18 +++++++++--------- flexday.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/courses.py b/courses.py index 195bb77..06a07fa 100644 --- a/courses.py +++ b/courses.py @@ -1031,7 +1031,7 @@ def enroll_id_list_to_shell(id_list, shell_id, v=0): # multiple semesters def enroll_stem_students_live(): - semesters = [184,] + semesters = [286,287] for S in semesters: enroll_stem_students_live_semester(S) @@ -1300,7 +1300,7 @@ def enroll_orientation_students(): DO_IT = 1 import localcache2 - ori_shell_id = "19094" # 2024 # "" # 2023 orientation shell 15924 # 2022: "9768" + ori_shell_id = "20862" # 2025 "19094" # 2024 # "" # 2023 orientation shell 15924 # 2022: "9768" print("Getting users in orientation shell") #users_in_ori_shell = set( \ @@ -1312,7 +1312,7 @@ def enroll_orientation_students(): # users_to_enroll = users_new_this_semester(the_semester) ### ##### USES LOCAL DB # double semester (SU + FA) - users_to_enroll = users_new_this_2x_semester("202450", "202470") ##### USES LOCAL DB + users_to_enroll = users_new_this_2x_semester("202510", "202530") ##### USES LOCAL DB #print("ALL ORIENTATION STUDENTS %s" % str(users_to_enroll)) #print("\n\nALREADY IN ORI SHELL %s" % str(users_in_ori_shell)) diff --git a/curric2022.py b/curric2022.py index 2973ca2..8d58aa6 100644 --- a/curric2022.py +++ b/curric2022.py @@ -181,11 +181,11 @@ def path_style_prog(): oo.flush() def term_txt_to_code(t): - term_codes = {'Spring':'30','Summer':'50','Fall':'70'} - parts = t.split(" ") - if len(parts)>1: - yr = parts[1] - sem = term_codes[parts[0]] + term_codes = {'Winter Intersession':'10','Spring':'30','Summer':'50','Fall':'70'} + m = re.search(r'(^.*)\s(\d\d\d+\d+)$', t) + if m: + yr = m.group(2) + sem = term_codes[m.group(1)] return yr+sem return '' @@ -333,10 +333,10 @@ def path_style_2_html(): v = verbose prog_title_subs = [] - with codecs.open('cache/program_published_names.csv', 'r','utf-8') as file: - reader = csv.reader(file) - for row in reader: - prog_title_subs.append(row) + #with codecs.open('cache/program_published_names.csv', 'r','utf-8') as file: + # reader = csv.reader(file) + # for row in reader: + # prog_title_subs.append(row) oo = codecs.open("cache/programs/allprogrampaths.txt","r","utf-8").readlines() diff --git a/flexday.py b/flexday.py index ad8a762..fb4b70c 100644 --- a/flexday.py +++ b/flexday.py @@ -260,12 +260,54 @@ def find_unnamed_people(): for Q in queries: print(Q) + + + + + +import pandas as pd + +# Function to generate SQL INSERT statements +def generate_insert_statements(table_name='conf_sessions'): + # Read the CSV into a pandas DataFrame + df = pd.read_csv('cache/flexsessions.csv') + + # Drop the columns 'date' and 'Start' (case-sensitive) + df = df.drop(columns=['date', 'Start'], errors='ignore') + + # Drop any columns that are unnamed (such as 'Unnamed: 8') + df = df.loc[:, ~df.columns.str.contains('^Unnamed')] + + insert_statements = [] + + # Iterate over each row in the DataFrame + for index, row in df.iterrows(): + columns = ", ".join(df.columns) # Get column names from the DataFrame + values = ", ".join(["'{0}'".format(str(value).replace("'", "''")) for value in row.values]) # Escape single quotes in values + + # Construct the SQL INSERT statement + #insert_statement = f"INSERT INTO {table_name} ({columns}) VALUES ({values});" + #insert_statements.append(insert_statement) + + set_clause = ", ".join(["`{}`='{}'".format(col, str(value).replace("'", "''")) for col, value in row.items()]) + + # Construct the SQL INSERT statement using SET + insert_statement = f"INSERT INTO {table_name} SET {set_clause};" + insert_statements.append(insert_statement) + + + for S in insert_statements: + print(S) + return insert_statements + + if __name__ == "__main__": print ("") options = { 1: ['(old) sync conf_user and iLearn employee tables', user_db_sync2] , 2: ['generate sql to fix conf_user dups', correct_dup_user_rows] , 3: ['add names to new accounts', find_unnamed_people], 4: ['search for user', search_user], + 5: ['generate insert statements', generate_insert_statements ] }