add update structure
This commit is contained in:
parent
c93cde3c7c
commit
b921536ce8
4
serra.go
4
serra.go
@ -36,4 +36,8 @@ Options:
|
||||
serra.Sets()
|
||||
}
|
||||
|
||||
if args["update"].(bool) {
|
||||
serra.Update()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -124,7 +124,6 @@ type PriceEntry struct {
|
||||
}
|
||||
|
||||
func fetch_card(path string) (*Card, error) {
|
||||
|
||||
// TODO better URL Building...
|
||||
resp, err := http.Get(fmt.Sprintf("https://api.scryfall.com/cards/%s/", path))
|
||||
if err != nil {
|
||||
|
||||
@ -19,7 +19,6 @@ func Add(cards []string) {
|
||||
|
||||
// Loop over different cards
|
||||
for _, card := range cards {
|
||||
|
||||
// Fetch card from scryfall
|
||||
c, err := fetch_card(card)
|
||||
if err != nil {
|
||||
@ -45,7 +44,11 @@ func Cards() {
|
||||
|
||||
client := storage_connect()
|
||||
coll := client.Database("serra").Collection("cards")
|
||||
cards, _ := storage_find(coll)
|
||||
|
||||
sort := bson.D{{"collectornumber", 1}}
|
||||
filter := bson.D{{}}
|
||||
cards, _ := storage_find(coll, filter, sort)
|
||||
|
||||
for _, card := range cards {
|
||||
fmt.Printf("%s (%s) %.2f\n", card.Name, card.Set, card.Prices.Eur)
|
||||
}
|
||||
@ -74,3 +77,20 @@ func Sets() {
|
||||
storage_disconnect(client)
|
||||
|
||||
}
|
||||
|
||||
func Update() {
|
||||
LogMessage(fmt.Sprintf("Serra %v\n", version), "green")
|
||||
|
||||
client := storage_connect()
|
||||
coll := client.Database("serra").Collection("cards")
|
||||
|
||||
sort := bson.D{{"_id", 1}}
|
||||
filter := bson.D{{"_id", "0d4f3c1d-d25e-4263-ab2b-19534c852678"}}
|
||||
cards, _ := storage_find(coll, filter, sort)
|
||||
|
||||
for _, card := range cards {
|
||||
fmt.Printf("%s (%s) %.2f\n", card.Name, card.Set, card.Prices.Eur)
|
||||
}
|
||||
|
||||
storage_disconnect(client)
|
||||
}
|
||||
|
||||
@ -37,10 +37,10 @@ func storage_add(coll *mongo.Collection, card *Card) error {
|
||||
|
||||
}
|
||||
|
||||
func storage_find(coll *mongo.Collection) ([]Card, error) {
|
||||
func storage_find(coll *mongo.Collection, filter, sort bson.D) ([]Card, error) {
|
||||
|
||||
opts := options.Find().SetSort(bson.D{{"collectornumber", 1}})
|
||||
cursor, err := coll.Find(context.TODO(), bson.D{{}}, opts)
|
||||
opts := options.Find().SetSort(sort)
|
||||
cursor, err := coll.Find(context.TODO(), filter, opts)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user