Skip to content

Commit a463ebb

Browse files
committed
made use of python 3.10+ typing features
1 parent dcb5f8b commit a463ebb

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

cache/ratings_cache.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515

1616
from datetime import datetime
1717
from pytz import timezone
18+
from typing import Any
1819

19-
from typing import Dict, Any
2020

21-
22-
def populate_db(data: Dict[str, Dict[str, Any]]) -> None:
21+
def populate_db(data: dict[str, dict[str, Any]]) -> None:
2322
cur, conn = connect_to_db()
2423

2524
create_tables(cur)

src/emailer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
import boto3
77
import config
8-
from typing import Optional
98

109

1110
def send_email(subject: str, body: str) -> bool:
1211
topic_arn = config.topic_arn
1312
return publish_to_sns(topic_arn, subject, body)
1413

1514

16-
def publish_to_sns(topic_arn: Optional[str], subject: str, body: str) -> bool:
15+
def publish_to_sns(topic_arn: str | None, subject: str, body: str) -> bool:
1716
sns = boto3.client("sns", endpoint_url=config.sns_endpoint)
1817

1918
if topic_arn is None: # will be None for local testing
@@ -25,7 +24,7 @@ def publish_to_sns(topic_arn: Optional[str], subject: str, body: str) -> bool:
2524
return False
2625

2726

28-
def get_sns_topic_arn(topic_name: str) -> Optional[str]:
27+
def get_sns_topic_arn(topic_name: str) -> str | None:
2928
sns = boto3.client("sns", endpoint_url=config.sns_endpoint)
3029
response = sns.list_topics()
3130
for topic in response["Topics"]:

src/parse.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ratings import rating
44
from datetime import datetime
55
import re
6-
from typing import Optional
76

87

98
def parse_subject_page(
@@ -74,7 +73,7 @@ def parse_crn_page(html: str, data: dict) -> None:
7473

7574
def get_instructors(
7675
instructors_str: str, include_ratings: bool, ratings_cache: dict
77-
) -> Optional[list]:
76+
) -> list | None:
7877
if instructors_str == "STAFF":
7978
return None
8079

@@ -149,7 +148,7 @@ def fix_encoding_issue(text: str) -> str:
149148
return text.replace("\xa0", " ")
150149

151150

152-
def parse_days(d: str) -> Optional[list[str]]:
151+
def parse_days(d: str) -> list[str] | None:
153152
if d == "TBD":
154153
return None
155154

@@ -170,7 +169,7 @@ def parse_days(d: str) -> Optional[list[str]]:
170169
return days
171170

172171

173-
def parse_time(t: str) -> tuple[Optional[str], Optional[str]]:
172+
def parse_time(t: str) -> tuple[str | None, str | None]:
174173
if t == "TBD":
175174
return (None, None)
176175
start_str, end_str = t.split(" - ")

src/ratings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import requests
66
from helpers import send_request
7-
from typing import Any, List, Dict, Optional
7+
from typing import Any
88

99
DREXEL_RMP_ID = "U2Nob29sLTE1MjE="
1010

@@ -14,7 +14,7 @@
1414
AUTHORIZATION_HEADER = "Basic dGVzdDp0ZXN0"
1515

1616

17-
def search_professors(professor_name: str) -> List[Dict[str, Dict[str, str]]]:
17+
def search_professors(professor_name: str) -> list[dict[str, dict[str, str]]]:
1818
query = """query searchProf($query: TeacherSearchQuery!){
1919
newSearch {
2020
teachers(query: $query) {
@@ -43,7 +43,7 @@ def search_professors(professor_name: str) -> List[Dict[str, Dict[str, str]]]:
4343
return response.json()["data"]["newSearch"]["teachers"]["edges"]
4444

4545

46-
def get_ratings(id: str) -> Dict[str, Any]:
46+
def get_ratings(id: str) -> dict[str, Any]:
4747
query = """query TeacherRatingsPageQuery($id: ID!){
4848
node(id: $id) {
4949
__typename
@@ -69,7 +69,7 @@ def get_ratings(id: str) -> Dict[str, Any]:
6969
return response.json()["data"]["node"]
7070

7171

72-
def rating(professor_name: str) -> Optional[Dict[str, int]]:
72+
def rating(professor_name: str) -> dict[str, int] | None:
7373
professor = search_professors(professor_name)
7474

7575
if len(professor) == 0:

0 commit comments

Comments
 (0)