From 762fbc800424015ceb62985398f76a3945bef58c Mon Sep 17 00:00:00 2001 From: Peter Howell Date: Fri, 29 Aug 2025 01:23:20 +0000 Subject: [PATCH] use safe folder patch in util --- courses.py | 8 ++++---- curric2022.py | 3 +-- curriculum.py | 7 +------ curriculum2020.py | 1 + degrees.py | 1 + flexday.py | 1 + gpt.py | 2 +- localcache.py | 5 +---- localcache2.py | 3 +-- outcomes.py | 6 +----- outcomes2022.py | 1 + pipelines.py | 10 ++++------ semesters.py | 3 +-- templates.py | 3 +-- util.py | 10 +++++----- 15 files changed, 25 insertions(+), 39 deletions(-) diff --git a/courses.py b/courses.py index 65906ad..e270f3d 100644 --- a/courses.py +++ b/courses.py @@ -1,21 +1,21 @@ -#from ast import Try, TryStar import json, re, requests, codecs, sys, time, funcy, os import pandas as pd from datetime import datetime import pytz -#from dateutil import parser from datetime import datetime -#from symbol import try_stmt from util import print_table, int_or_zero, float_or_zero, dept_from_name, num_from_name from pipelines import fetch, fetch_stream, fetch_collapse, header, url from schedules import get_semester_schedule -#from pipelines import sems from localcache import course_quick_stats, get_courses_in_term_local, course_student_stats, all_sem_courses_teachers, full_reload from localcache2 import db, users_new_this_semester, users_new_this_2x_semester, course_from_id, user_ids_in_shell from localcache2 import student_count, teacher_list, course_from_id, course_sched_entry_from_id from collections import defaultdict from semesters import find_term +#from dateutil import parser +#from ast import Try, TryStar +#from symbol import try_stmt +#from pipelines import sems stem_course_id = '11015' # TODO diff --git a/curric2022.py b/curric2022.py index 8de04a1..9de983e 100644 --- a/curric2022.py +++ b/curric2022.py @@ -1,11 +1,10 @@ +import util import requests,json,os,re, bisect, csv, codecs, funcy, sys, shutil, time from datetime import datetime import sortedcontainers as sc from collections import defaultdict from toolz.itertoolz import groupby,sliding_window from sortedcontainers import SortedList -#from durable.lang import * -#from durable.engine import * from pampy import match, _ from bs4 import BeautifulSoup as bs diff --git a/curriculum.py b/curriculum.py index 20342c5..c753bc2 100644 --- a/curriculum.py +++ b/curriculum.py @@ -1,10 +1,8 @@ +import util import requests,json,os,re, bisect, csv, codecs import sortedcontainers as sc from collections import defaultdict from toolz.itertoolz import groupby -#from docx.shared import Inches -#from docx import Document -#import docx from durable.lang import * from durable.engine import * from pampy import match, _ @@ -15,9 +13,6 @@ from schedules import get_semester_schedule from canvas_secrets import cq_url, cq_user, cq_pasw - -#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout) - TRACING = codecs.open('cache/progdebug.txt','w','utf-8') param = "?method=getCourses" diff --git a/curriculum2020.py b/curriculum2020.py index f47b222..3eb0781 100644 --- a/curriculum2020.py +++ b/curriculum2020.py @@ -1,3 +1,4 @@ +import util from pampy import match, _ import json, pypandoc, requests,json,os,re, bisect, csv, codecs import sortedcontainers as sc diff --git a/degrees.py b/degrees.py index b2f9954..266d5df 100644 --- a/degrees.py +++ b/degrees.py @@ -5,6 +5,7 @@ from minizinc import Instance, Model, Solver from datetime import datetime from collections import defaultdict import pandas as pd +import util debug_out = codecs.open("cache/degrees_debug.txt", "w", "utf-8") diff --git a/flexday.py b/flexday.py index b7a3c98..186765d 100644 --- a/flexday.py +++ b/flexday.py @@ -3,6 +3,7 @@ from localcache2 import user_from_goo from canvas_secrets import url from pipelines import fetch from users import getEmail +import util def user_db_sync(): diff --git a/gpt.py b/gpt.py index 177807a..0268a2b 100644 --- a/gpt.py +++ b/gpt.py @@ -1,6 +1,6 @@ import os, json, sys, codecs, re from datetime import datetime, timedelta - +import util from openai import OpenAI diff --git a/localcache.py b/localcache.py index a8f67e2..243b848 100644 --- a/localcache.py +++ b/localcache.py @@ -9,13 +9,10 @@ from datetime import timedelta from dateutil.parser import parse from os.path import exists, getmtime from pipelines import sync_non_interactive, url, header -#, gp, dean +import util from semesters import short_to_sis -#from courses import getCoursesInTerm -#from courses import user_in_depts_live - mycourses = {} local_data_folder = 'cache/canvas_data/' diff --git a/localcache2.py b/localcache2.py index 5034af4..1c520de 100644 --- a/localcache2.py +++ b/localcache2.py @@ -1,5 +1,5 @@ # Local data, saving and manipulating - +import util import os, re, gzip, codecs, funcy, pytz, json, random, functools, requests, sys, csv, time, psycopg2 import pandas as pd import numpy as np @@ -8,7 +8,6 @@ from datetime import datetime as dt from datetime import timedelta from dateutil.parser import parse from os.path import exists, getmtime -#from pipelines import sync_non_interactive, url, header, gp, dean from tabulate import tabulate from semesters import short_to_sis diff --git a/outcomes.py b/outcomes.py index a6e9e64..7ca51f0 100644 --- a/outcomes.py +++ b/outcomes.py @@ -1,18 +1,14 @@ - - +import util import requests, json, codecs, csv, re, sys, os, shutil, time from collections import defaultdict - from pipelines import fetch, url, header from courses import getCoursesInTerm, getTerms - from concurrent.futures import ThreadPoolExecutor f = codecs.open('cache/slo/log.txt','w','utf-8') VERBOSE = 1 - TERM = '180' SLO_CURRENT_SOURCE = 'cache/slo/2018_slo.csv' # term 21 diff --git a/outcomes2022.py b/outcomes2022.py index 2c642eb..1233ce1 100644 --- a/outcomes2022.py +++ b/outcomes2022.py @@ -19,6 +19,7 @@ # - Issue: # + Course naming / sections joined... +import util import concurrent.futures import pandas as pd from pipelines import fetch, url, header diff --git a/pipelines.py b/pipelines.py index a8e8b88..5033536 100644 --- a/pipelines.py +++ b/pipelines.py @@ -1,11 +1,7 @@ -#from sqlite3 import paramstyle -#from time import strptime -#from util import UnicodeDictReader -import codecs, json, requests, re, csv, datetime, pysftp, os, jsondiff, os.path +import util +import codecs, json, requests, re, csv, datetime, os, jsondiff, os.path import sys, shutil, hmac, hashlib, base64, schedule, time, pathlib -#import pdb from datetime import timedelta -#from collections import defaultdict from canvas_secrets import apiKey, apiSecret, FTP_SITE, FTP_USER, FTP_PW, url, domain, account_id, header, header_media, g_id, g_secret from canvas_secrets import instructure_url, instructure_username, instructure_private_key @@ -396,6 +392,7 @@ def file_doesnt_exist(name): # From instructure sftp site def fetch_current_rosters(): + import pysftp cnopts = pysftp.CnOpts() cnopts.hostkeys = None with pysftp.Connection(instructure_url,username=instructure_username, private_key=instructure_private_key,cnopts=cnopts) as sftp: @@ -578,6 +575,7 @@ def do_request(path): # Upload a json file to www def put_file(remotepath,localpath, localfile,prompt=1): + import pysftp show_all = 0 folder = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') cnopts = pysftp.CnOpts() diff --git a/semesters.py b/semesters.py index eac5bc5..21e13d6 100644 --- a/semesters.py +++ b/semesters.py @@ -1,8 +1,7 @@ # Try to gather all the different formats and ways of labeling a semester, along with their associated dates. import json, funcy, re, sys - -# sem_to_short = { 'Summer 2021': 'su21', 'Fall 2021':'fa21', 'Winter 2022':'wi22', 'Spring 2022':'sp22', 'Summer 2022':'su22', 'Fall 2022':'fa22' } +import util season_to_number = { 'Fall': '70', 'Summer': '50', 'Spring': '30', 'Winter': '10'} diff --git a/templates.py b/templates.py index 2413563..ab6eb7e 100644 --- a/templates.py +++ b/templates.py @@ -1,6 +1,5 @@ - import os, re, codecs - +import util from pipelines import get_doc, get_doc_generic, put_file # build web pages from fragments diff --git a/util.py b/util.py index 2e1fbf0..a0e2b3d 100755 --- a/util.py +++ b/util.py @@ -58,7 +58,7 @@ from functools import reduce # Teacher name format changed. Remove commas and switch first to last def fix_t_name(str): str = str.strip() - str = re.sub('\s+',' ',str) + str = re.sub(r'\s+',' ',str) parts = str.split(', ') if len(parts)>1: return parts[1].strip() + " " + parts[0].strip() @@ -69,7 +69,7 @@ def split_class_dept(c): return c.split(' ')[0] def split_class_code(c): num = c.split(' ')[1] - parts = re.match('(\d+)([a-zA-Z]+)',num) + parts = re.match(r'(\d+)([a-zA-Z]+)',num) #ret = "Got %s, " % c if parts: r = int(parts.group(1)) @@ -79,7 +79,7 @@ def split_class_code(c): return int(num) def split_class_code_letter(c): num = c.split(' ')[1] - parts = re.match('(\d+)([A-Za-z]+)',num) + parts = re.match(r'(\d+)([A-Za-z]+)',num) if parts: return parts.group(2) return '' @@ -215,14 +215,14 @@ def unix_time_millis(dt): # ENGL250 returns ENGL def dept_from_name(n): - m = re.search('^([a-zA-Z]+)\s?[\d\/]+',n) + m = re.search(r'^([a-zA-Z]+)\s?[\d\/]+',n) if m: return m.group(1) print(("Couldn't find dept from: " + n)) return '' # ENGL250 returns 250 def num_from_name(n): - m = re.search('^([a-zA-Z]+)\s?([\d\/]+[A-Z]?)',n) + m = re.search(r'^([a-zA-Z]+)\s?([\d\/]+[A-Z]?)',n) if m: return m.group(2) print(("Couldn't find num from: " + n)) return ''