示例#1
0
func setupApplication(t *testing.T) *Application {
	log.SetFlags(log.Ltime | log.Ldate | log.Lshortfile)
	spApp := env.String("STORMPATH_APP")
	apiId := env.String("STORMPATH_API_ID")
	apiSecret := env.String("STORMPATH_API_SECRET")
	s := Application{
		Href:      spApp,
		ApiId:     apiId,
		ApiSecret: apiSecret,
	}
	return &s
}
示例#2
0
func (s *S) TestStrings(c *C) {
	c.Assert(func() { env.String("DOESNT_EXIST") }, Panics, errors.New("env: Environment variable DOESNT_EXIST doesn't exist"))

	os.Setenv("test", "gocheck")
	test := map[string]string{
		env.String("test"):                                               "gocheck",
		env.StringDefault("foobar", "fizzbin"):                           "fizzbin",
		env.StringDefaultF("foobar", func() string { return "fizzbot" }): "fizzbot",
	}

	for obtained, expected := range test {
		c.Assert(obtained, Equals, expected)
	}
}
示例#3
0
func initBuffer() (buffer *bufferapi.Client) {
	authToken := env.String("BUFFER_AUTH_TOKEN")
	clientId := env.String("BUFFER_CLIENT_ID")
	clientSecret := env.String("BUFFER_CLIENT_SECRET")
	bufferConfig := &oauth.Config{
		ClientId:     clientId,
		ClientSecret: clientSecret,
		Scope:        "",
		AuthURL:      "",
		TokenURL:     "",
		TokenCache:   oauth.CacheFile(""),
	}
	transport := &oauth.Transport{Config: bufferConfig}
	buffer = bufferapi.ClientFactory(authToken, transport)
	return
}
示例#4
0
func setup(t *testing.T) *Heroku {
	log.SetFlags(log.Lshortfile)
	key := env.String("HEROKU_TEST_API_KEY")
	h := NewHeroku(key)
	h.rc.Log = false
	return h
}
// Greeting returns a pleasant, semi-useful greeting.
func Greeting() string {
	msg := "Hello world, the time is "
	msg += time.Now().String()
	msg += " and your PATH is "
	msg += env.String("PATH")
	return msg
}
示例#6
0
文件: main.go 项目: jmcvetta/blocker
func main() {
	// Gather configuration from environment
	port := env.StringDefault("PORT", "8080")
	pwd := env.String("PWD")
	dbDir := env.StringDefault("DB_DIR", pwd+"/db")

	// Start the service
	setupDb(dbDir)
	fmt.Printf("Starting server on localhost:%v\n", port)
	log.Fatal(http.ListenAndServe(":"+port, muxer()))
}
示例#7
0
func init() {
	redis := env.StringDefault("REDISCLOUD_URL", env.StringDefault("REDIS_PORT", ""))
	if redis != "" {
		cache.SetupRedis(redis, env.StringDefault("REDIS_OPTIONS", "timeout=15s&maxidle=1"))
	}

	rdbToken := env.String("READABILITY_TOKEN")
	pmToken := env.String("POSTMARK_TOKEN")
	from := env.String("FROM")
	binary, _ := exec.LookPath(fmt.Sprintf("kindlegen-%s", runtime.GOOS))

	tlogger := log.New(os.Stdout, "[tinderizer] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))

	app = tinderizer.New(rdbToken, pmToken, from, binary, tlogger)
	app.Run(QueueSize)

	// TODO: handle SIGINT
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
	go shutdown(c)
}
示例#8
0
func init() {
	goEnv = env.String("GO_ENV")

	host := env.String(goEnv + "_POSTGRES_HOST")
	database := env.String(goEnv + "_POSTGRES_DB")
	user := env.String(goEnv + "_POSTGRES_USER")
	port := env.String(goEnv + "_POSTGRES_PORT")
	password := env.String(goEnv + "_POSTGRES_PASSWORD")
	ssl := env.String(goEnv + "_POSTGRES_SSL")
	connectionInfo := fmt.Sprintf("dbname=%s user=%s password=%s host=%s port=%s sslmode=%s", database, user, password, host, port, ssl)
	db, err := sql.Open("postgres", connectionInfo)
	if err != nil {
		log.Fatalf("%+v", err)
	}
	dbmap = &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
	table := dbmap.AddTable(Vote{}).SetKeys(true, "Id")
	table.ColMap("DescriptionEnglish").SetMaxSize(2048)
	table.ColMap("DescriptionFrench").SetMaxSize(2048)
	dbmap.CreateTables()
}
示例#9
0
	"strings"
	"sync"
	"time"
)

const (
	FriendlyMessage = "Sorry, extraction failed."
	RetryTimes      = 3
	RetryPause      = 3 * time.Second
)

type JSON map[string]interface{}

var (
	timeout = 5 * time.Second
	token   = env.String("READABILITY_TOKEN")
	logger  = log.New(os.Stdout, "[extractor] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
	rdb     = readability.New(token, logger)
)

type Extractor struct {
	rdb    *readability.Endpoint
	wg     sync.WaitGroup
	Input  <-chan J.Job
	Output chan<- J.Job
	Error  chan<- J.Job
}

func New(rdb *readability.Endpoint, input <-chan J.Job, output chan<- J.Job, error chan<- J.Job) *Extractor {
	return &Extractor{
		rdb:    rdb,
示例#10
0
func main() {
	setup()

	latestVotes, err := votes.FetchLatestVotes()
	if err != nil {
		log.Printf("%+v", err)
	}

	wordsToTranslate := []string{}
	for _, vote := range latestVotes {
		firstWord := strings.Split(vote.DescriptionEnglish, " ")[0]
		wordsToTranslate = append(wordsToTranslate, firstWord)
	}

	translateConfig := translate.Config{
		GrantType:    "client_credentials",
		ScopeUrl:     "http://api.microsofttranslator.com",
		ClientId:     env.String("BING_CLIENT_ID"),
		ClientSecret: env.String("BING_CLIENT_SECRET"),
		AuthUrl:      "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/",
	}
	token, err := translate.GetToken(&translateConfig)
	if err != nil {
		log.Printf("%v", err)
	}
	translatedWords, err := token.TranslateArray(wordsToTranslate, "", "fr")
	if err != nil {
		log.Printf("%v", err)
	}
	for index, word := range translatedWords {
		switch word {
		case "Assentiment":
			translatedWords[index] = "Adoption"
		case "2ème":
			translatedWords[index] = "2e"
		case "Privé":
			translatedWords[index] = "Affaires"
		case "Temps":
			translatedWords[index] = "Attribution"
		}
	}
	if len(latestVotes) > 0 {
		log.Printf("%+v", wordsToTranslate)
		log.Printf("%+v", translatedWords)
	}

	for index, vote := range latestVotes {
		splitIndex := strings.LastIndex(vote.DescriptionEnglish, translatedWords[index])
		if splitIndex < 0 {
			splitIndex = len(vote.DescriptionEnglish) - 1
		}
		log.Printf("whole: %v", vote.DescriptionEnglish)
		english := strings.Join(strings.Split(vote.DescriptionEnglish, "")[0:splitIndex], "")
		log.Printf("en: %v", english)
		french := strings.Join(strings.Split(vote.DescriptionEnglish, "")[splitIndex:], "")
		log.Printf("fr: %v", french)
		latestVotes[index].DescriptionEnglish = english
		latestVotes[index].DescriptionFrench = french
	}

	// Insert oldest votes first
	latestVotes.Reverse()
	votes.InsertVotes(latestVotes)
	log.Printf("[worker] Inserted %d rows", len(latestVotes))

	// Push new votes to Buffer, oldest first
	buffer := initBuffer()
	profiles, err := buffer.Profiles()
	if err != nil {
		log.Printf("%v", err)
	}

	bufferCount := 0
	for _, vote := range latestVotes {
		u := bufferapi.NewUpdate{Text: vote.ShortDescription() + " " + vote.Link(),
			Media:      map[string]string{"link": vote.Link()},
			ProfileIds: []string{(*profiles)[0].Id},
			Shorten:    true,
			Now:        false}
		_, err := buffer.Update(&u)
		if err != nil {
			log.Printf("%v", err)
		} else {
			bufferCount++
		}
	}
	log.Printf("[worker] Pushed %d tweets to Buffer", bufferCount)

	latestTenVotes, err := votes.LatestTenVotes()
	if err != nil {
		log.Printf("%+v", err)
	}

	// Render JSON file
	j := JSONFeed{Title: "Today's Vote", Link: "http://www.todaysvote.ca", Description: "Stay up to date with what Canada's House of Commons is voting on each day.", Items: latestTenVotes}
	err = renderJSON("feed", j)
	if err != nil {
		log.Printf("%v", err)
	}
	log.Println("[worker] Rendered JSON feed")

	// Write feed to RSS file
	c := moverss.ChannelFactory("Today's Vote", "http://www.todaysvote.ca", "Stay up to date with what Canada's House of Commons is voting on each day.")
	err = renderRSS("feed", c, latestTenVotes)
	if err != nil {
		log.Printf("%v", err)
	}
	log.Println("[worker] Rendered RSS feed")

	// Render index.html
	err = renderHTML("index", latestTenVotes)
	if err != nil {
		log.Printf("%v", err)
	}
	log.Println("[worker] Rendered HTML page")
}
示例#11
0
	"github.com/darkhelmet/tinderizer/hashie"
	J "github.com/darkhelmet/tinderizer/job"
	"golang.org/x/net/html"
)

const (
	FriendlyMessage = "Sorry, extraction failed."
	RetryTimes      = 3
	RetryPause      = 3 * time.Second
)

type JSON map[string]interface{}

var (
	timeout = 5 * time.Second
	token   = env.String("MERCURY_TOKEN")
	logger  = log.New(os.Stdout, "[extractor] ", env.IntDefault("LOG_FLAGS", log.LstdFlags|log.Lmicroseconds))
	merc    = mercury.New(token, logger)
)

type Extractor struct {
	merc   *mercury.Endpoint
	wg     sync.WaitGroup
	Input  <-chan J.Job
	Output chan<- J.Job
	Error  chan<- J.Job
}

func New(merc *mercury.Endpoint, input <-chan J.Job, output chan<- J.Job, error chan<- J.Job) *Extractor {
	return &Extractor{
		merc:   merc,