Compare commits
6 Commits
v1.0.0
...
2211488f9a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2211488f9a | ||
|
|
e97f048eb6 | ||
|
|
e6aeb0158a | ||
|
|
19508f38e8 | ||
|
|
90c356584e | ||
|
|
585445cb6a |
18
config.toml
18
config.toml
@@ -1,18 +0,0 @@
|
||||
# User Constants - Update as needed
|
||||
batch_size = 500 # Max 500 messages per batch: https://postmarkapp.com/developer/api/templates-api#send-batch-with-templates
|
||||
test_email = "" # Fill this in with your own email address
|
||||
|
||||
# Handmade Cities Credentials - DON'T TOUCH
|
||||
[hmc]
|
||||
api_url = "https://api.handmadecities.com/v1/meetups/subscribers"
|
||||
shared_secret = "Land_OF_TERminA__MAJORAS_LAIR#666!"
|
||||
city = "Termina"
|
||||
|
||||
# Postmark App Credentials - NO TOUCHY TOUCHY
|
||||
[postmark]
|
||||
server_token = "37967b9a-6b1c-430e-a65f-de043de3e568"
|
||||
api_url = "https://api.postmarkapp.com/email/batchWithTemplates"
|
||||
template_id = 35682307
|
||||
sender_name = "Skull Kid"
|
||||
sender_email = "majora@handmadecities.com"
|
||||
message_stream = "termina"
|
||||
36
main.go
36
main.go
@@ -7,14 +7,14 @@
|
||||
// ============================ Contributors =========================
|
||||
// Bug & warning fixes
|
||||
// Jacob Bell (@MysteriousJ)
|
||||
// Asaf Gartner
|
||||
// Asaf Gartner (@AsafGartner)
|
||||
// Joshua Barnett (@jshbrntt)
|
||||
// Jack Punter (@TarriestPython)
|
||||
//
|
||||
// Emotional Support
|
||||
// Cucui Ganon Rosario
|
||||
// =========================================================================
|
||||
|
||||
// WARNING: This program requires a companion config.toml file provided by Abner. Without it we will crash!
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -113,15 +113,21 @@ func retrieveSubscribers(cfg *Config) ([]string, error) {
|
||||
return nil, errors.New("response format error: 'emails' field not found")
|
||||
}
|
||||
|
||||
/* Convert emails to []string */
|
||||
/* De-duplicate emails using a map */
|
||||
/* *** */
|
||||
var subscribers []string
|
||||
emailMap := make(map[string]bool)
|
||||
for _, email := range emails {
|
||||
if emailStr, ok := email.(string); ok {
|
||||
subscribers = append(subscribers, emailStr)
|
||||
emailMap[emailStr] = true
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert the map keys back to a slice */
|
||||
var subscribers []string
|
||||
for email := range emailMap {
|
||||
subscribers = append(subscribers, email)
|
||||
}
|
||||
|
||||
return subscribers, nil
|
||||
}
|
||||
|
||||
@@ -276,6 +282,13 @@ func blastMail(cfg *Config, logFile string, trackingFile string, audience []stri
|
||||
}
|
||||
}
|
||||
|
||||
existingReaderCount := len(sentToAddresses)
|
||||
newReaderCount := 0
|
||||
|
||||
if existingReaderCount > 0 {
|
||||
fmt.Println("Same email file specified: Sending only to new subscribers...")
|
||||
}
|
||||
|
||||
var group []string
|
||||
for _, a := range audience {
|
||||
if a == "" {
|
||||
@@ -301,6 +314,7 @@ func blastMail(cfg *Config, logFile string, trackingFile string, audience []stri
|
||||
for i, res := range results {
|
||||
log.WriteString(fmt.Sprintf("%s: %s\n", group[i], res.Message))
|
||||
}
|
||||
newReaderCount += len(group)
|
||||
group = group[0:0]
|
||||
}
|
||||
}
|
||||
@@ -316,7 +330,17 @@ func blastMail(cfg *Config, logFile string, trackingFile string, audience []stri
|
||||
for i, res := range results {
|
||||
log.WriteString(fmt.Sprintf("%s: %s\n", group[i], res.Message))
|
||||
}
|
||||
newReaderCount += len(group)
|
||||
}
|
||||
|
||||
if newReaderCount > 0 {
|
||||
newSubscribers := existingReaderCount > 0
|
||||
if newSubscribers {
|
||||
fmt.Printf("Sent to %d new subscribers!\n", newReaderCount)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Not sent (no new subscribers)\n")
|
||||
}
|
||||
}
|
||||
|
||||
var postmarkClient = http.Client{}
|
||||
|
||||
Reference in New Issue
Block a user