Move filesystem constants to main.go
This commit is contained in:
parent
a6463b0b25
commit
e98b0ec72f
|
@ -21,9 +21,6 @@ func check(err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CACHE_DIR string = "cache"
|
|
||||||
const ALL_CARDS_CACHE_FILENAME = CACHE_DIR + "/all-cards.json"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Printf("Getting bulk data listing...")
|
log.Printf("Getting bulk data listing...")
|
||||||
allCardsBulkData, err := methods.GetBulkDataByType(types.BulkDataTypeAllCards)
|
allCardsBulkData, err := methods.GetBulkDataByType(types.BulkDataTypeAllCards)
|
||||||
|
|
|
@ -1,28 +1,25 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
"sevenkeys/database"
|
"sevenkeys/database"
|
||||||
"sevenkeys/database/operations"
|
"sevenkeys/database/operations"
|
||||||
"sevenkeys/scryfall/methods"
|
"sevenkeys/scryfall/methods"
|
||||||
)
|
)
|
||||||
|
|
||||||
func check(err error) {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const CACHE_DIR string = "cache"
|
|
||||||
const ICON_CACHE_DIR string = CACHE_DIR + "/seticons/"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.Println("Downloading set data from Scryfall...")
|
||||||
sets, err := methods.GetSets()
|
sets, err := methods.GetSets()
|
||||||
check(err)
|
check(err)
|
||||||
|
log.Println("Downloaded set data.")
|
||||||
|
|
||||||
|
log.Println("Connecting to database...")
|
||||||
db := database.GetDatabaseFromConfig("config.json")
|
db := database.GetDatabaseFromConfig("config.json")
|
||||||
|
log.Println("Connected.")
|
||||||
|
|
||||||
// Download icon files to cache/ directory
|
|
||||||
for _, set := range sets {
|
for _, set := range sets {
|
||||||
// We're only interested in paper cards, so skip importing
|
// We're only interested in paper cards, so skip importing
|
||||||
// any sets that were only released in a video game
|
// any sets that were only released in a video game
|
||||||
|
@ -30,7 +27,20 @@ func main() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("Importing set: " + set.Name)
|
||||||
err = operations.InsertOrUpdateSet(db, set)
|
err = operations.InsertOrUpdateSet(db, set)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
response, err := http.Get(set.IconSvgUri)
|
||||||
|
log.Println("Downloading logo for set: " + set.Name)
|
||||||
|
defer response.Body.Close()
|
||||||
|
check(err)
|
||||||
|
|
||||||
|
iconFilename := ICON_CACHE_DIR + set.Code + FILE_EXTENSION_SVG
|
||||||
|
iconFile, err := os.Create(iconFilename)
|
||||||
|
check(err)
|
||||||
|
|
||||||
|
io.Copy(iconFile, response.Body)
|
||||||
|
log.Println("Finished importing set: " + set.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,13 @@ import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const CACHE_DIR string = "cache"
|
||||||
|
|
||||||
|
const SET_ICON_CACHE_DIR string = CACHE_DIR + "/seticons/"
|
||||||
|
const SET_ICON_FILE_EXTENSION string = ".svg"
|
||||||
|
|
||||||
|
const ALL_CARDS_CACHE_FILENAME = CACHE_DIR + "/all-cards.json"
|
||||||
|
|
||||||
func check(err error) {
|
func check(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue