Skip to content

Commit 621bc1c

Browse files
authored
Merge pull request #102 from UTDNebula/comet-cal-upload-and-automate
Comet calendar upload and automate
2 parents 321f9f3 + 7703882 commit 621bc1c

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func main() {
3939
// Flag for soc scraping
4040
scrapeOrganizations := flag.Bool("organizations", false, "Alongside -scrape, signifies that SOC organizations should be scraped.")
4141
// Flag for calendar scraping and parsing
42-
calendar := flag.Bool("calendar", false, "Alongside -scrape or -parse, signifies that calendar should be scraped.")
42+
cometCalendar := flag.Bool("cometCalendar", false, "Alongside -scrape or -parse, signifies that the Comet Calendar should be scraped/parsed.")
4343
// Flag for astra scraping and parsing
4444
astra := flag.Bool("astra", false, "Alongside -scrape or -parse, signifies that Astra should be scraped/parsed.")
4545
// Flag for mazevo scraping and parsing
@@ -56,7 +56,7 @@ func main() {
5656
upload := flag.Bool("upload", false, "Puts the tool into upload mode.")
5757
replace := flag.Bool("replace", false, "Alongside -upload, specifies that uploaded data should replace existing data rather than being merged.")
5858
staticOnly := flag.Bool("static", false, "Alongside -upload, specifies that we should only build and upload the static aggregations.")
59-
events := flag.Bool("events", false, "Alongside -upload, signifies that Astra and Mazevo should be uploaded.")
59+
events := flag.Bool("events", false, "Alongside -upload, signifies that Astra, Mazevo, and the Comet Calendar should be uploaded.")
6060

6161
// Flags for logging
6262
verbose := flag.Bool("verbose", false, "Enables verbose logging, good for debugging purposes.")
@@ -106,8 +106,8 @@ func main() {
106106
scrapers.ScrapeCoursebook(*term, *startPrefix, *outDir, *resume)
107107
case *scrapeOrganizations:
108108
scrapers.ScrapeOrganizations(*outDir)
109-
case *calendar:
110-
scrapers.ScrapeCalendar(*outDir)
109+
case *cometCalendar:
110+
scrapers.ScrapeCometCalendar(*outDir)
111111
case *astra:
112112
scrapers.ScrapeAstra(*outDir)
113113
case *mazevo:
@@ -119,8 +119,8 @@ func main() {
119119
}
120120
case *parse:
121121
switch {
122-
case *calendar:
123-
parser.ParseCalendar(*inDir, *outDir)
122+
case *cometCalendar:
123+
parser.ParseCometCalendar(*inDir, *outDir)
124124
case *astra:
125125
parser.ParseAstra(*inDir, *outDir)
126126
case *mazevo:
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ var validAbbreviations []string = []string{
131131
"RCW",
132132
}
133133

134-
func ParseCalendar(inDir string, outDir string) {
135-
136-
calendarFile, err := os.ReadFile(inDir + "/eventScraped.json")
134+
func ParseCometCalendar(inDir string, outDir string) {
135+
136+
calendarFile, err := os.ReadFile(inDir + "/cometCalendarScraped.json")
137137
if err != nil {
138138
panic(err)
139139
}
140-
140+
141141
var allEvents []schema.Event
142142

143143
err = json.Unmarshal(calendarFile, &allEvents)
@@ -147,7 +147,7 @@ func ParseCalendar(inDir string, outDir string) {
147147

148148
multiBuildingMap := make(map[string]map[string]map[string][]schema.Event)
149149

150-
for _, event := range(allEvents) {
150+
for _, event := range allEvents {
151151

152152
// Get date
153153
dateTime := event.StartTime
@@ -166,7 +166,7 @@ func ParseCalendar(inDir string, outDir string) {
166166

167167
// buildingRegexp might capture something that isn't a valid building abbreviation (e.g., UTD)
168168
isValidBuilding := slices.Contains(validAbbreviations, building)
169-
169+
170170
// If location doesn't have building abbreviation or buildingRegexp captured an invalid abbreviation,
171171
// check for the full building name
172172
lowercaseLocation := strings.ToLower(*location)
@@ -178,13 +178,13 @@ func ParseCalendar(inDir string, outDir string) {
178178
}
179179
}
180180
}
181-
181+
182182
// If location doesn't have room number, check to see if location included a room
183183
if room == "" && isValidBuilding {
184184
locationParts := strings.SplitN(*location, ",", 2)
185185
if len(locationParts) == 2 {
186186
room = locationParts[1]
187-
}
187+
}
188188
}
189189

190190
// If building is still empty string, then location was initally an empty string
@@ -218,13 +218,13 @@ func ParseCalendar(inDir string, outDir string) {
218218
var roomEvents []schema.RoomEvents[schema.Event]
219219
for room, events := range rooms {
220220
roomEvents = append(roomEvents, schema.RoomEvents[schema.Event]{
221-
Room: room,
221+
Room: strings.TrimSpace(room),
222222
Events: events,
223223
})
224224
}
225225

226226
singleBuildings = append(singleBuildings, schema.SingleBuildingEvents[schema.Event]{
227-
Building: building,
227+
Building: strings.TrimSpace(building),
228228
Rooms: roomEvents,
229229
})
230230
}
@@ -234,8 +234,8 @@ func ParseCalendar(inDir string, outDir string) {
234234
Buildings: singleBuildings,
235235
})
236236
}
237-
238-
log.Print("Parsed Calendar!")
239237

240-
utils.WriteJSON(fmt.Sprintf("%s/events.json", outDir), result)
241-
}
238+
log.Print("Parsed Comet Calendar!")
239+
240+
utils.WriteJSON(fmt.Sprintf("%s/cometCalendar.json", outDir), result)
241+
}

runners/daily.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
./api-tools -headless -verbose -parse -mazevo
88
./api-tools -headless -verbose -scrape -astra
99
./api-tools -headless -verbose -parse -astra
10+
./api-tools -headless -verbose -scrape -cometCalendar
11+
./api-tools -headless -verbose -parse -cometCalendar
1012
./api-tools -headless -verbose -upload -events
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type APICalendarResponse struct {
3131
Date map[string]string `json:"date"`
3232
}
3333

34-
// ScrapeCalendar retrieves calendar events through the API and writes normalized JSON output.
35-
func ScrapeCalendar(outDir string) {
34+
// ScrapeCometCalendar retrieves calendar events through the API and writes normalized JSON output.
35+
func ScrapeCometCalendar(outDir string) {
3636
err := os.MkdirAll(outDir, 0777)
3737
if err != nil {
3838
panic(err)
@@ -134,7 +134,7 @@ func ScrapeCalendar(outDir string) {
134134
log.Printf("Parsed the events of page %d successfully!\n\n", page+1)
135135
}
136136

137-
if err := utils.WriteJSON(fmt.Sprintf("%s/eventScraped.json", outDir), events); err != nil {
137+
if err := utils.WriteJSON(fmt.Sprintf("%s/cometCalendarScraped.json", outDir), events); err != nil {
138138
panic(err)
139139
}
140140
log.Printf("Finished parsing %d events successfully!\n\n", len(events))

uploader/eventsUploader.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// Note that this uploader assumes that the collection names match the names of these files, which they should.
1919
// If the names of these collections ever change, the file names should be updated accordingly.
2020

21-
var eventsFilesToUpload [2]string = [2]string{"astra.json", "mazevo.json"}
21+
var eventsFilesToUpload [3]string = [3]string{"astra.json", "mazevo.json", "cometCalendar.json"}
2222

2323
// UploadEvents loads event JSON files and replaces the corresponding MongoDB collections.
2424
func UploadEvents(inDir string) {
@@ -54,6 +54,8 @@ func UploadEvents(inDir string) {
5454
UploadData[schema.MultiBuildingEvents[schema.AstraEvent]](client, ctx, fptr, true)
5555
case "mazevo.json":
5656
UploadData[schema.MultiBuildingEvents[schema.MazevoEvent]](client, ctx, fptr, true)
57+
case "cometCalendar.json":
58+
UploadData[schema.MultiBuildingEvents[schema.Event]](client, ctx, fptr, true)
5759
}
5860
}
5961
}

0 commit comments

Comments
 (0)