Ejemplo n.º 1
0
func init() {
	rand.Seed(time.Now().UTC().UnixNano())

	stripeSecretKey := config.StripeTestSecretKey
	stripePublicKey = config.StripeTestPublicKey

	var cwd, _ = filepath.Abs(filepath.Dir(os.Args[0]))
	if os.Getenv("ENV") == "production" {
		STATIC_DIR = cwd + "/" + STATIC_DIR
		stripeSecretKey = config.StripeLiveSecretKey
		stripePublicKey = config.StripeLivePublicKey
	}
	stripe.SetKey(stripeSecretKey)
	chimp = gochimp.NewChimp(config.MailchimpKey, true)
	mandrill, _ = gochimp.NewMandrill(config.MandrillKey)
}
Ejemplo n.º 2
0
func main() {
	flag.BoolVar(&prod, "o", false, ":sync the MailChimp templates to the official account of Mandrill.")
	flag.Parse()

	start := time.Now()

	var config Config
	content, err := ioutil.ReadFile("config.json")
	if err != nil {
		panic(err)
	}
	if err = json.Unmarshal(content, &config); err != nil {
		panic(err)
	}
	fmt.Println(config)
	return

	key := config.MailChimp.APIKey
	if key == "" {
		log.Println("Please specify PROD_MAILCHIMP_KEY")
		os.Exit(1)
	}
	mailchimp := gochimp.NewChimp(key, true)

	var accounts []account
	if prod {
		log.Println("Updating Production Templates")
		accounts = append(accounts, config.Official)
	} else {
		log.Println("Updating Dev/Test Templates")
		accounts = config.Accounts
	}

	slugs := config.Slugs

	chimpList, err := mailchimp.TemplatesList(gochimp.TemplatesList{
		Types:   gochimp.TemplateListType{User: true, Gallery: true, Base: true},
		Filters: gochimp.TemplateListFilter{IncludeDragAndDrop: true},
	})
	if err != nil {
		panic(err)
	}

	for _, tmpl := range chimpList.User {
		slug, ok := slugs[tmpl.Name]
		if !ok {
			continue
		}
		log.Println("Slug:", slug)

		info, err := mailchimp.TemplatesInfo(gochimp.TemplateInfo{
			TemplateID: tmpl.Id,
			Type:       "user",
		})
		if err != nil {
			panic(err)
		}

		for _, account := range accounts {
			log.Println("Account:", account.Email)
			mandril, err := gochimp.NewMandrill(account.APIKey)
			if err != nil {
				panic(err)
			}

			var exists bool
			_, err = mandril.TemplateInfo(slug)
			if err != nil {
				if merr, ok := err.(gochimp.MandrillError); !ok && merr.Name != "Unknown_Template" {
					panic(err)
				}
			} else {
				exists = true
			}

			if exists {
				log.Println("Action: Update")
				_, err = mandril.TemplateUpdate(slug, info.Source, true)
			} else {
				log.Println("Action: Add")
				_, err = mandril.TemplateAdd(slug, info.Source, true)
			}
			if err != nil {
				panic(err)
			}
		}
	}
	log.Println("Took", time.Now().Sub(start))
}