예제 #1
0
func res(w http.ResponseWriter, r *http.Request) {

	// get the keys either from config file
	options, err := getOptions(w)
	if err != nil {
		fmt.Println(err)
		io.WriteString(w, fmt.Sprintf("ERROR: %v", err))
	}

	// google app engine requires it's own class for making http requests
	c := appengine.NewContext(r)
	httpClient := urlfetch.Client(c)

	// create a new yelp client with the auth keys and the custom http client
	client := yelp.New(options, httpClient)

	// make a simple query
	term := r.URL.Query().Get("term")
	location := r.URL.Query().Get("location")

	// call the yelp API
	results, err := client.DoSimpleSearch(term, location)
	if err != nil {
		fmt.Println(err)
		io.WriteString(w, fmt.Sprintf("ERROR: %v", err))
	}

	// print the results
	io.WriteString(w, fmt.Sprintf("<div>Found a total of %v results for \"%v\" in \"%v\".</div>", results.Total, term, location))
	io.WriteString(w, "<div>-----------------------------</div>")
	for i := 0; i < len(results.Businesses); i++ {
		io.WriteString(w, fmt.Sprintf("<div>%v, %v</div>", results.Businesses[i].Name, results.Businesses[i].Rating))
	}
}
예제 #2
0
func res(w http.ResponseWriter, r *http.Request) {

	// get the keys either from config file
	options, err := getOptions(w)
	if err != nil {
		fmt.Println(err)
	}

	// create a new yelp client with the auth keys
	client := yelp.New(options, nil)

	// make a simple query
	term := r.URL.Query().Get("term")
	location := r.URL.Query().Get("location")
	results, err := client.DoSimpleSearch(term, location)
	if err != nil {
		fmt.Println(err)
	}

	// print the results
	io.WriteString(w, fmt.Sprintf("<div>Found a total of %v results for \"%v\" in \"%v\".</div>", results.Total, term, location))
	io.WriteString(w, "<div>-----------------------------</div>")
	for i := 0; i < len(results.Businesses); i++ {
		io.WriteString(w, fmt.Sprintf("<div>%v, %v</div>", results.Businesses[i].Name, results.Businesses[i].Rating))
	}
}
예제 #3
0
func findYelp(api *telegram.Api, term string, location string) {
	m := make(map[string]string)
	m["chat_id"] = "-28394494"
	m["text"] = fmt.Sprintf("Moonvuibot finds you some %s  shop near %s", term, location)
	message, _ := api.SendMessage(m)
	fmt.Println("MMM = ", message)

	o := &yelp.AuthOptions{
		ConsumerKey:       os.Getenv("YELP_CONSUMER_KEY"),
		ConsumerSecret:    os.Getenv("YELP_CONSUMER_SECRET"),
		AccessToken:       os.Getenv("YELP_TOKEN"),
		AccessTokenSecret: os.Getenv("YELP_TOKEN_SECRET"),
	}
	yelpClient := yelp.New(o, nil)
	results, err := yelpClient.DoSimpleSearch(term, location)
	if err != nil {
		fmt.Println(err)
	}
	m["text"] = fmt.Sprintf("Found a total of %v results for \"%v\" in \"%v\". \n===\n", results.Total, term, location)
	for _, business := range results.Businesses {
		m["text"] = m["text"] + fmt.Sprintf("\n %v, rate: %v\n\n", business.Name, business.Rating)
	}
	api.SendMessage(m)

}
예제 #4
0
func main() {

	// get the keys either from config file
	var o yelp.AuthOptions
	data, err := ioutil.ReadFile("../../config.json")
	if err != nil {
		panic(err)
	}
	err = json.Unmarshal(data, &o)
	if err != nil {
		panic(err)
	}

	// create a new yelp client with the auth keys
	client := yelp.New(&o, nil)

	// make a simple query
	term := os.Args[1]
	location := os.Args[2]
	results, err := client.DoSimpleSearch(term, location)
	if err != nil {
		panic(err)
	}

	// print the results
	fmt.Printf("\nFound a total of %v results for \"%v\" in \"%v\".\n", results.Total, term, location)
	fmt.Println("-----------------------------")
	for i := 0; i < len(results.Businesses); i++ {
		fmt.Printf("%v\t\t%v\n", results.Businesses[i].Name, results.Businesses[i].Rating)
	}
}