Example #1
0
func run(t *time.Time) error {
	// Make the image grid.
	m := make([][]image.Image, depth)
	for i := range m {
		m[i] = make([]image.Image, depth)
	}

	// Download images in parallel. Woo go!
	log.Println("Starting download...")
	startTime := time.Now()
	var wg sync.WaitGroup
	var err error
	for i := 0; i < depth; i++ {
		for j := 0; j < depth; j++ {
			wg.Add(1)
			go func(i, j int) {
				defer wg.Done()
				m[i][j], err = himawari.GridAt(t, depth, i, j)
			}(i, j)
		}
	}
	wg.Wait()
	log.Printf("Done! Downloading images took %s.\n", time.Now().Sub(startTime))

	// Join the pieces and set the background image.
	// A depth=20 crashed my VM around this part, so watch out.
	var img image.Image
	img = background.Join(m, gridSize*depth, gridSize*depth)
	img = background.Expand(img, 16/9) // FIXME

	log.Println("Setting image as background...")
	return background.Set(img)
}
Example #2
0
func main() {
	flag.Parse()

	// Set the satellite.
	var dl download.Downloader
	switch satellite {
	case "himawari":
		dl = download.Himawari{Depth: depth}
	case "dscovr":
		dl = download.Dscovr{}
	default:
		log.Fatalln("Satellite not recognized. Exiting.")
	}

	// Start off with a zero time.
	for lastTime := (time.Time{}); ; time.Sleep(every) {
		// Get the filename to the latest image.
		filename, err := dl.ModifiedSince(lastTime)
		if err != nil {
			log.Println(err)
			continue
		}
		if filename == "" {
			log.Println("No changes since last time. Trying again later...")
			continue
		}

		// There is new image out. Download it.
		log.Println("Starting download...")
		benchmarkTime := time.Now()
		img, err := dl.Download(filename)
		if err != nil {
			log.Println(err)
			continue
		}
		log.Printf("Done! Download took %s.\n", time.Now().Sub(benchmarkTime))

		// Set the image as the background.
		// This one's a serious error, so break if it happens.
		log.Println("Setting image as background...")
		if err := background.Set(img); err != nil {
			log.Println(err)
			break
		}

		// Success. Replace lastTime with the current time.
		lastTime = time.Now()

		// If we're only doing this once, quit.
		if every == 0 {
			break
		}
	}
}