diff options
Diffstat (limited to 'funcs.go')
-rw-r--r-- | funcs.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/funcs.go b/funcs.go index 5ab913c..fbcd62d 100644 --- a/funcs.go +++ b/funcs.go @@ -6,6 +6,7 @@ import ( "log" "net/http" "os" + "strings" ) // downloadCategory downloads the given category from celestrack @@ -39,3 +40,28 @@ func downloadCategory(categoryName string) { fmt.Printf("Could not write to file data/%s.txt", categoryName) } } + +// dumpall dumps all the categories into the data folder +func dumpall() { + // read the name of the categories from the categories.txt file and write + // the result to the categories slice + content, err := ioutil.ReadFile("categories.txt") + if err != nil { + log.Printf("%s\n", "could not read categories.txt file!") + } + lines := strings.Split(string(content), "\n") + + for _, line := range lines { + if line != "" { + categories = append(categories, line) + } + } + + // download all the categories to the data/<category name> directory + for _, category := range categories { + fmt.Fprintf(w, "downloading %s... ", category) + log.Printf("downloading %s... ", category) + downloadCategory(category) + fmt.Fprintf(w, "done.\n") + } +} |