93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sevenkeys/database"
|
|
"sevenkeys/logic"
|
|
"sevenkeys/logic/scryfall"
|
|
)
|
|
|
|
func main() {
|
|
db := database.GetDatabaseFromConfig("config.json")
|
|
|
|
fmt.Println("Checking for updates...")
|
|
bulkData, err := scryfall.GetBulkDataByType(scryfall.BulkDataTypeAllCards)
|
|
logic.Check(err)
|
|
|
|
needsUpdate, err := logic.CheckForUpdates(db, bulkData)
|
|
logic.Check(err)
|
|
|
|
if needsUpdate {
|
|
fmt.Println("Update required.")
|
|
|
|
if logic.ConfirmUpdate() {
|
|
fmt.Println("Running update...")
|
|
|
|
logic.CreateCacheDirectories()
|
|
|
|
err = logic.UpdateSets(db)
|
|
logic.Check(err)
|
|
|
|
err = logic.UpdateCards(db, bulkData)
|
|
logic.Check(err)
|
|
}
|
|
|
|
fmt.Println("Update finished.")
|
|
} else {
|
|
fmt.Println("No update required.")
|
|
}
|
|
|
|
storageBox := logic.GetResponse("Enter storage box label:")
|
|
source := logic.GetResponse("Enter source:")
|
|
|
|
storageLocation := database.CardStorageLocation{
|
|
StorageBox: storageBox,
|
|
Source: source,
|
|
}
|
|
|
|
searchOptions, err := logic.GetAllSearchOptions(db)
|
|
logic.Check(err)
|
|
|
|
var selectedCardId int
|
|
var selectedCardSearchOption string = "None"
|
|
for {
|
|
/*
|
|
screen.Clear()
|
|
screen.MoveTopLeft()
|
|
*/
|
|
|
|
fmt.Println("Storage location:", storageBox, "|", "Source:", source)
|
|
fmt.Println("Selected card:", selectedCardSearchOption, "ID:", selectedCardId)
|
|
|
|
var action string
|
|
action = logic.GetResponse("[s]earch for card/[i]nsert selected card/[q]uit:")
|
|
switch action {
|
|
case "s":
|
|
selectedCardId, selectedCardSearchOption, err = logic.Search(searchOptions)
|
|
logic.Check(err)
|
|
|
|
storageLocation.CardPrintingId = selectedCardId
|
|
|
|
continue
|
|
case "i":
|
|
if selectedCardId == 0 {
|
|
fmt.Println("No selected card, please search for one.")
|
|
continue
|
|
}
|
|
|
|
err = logic.StoreCard(db, storageLocation)
|
|
logic.Check(err)
|
|
|
|
break
|
|
case "q":
|
|
os.Exit(0)
|
|
default:
|
|
fmt.Println("Not a valid command:", action)
|
|
break
|
|
}
|
|
|
|
fmt.Print("\n\n")
|
|
}
|
|
}
|