Skip to content

Commit 090021b

Browse files
Add automatic quarter detection for Drexel course scraper
Co-authored-by: zohair.ul.hasan <[email protected]>
1 parent 7d0b70c commit 090021b

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,23 @@ python src/main.py
4444

4545
The scraper will output a JSON file called `data.json` in the same directory as the scraper.
4646

47-
You can modify the scraper to scrape other terms by changing the `year`, `quarter`, and `college_code` variables in `src/config.py`.
47+
#### Automatic Quarter Detection
48+
49+
The scraper now automatically detects the current Drexel quarter based on the current date. You no longer need to manually update the `year` and `quarter` values in `src/config.py`. The system uses the following schedule:
50+
51+
- **Fall Quarter (15)**: September 23 - December 31
52+
- **Winter Quarter (25)**: January 1 - March 22
53+
- **Spring Quarter (35)**: March 23 - June 14
54+
- **Summer Quarter (45)**: June 15 - September 22
55+
56+
If you need to override the automatic detection (e.g., for testing or scraping a specific past/future quarter), you can set the `DREXEL_YEAR` and `DREXEL_QUARTER` environment variables:
57+
58+
```bash
59+
export DREXEL_YEAR=2024
60+
export DREXEL_QUARTER=35 # Spring quarter
61+
```
62+
63+
You can still modify the `college_code` variable in `src/config.py` to scrape a specific college.
4864

4965
To view all the options that the scraper supports, run `python3 src/main.py --help` on Mac/Linux, or `python src/main.py --help` on Windows.
5066

src/config.py

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

4-
# in format YYYY (e.g. 2022)
5-
# example value: 2022
6-
year = "2024"
7-
# 15 for Fall, 25 for Winter, 35 for Spring, 45 for Summer
8-
# example value: 45
9-
quarter = "45"
5+
# Automatically determine the current quarter and year
6+
# Can be overridden with DREXEL_YEAR and DREXEL_QUARTER environment variables
7+
if "DREXEL_YEAR" in os.environ and "DREXEL_QUARTER" in os.environ:
8+
year = os.environ["DREXEL_YEAR"]
9+
quarter = os.environ["DREXEL_QUARTER"]
10+
print(f"Using manually configured {get_quarter_name(quarter)} {year} quarter (code: {quarter})")
11+
else:
12+
year, quarter = get_current_quarter_and_year()
13+
print(f"Using auto-detected {get_quarter_name(quarter)} {year} quarter (code: {quarter})")
14+
15+
# Note: These values are now automatically determined based on the current date
16+
# Fall (15): Late September - Mid December
17+
# Winter (25): Early January - Late March
18+
# Spring (35): Late March/Early April - Mid June
19+
# Summer (45): Late June - Early September
1020
# check college code by going to the tms website and selecting your college from the left sidebar
1121
# the URL bar should update and it should end with something like collCode=CI
1222
# the characters after the = sign is your college code

src/quarter_utils.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from datetime import datetime
2+
from typing import Tuple
3+
4+
5+
def get_current_quarter_and_year() -> Tuple[str, str]:
6+
"""
7+
Determine the current Drexel quarter and year based on the current date.
8+
9+
Drexel quarters:
10+
- Fall (15): Late September - Mid December
11+
- Winter (25): Early January - Late March
12+
- Spring (35): Late March/Early April - Mid June
13+
- Summer (45): Late June - Early September
14+
15+
Returns:
16+
Tuple of (year, quarter_code) as strings
17+
"""
18+
now = datetime.now()
19+
month = now.month
20+
day = now.day
21+
year = now.year
22+
23+
# Determine quarter based on month and day
24+
if month == 1 or month == 2 or (month == 3 and day <= 22):
25+
# Winter quarter
26+
quarter = "25"
27+
elif (month == 3 and day > 22) or month == 4 or month == 5 or (month == 6 and day <= 14):
28+
# Spring quarter
29+
quarter = "35"
30+
elif (month == 6 and day > 14) or month == 7 or month == 8 or (month == 9 and day <= 22):
31+
# Summer quarter
32+
quarter = "45"
33+
else:
34+
# Fall quarter (Sept 23 - Dec 31)
35+
quarter = "15"
36+
37+
# For Fall quarter, if we're in September-December, it's the current year
38+
# For other quarters in January-August, they belong to the current year
39+
return str(year), quarter
40+
41+
42+
def get_quarter_name(quarter_code: str) -> str:
43+
"""Get the human-readable name for a quarter code."""
44+
quarter_names = {
45+
"15": "Fall",
46+
"25": "Winter",
47+
"35": "Spring",
48+
"45": "Summer"
49+
}
50+
return quarter_names.get(quarter_code, "Unknown")
51+
52+
53+
if __name__ == "__main__":
54+
# Test the function
55+
year, quarter = get_current_quarter_and_year()
56+
quarter_name = get_quarter_name(quarter)
57+
print(f"Current quarter: {quarter_name} {year} (code: {quarter})")

0 commit comments

Comments
 (0)