@@ -19,7 +19,7 @@ import (
1919 "go.mongodb.org/mongo-driver/bson/primitive"
2020)
2121
22- const BASE_CAL_URL string = "https://calendar.utdallas.edu/api/2/events"
22+ const CAL_URL string = "https://calendar.utdallas.edu/api/2/events"
2323
2424// RawEvent mirrors the nested event payload returned by the calendar API.
2525type RawEvent struct {
@@ -44,7 +44,8 @@ func ScrapeCometCalendar(outDir string) {
4444
4545 // Get the total number of pages
4646 log .Printf ("Getting the number of pages..." )
47- if err := callAPIAndUnmarshal (& client , 0 , & calendarData ); err != nil {
47+
48+ if err := callAndUnmarshal (& client , 0 , & calendarData ); err != nil {
4849 panic (err )
4950 }
5051 numPages := calendarData .Page ["total" ]
@@ -53,7 +54,7 @@ func ScrapeCometCalendar(outDir string) {
5354 var calendarEvents []schema.Event
5455 for page := range numPages {
5556 log .Printf ("Scraping events of page %d..." , page + 1 )
56- if err := callAPIAndUnmarshal (& client , page + 1 , & calendarData ); err != nil {
57+ if err := callAndUnmarshal (& client , page + 1 , & calendarData ); err != nil {
5758 panic (err )
5859 }
5960 for _ , rawEvent := range calendarData .Events {
@@ -81,20 +82,22 @@ func ScrapeCometCalendar(outDir string) {
8182 ContactPhoneNumber : contactInfo [2 ],
8283 })
8384 }
85+
8486 log .Printf ("Scraped events of page %d successfully!\n " , page + 1 )
8587 }
8688
8789 writePath := fmt .Sprintf ("%s/cometCalendarScraped.json" , outDir )
8890 if err := utils .WriteJSON (writePath , calendarEvents ); err != nil {
8991 panic (err )
9092 }
93+
9194 log .Printf ("Finished scraping %d events successfully!\n \n " , len (calendarEvents ))
9295}
9396
9497// scrapeAndUnmarshal fetches a calendar page and decodes it into data.
95- func callAPIAndUnmarshal (client * http.Client , page int , data * APICalendarResponse ) error {
98+ func callAndUnmarshal (client * http.Client , page int , data * APICalendarResponse ) error {
9699 // Call API to get the byte data
97- calendarUrl := fmt .Sprintf ("%s?days=365&pp=100&page=%d" , BASE_CAL_URL , page )
100+ calendarUrl := fmt .Sprintf ("%s?days=365&pp=100&page=%d" , CAL_URL , page )
98101 request , err := http .NewRequest ("GET" , calendarUrl , nil )
99102 if err != nil {
100103 return err
@@ -162,7 +165,7 @@ func getEventLocation(event RawEvent) string {
162165// getFilters parses the types, topics, and target audiences
163166func getFilters (event RawEvent ) ([]string , []string , []string ) {
164167 types := []string {}
165- targetAudiences := []string {}
168+ audiences := []string {}
166169 topics := []string {}
167170
168171 filters := convert [map [string ]any ](event .Event ["filters" ])
@@ -174,15 +177,15 @@ func getFilters(event RawEvent) ([]string, []string, []string) {
174177
175178 rawAudiences := convert [[]any ](filters ["event_target_audience" ])
176179 for _ , audience := range rawAudiences {
177- targetAudiences = append (targetAudiences , convert [string ](convert [map [string ]any ](audience )["name" ]))
180+ audiences = append (audiences , convert [string ](convert [map [string ]any ](audience )["name" ]))
178181 }
179182
180183 rawTopics := convert [[]any ](filters ["event_topic" ])
181184 for _ , topic := range rawTopics {
182185 topics = append (topics , convert [string ](convert [map [string ]any ](topic )["name" ]))
183186 }
184187
185- return types , targetAudiences , topics
188+ return types , audiences , topics
186189}
187190
188191// getDepartmentsAndTags parses the departments, and tags
0 commit comments