2024-05-28 14:29:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-05-31 21:44:52 +00:00
|
|
|
"os"
|
2024-05-28 14:29:13 +00:00
|
|
|
"sevenkeys/database"
|
|
|
|
"sevenkeys/logic"
|
2024-05-29 19:55:38 +00:00
|
|
|
"sevenkeys/logic/scryfall"
|
2024-06-01 21:54:15 +00:00
|
|
|
|
|
|
|
"github.com/inancgumus/screen"
|
2024-05-28 14:29:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
db := database.GetDatabaseFromConfig("config.json")
|
|
|
|
|
2024-05-28 14:38:30 +00:00
|
|
|
fmt.Println("Checking for updates...")
|
2024-05-29 19:55:38 +00:00
|
|
|
bulkData, err := scryfall.GetBulkDataByType(scryfall.BulkDataTypeAllCards)
|
|
|
|
logic.Check(err)
|
|
|
|
|
|
|
|
needsUpdate, err := logic.CheckForUpdates(db, bulkData)
|
2024-05-28 14:29:13 +00:00
|
|
|
logic.Check(err)
|
|
|
|
|
|
|
|
if needsUpdate {
|
2024-05-28 14:38:30 +00:00
|
|
|
fmt.Println("Update required.")
|
2024-05-29 19:55:38 +00:00
|
|
|
|
2024-05-28 14:38:30 +00:00
|
|
|
if logic.ConfirmUpdate() {
|
2024-05-29 19:55:38 +00:00
|
|
|
fmt.Println("Running update...")
|
|
|
|
|
|
|
|
logic.CreateCacheDirectories()
|
|
|
|
|
|
|
|
err = logic.UpdateSets(db)
|
|
|
|
logic.Check(err)
|
|
|
|
|
|
|
|
err = logic.UpdateCards(db, bulkData)
|
|
|
|
logic.Check(err)
|
2024-05-28 14:38:30 +00:00
|
|
|
}
|
2024-05-29 19:55:38 +00:00
|
|
|
|
|
|
|
fmt.Println("Update finished.")
|
|
|
|
} else {
|
|
|
|
fmt.Println("No update required.")
|
2024-05-28 14:29:13 +00:00
|
|
|
}
|
2024-05-30 13:32:04 +00:00
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
storageBox := logic.GetResponse("Enter storage box label:")
|
|
|
|
source := logic.GetResponse("Enter source:")
|
2024-06-01 21:18:33 +00:00
|
|
|
|
|
|
|
storageLocation := database.CardStorageLocation{
|
|
|
|
StorageBox: storageBox,
|
|
|
|
Source: source,
|
|
|
|
}
|
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
searchOptions, err := logic.GetAllSearchOptions(db)
|
|
|
|
logic.Check(err)
|
2024-05-30 13:32:04 +00:00
|
|
|
|
2024-06-03 16:08:15 +00:00
|
|
|
var selectedCardId string
|
2024-06-01 21:18:33 +00:00
|
|
|
var selectedCardSearchOption string = "None"
|
2024-06-01 21:54:15 +00:00
|
|
|
var lastOutput string
|
2024-05-30 13:32:04 +00:00
|
|
|
for {
|
2024-06-01 21:54:15 +00:00
|
|
|
screen.Clear()
|
|
|
|
screen.MoveTopLeft()
|
2024-05-31 19:32:44 +00:00
|
|
|
|
2024-06-01 21:18:33 +00:00
|
|
|
fmt.Println("Storage location:", storageBox, "|", "Source:", source)
|
|
|
|
fmt.Println("Selected card:", selectedCardSearchOption, "ID:", selectedCardId)
|
2024-05-31 19:32:44 +00:00
|
|
|
|
2024-06-01 21:54:15 +00:00
|
|
|
if lastOutput != "" {
|
|
|
|
fmt.Println(lastOutput)
|
|
|
|
}
|
|
|
|
|
2024-06-01 21:18:33 +00:00
|
|
|
var action string
|
|
|
|
action = logic.GetResponse("[s]earch for card/[i]nsert selected card/[q]uit:")
|
|
|
|
switch action {
|
2024-05-31 19:32:44 +00:00
|
|
|
case "s":
|
2024-06-01 21:18:33 +00:00
|
|
|
selectedCardId, selectedCardSearchOption, err = logic.Search(searchOptions)
|
|
|
|
logic.Check(err)
|
|
|
|
|
|
|
|
storageLocation.CardPrintingId = selectedCardId
|
2024-06-01 21:54:15 +00:00
|
|
|
lastOutput = ""
|
2024-06-01 21:18:33 +00:00
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
continue
|
2024-06-01 21:18:33 +00:00
|
|
|
case "i":
|
2024-06-03 16:08:15 +00:00
|
|
|
if selectedCardId == "" {
|
2024-06-01 21:54:15 +00:00
|
|
|
lastOutput = "No selected card, please search for one."
|
2024-06-01 21:18:33 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
err = logic.StoreCard(db, storageLocation)
|
|
|
|
logic.Check(err)
|
2024-06-01 21:18:33 +00:00
|
|
|
|
2024-06-01 21:54:15 +00:00
|
|
|
lastOutput = "Inserted card: " + selectedCardSearchOption
|
|
|
|
|
2024-05-31 19:32:44 +00:00
|
|
|
break
|
2024-05-31 21:44:52 +00:00
|
|
|
case "q":
|
|
|
|
os.Exit(0)
|
2024-06-01 21:18:33 +00:00
|
|
|
default:
|
2024-06-01 21:54:15 +00:00
|
|
|
lastOutput = "Not a valid command: " + action
|
2024-06-01 21:18:33 +00:00
|
|
|
break
|
2024-05-31 19:32:44 +00:00
|
|
|
}
|
2024-05-30 13:32:04 +00:00
|
|
|
}
|
2024-05-28 14:29:13 +00:00
|
|
|
}
|