<commit_before>// Copyright 2015 Blackhawk Network, Inc.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"code.google.com/p/go-uuid/uuid"
	"encoding/json"
	"flag"
	"html/template"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"regexp"
	"github.com/musicbeat/chimpathon/chimpmail"
)

var (
	addr = flag.Bool("addr", false, "find open address and print to final-port.txt")
)

type Order struct {
	Title              string
	OrderNumber        string
	ProductId          string
	ProductDescription string
	FaceValue          string
	ToEmail            string
	EGiftId           string
}

func (o *Order) save() error {
	// save the order
	filename := o.Title + ".txt"
	j, err := json.MarshalIndent(o, "", "  ")
	if err != nil {
		log.Fatal(err)
	}
	// do something to email the order

	err = chimpmail.SendTemplate("Happy Birthday", o.EGiftId, o.ToEmail, "Darden")

	if err != nil {
		log.Fatal(err)
	}

	return ioutil.WriteFile(filename, j, 0600)
}

func loadOrder(title string) (*Order, error) {
	filename := title + ".txt"
	var order Order
	b, err := ioutil.ReadFile(filename)
	if err != nil {
		return &order, err
	}
	err = json.Unmarshal(b, &order)
	if err != nil {
		log.Fatal(err)
	}
	return &order, nil
}

func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
	o, err := loadOrder(title)
	if err != nil {
		http.Redirect(w, r, "/edit/"+template.HTMLEscapeString(title), http.StatusFound)
		return
	}
	renderTemplate(w, "view", o)
}

func editHandler(w http.ResponseWriter, r *http.Request, title string) {
	o, err := loadOrder(title)
	if err != nil {
		uuid := template.HTMLEscapeString(uuid.NewRandom().String())
		eGiftId := "https://egift.io/" + uuid
		o = &Order{Title: uuid, OrderNumber: uuid, EGiftId: eGiftId}<commit_msg>=some more changes<commit_after>// Copyright 2015 Blackhawk Network, Inc.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"code.google.com/p/go-uuid/uuid"
	"encoding/json"
	"flag"
	"html/template"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"regexp"
	"github.com/musicbeat/chimpathon/chimpmail"
)

var (
	addr = flag.Bool("addr", false, "find open address and print to final-port.txt")
)

type Order struct {
	Title              string
	OrderNumber        string
	ProductId          string
	ProductDescription string
	FaceValue          string
	ToEmail            string
	EGiftId           string
}

func (o *Order) save() error {
	// save the order
	filename := o.Title + ".txt"
	j, err := json.MarshalIndent(o, "", "  ")
	if err != nil {
		log.Fatal(err)
	}
	// do something to email the order

	err = chimpmail.SendTemplate("Happy Birthday", o.EGiftId, o.ToEmail, "Darden")

	if err != nil {
		log.Fatal(err)
	}

	return ioutil.WriteFile(filename, j, 0600)
}

func loadOrder(title string) (*Order, error) {
	filename := title + ".txt"
	var order Order
	b, err := ioutil.ReadFile(filename)
	if err != nil {
		return &order, err
	}
	err = json.Unmarshal(b, &order)
	if err != nil {
		log.Fatal(err)
	}
	return &order, nil
}

func viewHandler(w http.ResponseWriter, r *http.Request, title string) {
	o, err := loadOrder(title)
	if err != nil {
		http.Redirect(w, r, "/edit/"+template.HTMLEscapeString(title), http.StatusFound)
		return
	}
	renderTemplate(w, "view", o)
}

func editHandler(w http.ResponseWriter, r *http.Request, title string) {
	o, err := loadOrder(title)
	if err != nil {
		uuid := template.HTMLEscapeString(uuid.NewRandom().String())
		eGiftId := uuid
		o = &Order{Title: uuid, OrderNumber: uuid, EGiftId: eGiftId}
{'fraction_non_alphanumeric': 0.1372009898267803, 'fraction_numerical': 0.004399230134726423, 'mean_word_length': 3.3258026159334126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3179065', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1306, 'n_words': 360}