Modify Makefile to use unified importer

This commit is contained in:
The Magician 2024-05-21 12:35:01 +01:00
parent 787794ac97
commit fd4c2048e1
2 changed files with 2 additions and 50 deletions

View File

@ -1,9 +1,7 @@
createdb:
mysql --user=root --password=$(shell pass show sevenkeys/mysql) <sql/createdb.sql
importsets: createdb
go run cmd/importsets/main.go
importcards: importsets
go run cmd/importcards/main.go
import: createdb
go run main.go
clean:
mysql --user=root --password=$(shell pass show sevenkeys/mysql) <sql/removedb.sql

View File

@ -1,46 +0,0 @@
package main
import (
"io"
"log"
"net/http"
"os"
"sevenkeys/database"
"sevenkeys/database/operations"
"sevenkeys/scryfall/methods"
)
func main() {
log.Println("Downloading set data from Scryfall...")
sets, err := methods.GetSets()
check(err)
log.Println("Downloaded set data.")
log.Println("Connecting to database...")
db := database.GetDatabaseFromConfig("config.json")
log.Println("Connected.")
for _, set := range sets {
// We're only interested in paper cards, so skip importing
// any sets that were only released in a video game
if set.Digital {
continue
}
log.Println("Importing set: " + set.Name)
err = operations.InsertOrUpdateSet(db, set)
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)
}
}