Skip to content

Commit e584851

Browse files
Refactor quarter detection logic and improve code formatting
Co-authored-by: zohair.ul.hasan <[email protected]>
1 parent edb08a2 commit e584851

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/config.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import os
22
import sys
3+
34
from quarter_utils import get_current_quarter_and_year, get_quarter_name
45

56
# Automatically determine the current quarter and year
67
# Can be overridden with DREXEL_YEAR and DREXEL_QUARTER environment variables
78
if "DREXEL_YEAR" in os.environ and "DREXEL_QUARTER" in os.environ:
89
year = os.environ["DREXEL_YEAR"]
910
quarter = os.environ["DREXEL_QUARTER"]
10-
print(f"Using manually configured {get_quarter_name(quarter)} {year} quarter (code: {quarter})")
11+
print(
12+
f"Using manually configured {get_quarter_name(quarter)} {year} "
13+
f"quarter (code: {quarter})"
14+
)
1115
else:
1216
year, quarter = get_current_quarter_and_year()
13-
print(f"Using auto-detected {get_quarter_name(quarter)} {year} quarter (code: {quarter})")
17+
print(
18+
f"Using auto-detected {get_quarter_name(quarter)} {year} "
19+
f"quarter (code: {quarter})"
20+
)
1421

1522
# Note: These values are now automatically determined based on the current date
1623
# Fall (15): July 1 - September 27

src/quarter_utils.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
1+
"""Utilities for determining the current Drexel quarter based on date."""
2+
13
from datetime import datetime
2-
from typing import Tuple
34

45

5-
def get_current_quarter_and_year() -> Tuple[str, str]:
6+
def get_current_quarter_and_year() -> tuple[str, str]:
67
"""
78
Determine the current Drexel quarter and year based on the current date.
8-
9+
910
Drexel quarters:
1011
- Fall (15): July 1 - September 27
1112
- Winter (25): September 28 - January 15
1213
- Spring (35): January 16 - April 14
1314
- Summer (45): April 15 - June 30
14-
15+
1516
Returns:
1617
Tuple of (year, quarter_code) as strings
1718
"""
1819
now = datetime.now()
1920
month = now.month
2021
day = now.day
2122
year = now.year
22-
23+
2324
# Determine quarter based on month and day
24-
if (month == 7) or (month == 8) or (month == 9 and day <= 27):
25+
if month == 7 or month == 8 or (month == 9 and day <= 27):
2526
# Fall quarter
2627
quarter = "15"
27-
elif (month == 9 and day >= 28) or month == 10 or month == 11 or month == 12 or (month == 1 and day <= 15):
28+
elif (
29+
(month == 9 and day >= 28)
30+
or month == 10
31+
or month == 11
32+
or month == 12
33+
or (month == 1 and day <= 15)
34+
):
2835
# Winter quarter
2936
quarter = "25"
30-
elif (month == 1 and day >= 16) or month == 2 or month == 3 or (month == 4 and day <= 14):
37+
elif (
38+
(month == 1 and day >= 16)
39+
or month == 2
40+
or month == 3
41+
or (month == 4 and day <= 14)
42+
):
3143
# Spring quarter
3244
quarter = "35"
3345
else:
3446
# Summer quarter (April 15 - June 30)
3547
quarter = "45"
36-
48+
3749
# For Winter quarter spanning two calendar years (Sept 28 - Jan 15),
3850
# if we're in January, it belongs to the previous year's academic year
3951
if quarter == "25" and month == 1:
4052
year = year - 1
41-
53+
4254
return str(year), quarter
4355

4456

@@ -48,7 +60,7 @@ def get_quarter_name(quarter_code: str) -> str:
4860
"15": "Fall",
4961
"25": "Winter",
5062
"35": "Spring",
51-
"45": "Summer"
63+
"45": "Summer",
5264
}
5365
return quarter_names.get(quarter_code, "Unknown")
5466

0 commit comments

Comments
 (0)