Skip to content

Commit ce2dd09

Browse files
committed
added ruff
1 parent bb5a091 commit ce2dd09

File tree

6 files changed

+62
-65
lines changed

6 files changed

+62
-65
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"vscode": {
1313
"extensions": [
1414
"ms-python.python",
15-
"ms-python.black-formatter"
15+
"charliermarsh.ruff"
1616
],
1717
"settings": {
18-
"editor.defaultFormatter": "ms-python.black-formatter",
18+
"editor.defaultFormatter": "charliermarsh.ruff",
1919
"editor.formatOnSave": true
2020
}
2121
}

.github/workflows/functional_test.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v4
1313

14-
- name: Check code formatting with Black
15-
uses: psf/black@stable
14+
- name: Install Python
15+
uses: actions/setup-python@v5
1616
with:
17-
options: "--check --verbose"
18-
src: "./src"
17+
python-version: "3.11"
18+
19+
- name: Install linter/formatter dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install ruff
23+
24+
- name: Run Linter
25+
run: ruff check --output-format=github src
26+
27+
- name: Run Formatter
28+
run: ruff format --check src
1929

2030
- name: Set up Docker Compose
2131
uses: docker/setup-buildx-action@v3

src/db.py

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,29 @@ def bulk_insert_instructors(cur: cursor, course: dict) -> list[int]:
9999
instructor_data = []
100100
instructor_names = []
101101
for instructor in course["instructors"]:
102-
instructor_data.append(
102+
instructor_data.append((
103+
instructor["name"],
103104
(
104-
instructor["name"],
105-
(
106-
instructor["rating"]["legacyId"]
107-
if instructor.get("rating", None) is not None
108-
else None
109-
),
110-
(
111-
instructor["rating"]["avgDifficulty"]
112-
if instructor.get("rating", None) is not None
113-
else None
114-
),
115-
(
116-
instructor["rating"]["avgRating"]
117-
if instructor.get("rating", None) is not None
118-
else None
119-
),
120-
(
121-
instructor["rating"]["numRatings"]
122-
if instructor.get("rating", None) is not None
123-
else None
124-
),
125-
)
126-
)
105+
instructor["rating"]["legacyId"]
106+
if instructor.get("rating", None) is not None
107+
else None
108+
),
109+
(
110+
instructor["rating"]["avgDifficulty"]
111+
if instructor.get("rating", None) is not None
112+
else None
113+
),
114+
(
115+
instructor["rating"]["avgRating"]
116+
if instructor.get("rating", None) is not None
117+
else None
118+
),
119+
(
120+
instructor["rating"]["numRatings"]
121+
if instructor.get("rating", None) is not None
122+
else None
123+
),
124+
))
127125

128126
instructor_names.append(instructor["name"])
129127

@@ -155,24 +153,22 @@ def bulk_insert_instructors(cur: cursor, course: dict) -> list[int]:
155153
def bulk_insert_courses(cur: cursor, courses_data: list[dict]):
156154
courses = []
157155
for course in courses_data:
158-
courses.append(
159-
(
160-
course["crn"],
161-
course["subject_code"],
162-
course["course_number"],
163-
course["instruction_type"],
164-
course["instruction_method"],
165-
course["section"],
166-
course["enroll"],
167-
course["max_enroll"],
168-
course["course_title"],
169-
course["credits"],
170-
course["prereqs"],
171-
course["start_time"],
172-
course["end_time"],
173-
course["days"],
174-
)
175-
)
156+
courses.append((
157+
course["crn"],
158+
course["subject_code"],
159+
course["course_number"],
160+
course["instruction_type"],
161+
course["instruction_method"],
162+
course["section"],
163+
course["enroll"],
164+
course["max_enroll"],
165+
course["course_title"],
166+
course["credits"],
167+
course["prereqs"],
168+
course["start_time"],
169+
course["end_time"],
170+
course["days"],
171+
))
176172

177173
cur.executemany(
178174
"""

src/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def main(args: argparse.Namespace):
3636

3737

3838
if __name__ == "__main__":
39-
4039
parser = argparse.ArgumentParser(
4140
description="Scrape data from Term Master Schedule and save it to a data.json file."
4241
)
@@ -67,7 +66,7 @@ def main(args: argparse.Namespace):
6766
if not os.path.exists("performance"):
6867
os.makedirs("performance")
6968
cProfile.run("main(args)", "performance/profile_output.pstat")
70-
except Exception as e:
69+
except Exception:
7170
trace = traceback.format_exc()
7271
print(trace)
7372

src/parse.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
def parse_subject_page(
88
html, data: dict, include_ratings: bool = False, ratings_cache: dict = {}
99
):
10-
1110
soup = BeautifulSoup(html, "html.parser")
1211
table_rows = soup.find_all("tr", class_=["odd", "even"])
1312

@@ -82,7 +81,6 @@ def get_instructors(
8281
name = instructor.strip()
8382

8483
if include_ratings:
85-
8684
# Search for first word and last word in name first
8785
# If that doesn't work, try first two words
8886
# If that still doesn't work, don't include rating
@@ -98,19 +96,15 @@ def get_instructors(
9896

9997
rating_obj = ratings_cache[name]
10098

101-
instructors.append(
102-
{
103-
"name": name,
104-
"rating": rating_obj,
105-
}
106-
)
99+
instructors.append({
100+
"name": name,
101+
"rating": rating_obj,
102+
})
107103

108104
else:
109-
instructors.append(
110-
{
111-
"name": name,
112-
}
113-
)
105+
instructors.append({
106+
"name": name,
107+
})
114108

115109
return instructors
116110

@@ -142,7 +136,6 @@ def fix_encoding_issue(text: str) -> str:
142136

143137

144138
def parse_days(d: str):
145-
146139
if d == "TBD":
147140
return None
148141

src/scrape.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def scrape_all_subjects(session: Session, data: dict, html: str, include_ratings
6262
for subject_page_link in college_page_soup.find_all(
6363
"a", href=lambda href: href and href.startswith("/webtms_du/courseList")
6464
):
65-
6665
try:
6766
response = send_request(
6867
session, config.tms_base_url + subject_page_link["href"]

0 commit comments

Comments
 (0)