Пример #1
0
func main() {
	app.Action = func(c *cli.Context) {
		api := wolfram.NewApi(c.String("key"), "Russia")
		res, err := api.Query(c.Args().First())
		if err != nil {
			log.Fatalln(err)
		}
		if len(res.Pods) < 2 || len(res.Pods[1].SubPods) < 1 {
			log.Fatalln("wolfram: unable to compute any result")
		}
		fmt.Println(res.Pods[1].SubPods[0].Plaintext)
	}
	if err := app.Run(os.Args); err != nil {
		log.Fatalln(err)
	}
}
Пример #2
0
func NewMessageHandler(cfg *handlerConfig) (h *MessageHandler, err error) {
	h = &MessageHandler{
		wikiApi: wikipedia.NewApi(),
		wolfApi: wolfram.NewApi(cfg.Credentials.WolframPrivateKey, originCountry),
		smsApi:  smsru.NewApi(cfg.Credentials.SmsruPrivateKey),
	}
	if h.googlApi, err = googl.NewShortener(
		cfg.Credentials.GoogleClientEmail,
		[]byte(cfg.Credentials.GooglePrivateKey),
	); err != nil {
		return
	}
	if h.db, err = gorm.Open("postgres", cfg.DbCfg.DataSourceName()); err != nil {
		return nil, err
	}
	if err = h.db.AutoMigrate(Request{}).Error; err != nil {
		return nil, err
	}
	if h.stats, err = nsq.NewProducer(cfg.NsqAddr, cfg.NsqCfg); err != nil {
		return nil, err
	}
	return
}