-
Notifications
You must be signed in to change notification settings - Fork 0
/
geobird.go
68 lines (57 loc) · 1.4 KB
/
geobird.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* The G - O Bird: a bird's-eye look at the geoid.
Geobird is a tool for batch-downloading images from Nasa's earthdata.
*/
package main
import (
"fmt"
"net/url"
"os"
)
func main() {
// Work out the opts and choose images
options := parseCommandLineArguments()
imageSet := prepImageSet(options)
// Construct urls to fetch, and paths to save
iChannel := make(chan Image)
go imageSet.getImages(iChannel)
// Fetch urls and save as files
var iURL url.URL
var err error
// dryErr := errors.New("we're only pretending")
var exists bool
for img := range iChannel {
// arrange URL and file paths
iURL = img.getImageURL()
iDir, iName := img.getImagePath()
// Check if the file already exists
_, err = os.Stat(iDir + iName)
exists = !os.IsNotExist(err)
// verbosity
switch options.verbosity {
case 1:
if !exists {
fmt.Println("Producing", iDir+iName)
}
case 2:
fmt.Println("getting", iURL.String())
fmt.Println("and putting at", iDir+iName)
if exists {
fmt.Println("...but it's already there")
}
if options.dryRun {
fmt.Println("...but we're only pretending")
}
}
// If it's not already there, and we're not a dry-run,
// do that funky stuff!
if !exists && !options.dryRun {
err = getAndSaveImage(iURL.String(), iDir, iName)
if err != nil {
fmt.Println("however...", err, "\n")
}
}
}
if options.verbosity > 0 {
fmt.Println("birdy!")
}
}