// Create a New Instagram Connection
func NewInstagramConnection(client_id, tag string) *InstagramConnection {
	var returned InstagramConnection
	value := instagram.NewClient(nil)
	value.ClientID = client_id
	returned.Client = *value
	returned.Channel = make(chan image.Image)
	returned.Tag = tag
	returned.Started = false
	returned.Ticker = time.NewTicker(time.Second * 5)
	returned.MaxID = nil
	return &returned
}
Example #2
0
func BuildBot(token string, workers int, youtubeurl string, instaid string, slideapi string, slidesecret string) *tgbot.TgBot {
	youtubedl = youtubeurl
	slideshareclient = &slideshare.Service{slideapi, slidesecret}
	instaclient = instagram.NewClient(nil)
	instaclient.ClientID = instaid
	get_all_domains_available()
	StartDispatcher(workers)
	setupSignalHandler()

	// fmt.Println("Start upstream test")
	// cfg, err := stdn.GetConfig()
	// if err == nil && len(cfg.Servers) > 0 {
	// 	for i, s := range cfg.Servers {
	// 		fmt.Println("Testing server", i)
	// 		bps, err := s.Upstream(3)
	// 		if err == nil {
	// 			bpsspeed = bps
	// 			fmt.Println("Founded speed!", bps)
	// 			break
	// 		}
	// 	}
	// }
	// fmt.Println("Finished upstream test")

	bot := tgbot.New(token).
		AnyMsgFn(func(bot tgbot.TgBot, msg tgbot.Message) {
			m := fmt.Sprintf("<%d", msg.From.ID)
			if msg.From.Username != nil {
				m = fmt.Sprintf("%s(%s)", m, *msg.From.Username)
			}
			m = fmt.Sprintf("%s>:", m)
			if msg.Text != nil {
				m = fmt.Sprintf("%s %s", m, *msg.Text)
			}
			log.Println(m)
		}).
		SimpleCommandFn(`help`, help).
		SimpleCommandFn(`supported`, supported).
		SimpleCommandFn(`start`, help).
		SimpleCommandFn(`about`, about).
		SimpleCommandFn(`contact`, contact).
		SimpleCommandFn(`googleformats`, googleformats).
		MultiRegexFn([]string{
			`^([^/]\S+)$`,
			`^([^/]\S+) (audio|video)$`,
			`^([^/]\S+) (format) (doc|pdf|txt|html|odt|pptx|xlsx)$`,
			`^([^/]\S+) ([a-zA-Z0-9_-]+\..+)$`,
		}, down)
	return bot
}
Example #3
0
func getTopImgInstagram() {
	instagram_client := instagram.NewClient(nil)
	instagram_client.ClientID = botData.InstaID
	//opt := &instagram.Parameters{Count: 1}
	for {
		for msg := range instagram_req {
			media, _, err := instagram_client.Media.Popular() //Tags.RecentMedia("instasky", opt) //.Media.Popular()
			if err != nil {
				log.Println(err)
				continue
			}
			if len(media) > 0 {
				instagram_res <- InstagramResponse{media[0].Link, msg}
			}
		}
	}
}
Example #4
0
func main() {

	client := instagram.NewClient(nil)
	client.ClientID = "8f2c0ad697ea4094beb2b1753b7cde9c"
	// If you have access_token you can supply it
	// client.AccessToken = ""

	media, next, err := client.Media.Popular()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
	}
	for _, m := range media {
		fmt.Printf("ID: %v, Type: %v\n", m.ID, m.Type)
	}
	if next.NextURL != "" {
		fmt.Println("Next URL", next.NextURL)
	}
}
Example #5
0
func (in *InstagramStream) Create() {
	in.client = instagram.NewClient(nil)
	in.client.ClientID = in.config.InstagramConfig.ClientID
	in.client.ClientSecret = in.config.InstagramConfig.ClientSecret
	in.client.AccessToken = in.config.InstagramConfig.AccessToken
}
Example #6
0
func NewPic(w http.ResponseWriter, req *http.Request) {
	m, _ := url.ParseQuery(req.URL.RawQuery)
	c := appengine.NewContext(req)
	if m["hub.challenge"] != nil {
		io.WriteString(w, m["hub.challenge"][0])
		return
	}
	bod, _ := ioutil.ReadAll(req.Body)
	var resp []instagram.RealtimeResponse
	err := json.Unmarshal(bod, &resp)
	//	w.Header().Set("content-type", "application/json")
	if err != nil {
		json.NewEncoder(w).Encode(err.Error())
	}
	counter++
	if counter == 10 {
		counter = 0
	} else {
		return
	}
	cli := urlfetch.Client(c)
	resp2, err := cli.Get("https://script.google.com/macros/s/AKfycbz9_kR9I1FOE00v7pXJaaFuyXSDS-CFjRDJDM8UemnojyI3ua0/exec")
	if err != nil {
		json.NewEncoder(w).Encode(err.Error())
	}
	defer resp2.Body.Close()
	contents, err := ioutil.ReadAll(resp2.Body)
	response2 := strings.Split(string(contents), "|")
	client := instagram.NewClient(cli)
	client.ClientID = response2[0]
	client.ClientSecret = response2[1]
	res, _, err := client.Tags.RecentMedia(resp[0].ObjectID, nil)
	if err == nil {
		i := 0
		for i < len(res) {
			v := res[i]
			i++
			item, err := memcache.Get(c, "last")
			url := v.Images.StandardResolution.URL
			if err == nil && string(item.Value) == url {
				break
			}
			q := datastore.NewQuery("image").Filter("Link =", url)
			var link []models.Image
			q.GetAll(c, &link)
			if len(link) != 0 {
				break
			}
			rgb, err := util.PixColor(url, c)
			if err != nil {
				json.NewEncoder(w).Encode(err.Error())
			}
			err = controllers.AddImage(url, rgb, c)
			if err != nil {
				json.NewEncoder(w).Encode(err.Error())
			}
		}
	} else {
		json.NewEncoder(w).Encode(err.Error())
	}
	cache := &memcache.Item{
		Key:   "last",
		Value: []byte(res[0].Images.StandardResolution.URL),
	}
	if err := memcache.Add(c, cache); err != nil {
		memcache.Set(c, cache)
	}
}