Compare commits
No commits in common. "4f10099b4173ab5d113004c1f48308c5b6159671" and "05fb63e633baaeb712288e563759dfbd08fda581" have entirely different histories.
4f10099b41
...
05fb63e633
71
main.go
71
main.go
|
|
@ -194,6 +194,7 @@ func sendTest(cfg *Config, markdownFile string) {
|
||||||
/* *** */
|
/* *** */
|
||||||
url, valid := bloggify(cfg, subject, body, false)
|
url, valid := bloggify(cfg, subject, body, false)
|
||||||
if !valid {
|
if !valid {
|
||||||
|
fmt.Printf("Error converting '%s' into a blog post\n", markdownFile)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,24 +218,21 @@ func sendTest(cfg *Config, markdownFile string) {
|
||||||
os.WriteFile(sha1File, []byte(sumString), 0666)
|
os.WriteFile(sha1File, []byte(sumString), 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
func bloggify(cfg *Config, subject, body string, isLive bool) (url string, valid bool) {
|
||||||
if !isLive {
|
if !isLive {
|
||||||
return "https://handmadecities.com/meetupinvite2000", true
|
return "https://handmadecities.com/meetup-invite-test", true
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare request payload */
|
/* Prepare request payload */
|
||||||
/* *** */
|
/* *** */
|
||||||
payload := map[string]string{
|
payload := map[string]string{
|
||||||
"city": cfg.HMC.City,
|
|
||||||
"author": cfg.Postmark.SenderName,
|
|
||||||
"email": cfg.Postmark.SenderEmail,
|
|
||||||
"subject": subject,
|
"subject": subject,
|
||||||
"body": body,
|
"body": body,
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes, err := json.Marshal(payload)
|
payloadBytes, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error encoding payload: %v\n", err)
|
fmt.Printf("Error encoding bloggify payload: %v\n", err)
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,41 +240,19 @@ func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
||||||
/* *** */
|
/* *** */
|
||||||
req, err := http.NewRequest("POST", "https://deploy.handmadecities.com/v1/bloggify", bytes.NewReader(payloadBytes))
|
req, err := http.NewRequest("POST", "https://deploy.handmadecities.com/v1/bloggify", bytes.NewReader(payloadBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error creating request: %v\n", err)
|
fmt.Printf("Error creating bloggify request: %v\n", err)
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Authorization", cfg.HMC.SharedSecret)
|
req.Header.Set("Authorization", cfg.HMC.SharedSecret)
|
||||||
|
|
||||||
/* Spinner while request runs */
|
|
||||||
/* *** */
|
|
||||||
stop := make(chan struct{})
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
frames := []rune{'⠁', '⠂', '⠄', '⡀', '⢀', '⠠', '⠐', '⠈'}
|
|
||||||
i := 0
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-stop:
|
|
||||||
close(done)
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
fmt.Printf("\r📝 Bloggifying your email... %c", frames[i%len(frames)])
|
|
||||||
i++
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
/* Execute request */
|
/* Execute request */
|
||||||
/* *** */
|
/* *** */
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
close(stop)
|
fmt.Printf("Error making bloggify request: %v\n", err)
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[31m📝 Failed to bloggify: %v\033[0m\n", err)
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
@ -284,9 +260,7 @@ func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
||||||
/* Fail if status code is not in the 2xx range */
|
/* Fail if status code is not in the 2xx range */
|
||||||
/* *** */
|
/* *** */
|
||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
close(stop)
|
fmt.Printf("Bloggify error: HTTP status code %d\n", resp.StatusCode)
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[31m📝 Bloggify error: HTTP status code %d\033[0m\n", resp.StatusCode)
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,9 +268,7 @@ func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
||||||
/* *** */
|
/* *** */
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
close(stop)
|
fmt.Printf("Error reading bloggify response body: %v\n", err)
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[31m📝 Error reading bloggify response: %v\033[0m\n", err)
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,9 +276,7 @@ func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
||||||
/* *** */
|
/* *** */
|
||||||
var data map[string]interface{}
|
var data map[string]interface{}
|
||||||
if err := json.Unmarshal(respBody, &data); err != nil {
|
if err := json.Unmarshal(respBody, &data); err != nil {
|
||||||
close(stop)
|
fmt.Printf("Error unmarshalling bloggify JSON: %v\n", err)
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[31m📝 Error parsing bloggify JSON: %v\033[0m\n", err)
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,16 +284,10 @@ func bloggify(cfg *Config, subject, body string, isLive bool) (string, bool) {
|
||||||
/* *** */
|
/* *** */
|
||||||
url, ok := data["url"].(string)
|
url, ok := data["url"].(string)
|
||||||
if !ok || url == "" {
|
if !ok || url == "" {
|
||||||
close(stop)
|
fmt.Println("Bloggify response format error: 'url' field not found or empty")
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[31m📝 Bloggify response missing 'url' field\033[0m\n")
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
close(stop)
|
|
||||||
<-done
|
|
||||||
fmt.Printf("\r\033[32m📝 Your email is a blog post at %s\033[0m\n", url)
|
|
||||||
|
|
||||||
return url, true
|
return url, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +315,7 @@ func sendNews(cfg *Config, markdownFile string) {
|
||||||
/* *** */
|
/* *** */
|
||||||
url, valid := bloggify(cfg, subject, body, true)
|
url, valid := bloggify(cfg, subject, body, true)
|
||||||
if !valid {
|
if !valid {
|
||||||
fmt.Printf("Error converting '%s' into a blog post\n%v\n", markdownFile, err)
|
fmt.Printf("Error converting '%s' into a blog post\n", markdownFile)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1093,7 +1057,7 @@ func main() {
|
||||||
* Batch sends your invite using our Email API (Postmark)
|
* Batch sends your invite using our Email API (Postmark)
|
||||||
* Produces .track file that tracks email addresses we attempted to send to
|
* Produces .track file that tracks email addresses we attempted to send to
|
||||||
* Produces .log file with information received back from Postmark
|
* Produces .log file with information received back from Postmark
|
||||||
* You can always blast again: addresses in .track files are skipped
|
* You can always blast again: useful when emailing new subscribers. Addresses already in .track file will be skipped
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -1146,17 +1110,6 @@ func main() {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
fmt.Printf("Ready to blast to everyone in %s? (Y/n): ", config.HMC.City)
|
|
||||||
resp, _ := reader.ReadString('\n')
|
|
||||||
resp = strings.TrimSpace(strings.ToLower(resp))
|
|
||||||
|
|
||||||
if resp != "" && resp != "y" && resp != "yes" {
|
|
||||||
fmt.Println("Blast cancelled.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
updateFile := args[0]
|
updateFile := args[0]
|
||||||
sendNews(config, updateFile)
|
sendNews(config, updateFile)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue