Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active October 25, 2021 17:43
Show Gist options
  • Select an option

  • Save jayhuang75/6ece0364def0113dd547289aec008a9e to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/6ece0364def0113dd547289aec008a9e to your computer and use it in GitHub Desktop.
go-train-delay-inline-processor.go
func (a *App) processEmail(email_list *gmail.ListMessagesResponse, total int64) ([]DelayDataSet, error) {
delayDataSet := []DelayDataSet{}
bar := processBar(total, "[email] processing...")
for _, l := range email_list.Messages {
log.Debugf("[processEmail] processing email id: %s\n", l.Id)
msg, err := a.getEmail(l.Id)
if err != nil {
log.Fatalf("[processEmail] Unable to retrieve msg: %v", err)
}
// reduce part
delay_email, mins := getDelayDetails(msg)
if delay_email != "" {
delayData := DelayDataSet{}
// process to get
// departure station
departure, destination := inlineProcessor(delay_email)
delayData.Departure = departure
delayData.Destination = destination
delayData.Mins = mins
// process to get timestamp
delayData.Date = getDateFromHeader(msg)
delayDataSet = append(delayDataSet, delayData)
}
bar.Add(1)
time.Sleep(10 * time.Millisecond)
}
return delayDataSet, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment