From a7b5f6de1427cc1960592fe9bdcf40907fd4934b Mon Sep 17 00:00:00 2001 From: Nulo Date: Tue, 9 Nov 2021 19:32:48 -0300 Subject: [PATCH] Mostrar algunos NFTs copiados en index --- index.tmpl | 8 ++++++++ main.go | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/index.tmpl b/index.tmpl index ea0248c..ceca976 100644 --- a/index.tmpl +++ b/index.tmpl @@ -12,3 +12,11 @@

Inspirado en Kopimashin de brokep.

Kopimi

+
+

Algunos NFTs descargados

+ {{range .NFTs}} + + + + {{end}} +
diff --git a/main.go b/main.go index 4eafe2b..ec09343 100644 --- a/main.go +++ b/main.go @@ -7,16 +7,19 @@ import ( "io" "io/fs" "log" + "math/rand" "net/http" "os" "path" "path/filepath" "strings" + "time" ) type Status struct { NFTNum int TotalUSDValue float64 + NFTs []string } const NFTS_DIR = "./nfts" @@ -41,6 +44,10 @@ func getStatus() (Status, error) { return status, err } + // https://yourbasic.org/golang/shuffle-slice-array/ + rand.Seed(time.Now().UnixNano()) + rand.Shuffle(len(entries), func(i, j int) { entries[i], entries[j] = entries[j], entries[i] }) + for _, val := range entries { info, err := val.Info() if err != nil { @@ -50,11 +57,16 @@ func getStatus() (Status, error) { continue } - asset, err := getDownloadedOpenSeaAsset(strings.Split(info.Name(), ".")[0]) + id := strings.Split(info.Name(), ".")[0] + asset, err := getDownloadedOpenSeaAsset(id) if err != nil { return status, err } + if len(status.NFTs) <= 20 { + status.NFTs = append(status.NFTs, id) + } + status.NFTNum += 1 status.TotalUSDValue += asset.GetUSDPrice() }