Skip to content

Commit 2395774

Browse files
committed
I like it that way
1 parent f355915 commit 2395774

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

parser/cometCalendarParser.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ func getLocationAbbreviations(inDir string) (map[string]string, []string) {
259259
scrapers.ScrapeMapLocations(inDir)
260260
time.Sleep(2 * time.Second)
261261
ParseMapLocations(inDir, inDir)
262-
time.Sleep(2 * time.Second) // Probably a good idea to let it sleep before moving on?
262+
time.Sleep(2 * time.Second)
263263

264-
// If fail to get the locations again, not because unscraped
265-
mapFile, _ = os.ReadFile(inDir + "/mapLocations.json")
264+
// If fail to get the locations again, it's not because location is unscraped
265+
mapFile, err = os.ReadFile(inDir + "/mapLocations.json")
266+
if err != nil {
267+
panic(err)
268+
}
266269
} else {
267270
panic(err)
268271
}
@@ -280,13 +283,13 @@ func getLocationAbbreviations(inDir string) (map[string]string, []string) {
280283
// Trim the following acronym in the name
281284
trimmedName := strings.Split(*location.Name, " (")[0]
282285
// Fallback on the locations that have no acronyms
283-
acronym := ""
286+
abbreviation := ""
284287
if location.Acronym != nil {
285-
acronym = *location.Acronym
288+
abbreviation = *location.Acronym
286289
}
287290

288-
buildingsAbbreviations[trimmedName] = acronym
289-
validAbbreviations = append(validAbbreviations, acronym)
291+
buildingsAbbreviations[trimmedName] = abbreviation
292+
validAbbreviations = append(validAbbreviations, abbreviation)
290293
}
291294

292295
return buildingsAbbreviations, validAbbreviations

scrapers/cometCalendar.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ func callAndUnmarshal(client *http.Client, page int, data *APICalendarResponse)
131131
// getTime parses the start and end time of the event
132132
func getTime(event RawEvent) (time.Time, time.Time) {
133133
instance := convert[map[string]any](
134-
convert[map[string]any](
135-
convert[[]any](event.Event["event_instances"])[0])["event_instance"])
134+
convert[map[string]any](convert[[]any](event.Event["event_instances"])[0])["event_instance"])
136135

137136
// Converts RFC3339 timestamp string to time.Time
138137
startTime, err := time.Parse(time.RFC3339, convert[string](instance["start"]))
@@ -164,28 +163,28 @@ func getEventLocation(event RawEvent) string {
164163

165164
// getFilters parses the types, topics, and target audiences
166165
func getFilters(event RawEvent) ([]string, []string, []string) {
167-
types := []string{}
168-
audiences := []string{}
169-
topics := []string{}
166+
eventTypes := []string{}
167+
targetAudiences := []string{}
168+
eventTopics := []string{}
170169

171170
filters := convert[map[string]any](event.Event["filters"])
172171

173172
rawTypes := convert[[]any](filters["event_types"])
174173
for _, rawType := range rawTypes {
175-
types = append(types, convert[string](convert[map[string]any](rawType)["name"]))
174+
eventTypes = append(eventTypes, convert[string](convert[map[string]any](rawType)["name"]))
176175
}
177176

178177
rawAudiences := convert[[]any](filters["event_target_audience"])
179178
for _, audience := range rawAudiences {
180-
audiences = append(audiences, convert[string](convert[map[string]any](audience)["name"]))
179+
targetAudiences = append(targetAudiences, convert[string](convert[map[string]any](audience)["name"]))
181180
}
182181

183182
rawTopics := convert[[]any](filters["event_topic"])
184183
for _, topic := range rawTopics {
185-
topics = append(topics, convert[string](convert[map[string]any](topic)["name"]))
184+
eventTopics = append(eventTopics, convert[string](convert[map[string]any](topic)["name"]))
186185
}
187186

188-
return types, audiences, topics
187+
return eventTypes, targetAudiences, eventTopics
189188
}
190189

191190
// getDepartmentsAndTags parses the departments, and tags

0 commit comments

Comments
 (0)