Exemplo n.º 1
0
func (i *thumbInventory) AddTag(tag string) chan bool {
	i.mu.Lock()
	defer i.mu.Unlock()

	// Initialize the inventory.
	if _, ok := i.images[tag]; !ok {
		cache := i.tagCacheFunc(tag)
		i.images[tag] = mosaic.NewImageInventory(cache)

	}
	inv := i.images[tag]

	// Initialize the state.
	if ch, ok := i.states[tag]; ok {
		log.Printf("AddTag(%s) already has it\n", tag)
		return ch
	}
	i.states[tag] = make(chan bool)

	log.Printf("AddTag(%s) beginning fetch\n", tag)
	go func() {
		fetcher := instagram.NewTagFetcher(i.api, tag)
		if err := inv.Fetch(fetcher, ImagesPerTag); err != nil {
			log.Printf("Failed to fetch tag %s: %s", tag, err)
		}
		close(i.states[tag])
	}()

	return i.states[tag]
}
Exemplo n.º 2
0
func downloadImages(tag string, numImages int, inv *mosaic.ImageInventory) error {
	api := instagram.NewClient()
	fetcher := instagram.NewTagFetcher(api, tag)
	if err := inv.Fetch(fetcher, numImages); err != nil {
		return err
	}
	time.Sleep(1 * time.Second)
	return nil
}