Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Refactored backend database `runDb` helper in `app/Config.hs`
- Refactored `Database.Tables.MeetTime` into `Models.Meeting` and renamed it to `MeetingParsedData`; consolidated and refactored timetable JSON parsing helpers
- Restructured `courseography.cabal` to separate executable from library, extract shared settings, and remove `hlint`
- Refactored `createReqBody` in `app/Config.hs` to use session field from `config.yaml`

## [0.8.1] - 2026-08-10

Expand Down
15 changes: 12 additions & 3 deletions app/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Config (
timetableApiUrl,
fasCalendarUrl,
programsUrl,
timetableSessions,
createReqBody,
reqHeaders,
fallStartDate,
Expand Down Expand Up @@ -51,6 +52,7 @@ data Config = Config
, timetableApiUrlValue :: Text
, fasCalendarUrlValue :: String
, programsUrlValue :: String
, timetableSessionsValue :: [T.Text]
, fallStartDateValue :: Day
, fallEndDateValue :: Day
, winterStartDateValue :: Day
Expand All @@ -73,6 +75,7 @@ instance FromJSON Config where
<*> obj .: "timetableApiUrl"
<*> obj .: "fasCalendarUrl"
<*> obj .: "programsUrl"
<*> obj .: "timetableSessions"
<*> obj .: "fallStartDate"
<*> obj .: "fallEndDate"
<*> obj .: "winterStartDate"
Expand Down Expand Up @@ -159,11 +162,17 @@ fasCalendarUrl = fasCalendarUrlValue <$> loadConfig
programsUrl :: IO String
programsUrl = programsUrlValue <$> loadConfig

-- DATA FETCHING PARAMETERS

-- | The sessions field for the timetable API
timetableSessions :: IO [T.Text]
timetableSessions = timetableSessionsValue <$> loadConfig

-- HTTP REQUEST STRINGS

-- | Create the body for the HTTP request based on the page
createReqBody :: Int -> Value
createReqBody page =
createReqBody :: [T.Text] -> Int -> Value
createReqBody sessions page =
object
[ "campuses" .= ([] :: [T.Text])
, "courseCodeAndTitleProps"
Expand All @@ -184,7 +193,7 @@ createReqBody page =
, "page" .= page
, "pageSize" .= (300 :: Int)
, "requirementProps" .= ([] :: [T.Text])
, "sessions" .= (["20269", "20271", "20269-20271"] :: [T.Text])
, "sessions" .= sessions
, "timePreferences" .= ([] :: [T.Text])
]

Expand Down
5 changes: 3 additions & 2 deletions app/WebParsing/UtsgJsonParser.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module WebParsing.UtsgJsonParser (parseTimetable, insertTimetableData) where

import Config (createReqBody, reqHeaders, runDb, timetableApiUrl)
import Config (createReqBody, reqHeaders, runDb, timetableApiUrl, timetableSessions)
import Control.Monad.IO.Class (liftIO)
import Data.Aeson (Object, decode, encode, (.!=), (.:), (.:?))
import Data.Aeson.Types (Parser, parseMaybe)
Expand Down Expand Up @@ -34,7 +34,8 @@ parseTimetable = do
makeRequest :: Int -> IO ByteString
makeRequest pageNum = do
-- set up the request
let reqBody = createReqBody pageNum
sessions <- timetableSessions
let reqBody = createReqBody sessions pageNum
timetableApi <- liftIO timetableApiUrl
request <- liftIO $ parseRequest (T.unpack timetableApi)
let request' = request{method = "POST", requestBody = RequestBodyLBS $ encode reqBody, requestHeaders = reqHeaders}
Expand Down
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ timetableApiUrl: "https://api.easi.utoronto.ca/ttb/getPageableCourses"
fasCalendarUrl: "https://artsci.calendar.utoronto.ca/"
programsUrl: "https://artsci.calendar.utoronto.ca/listing-program-subject-areas"

# Data fetching parameters
timetableSessions:
Comment thread
david-yz-liu marked this conversation as resolved.
- "20269"
- "20271"
- "20269-20271"

# Term dates
fallStartDate: 2026-09-08
fallEndDate: 2026-12-07
Expand Down
Loading