Mostrar algunos NFTs copiados en index
All checks were successful
continuous-integration/woodpecker the build was successful

This commit is contained in:
Cat /dev/Nulo 2021-11-09 19:32:48 -03:00
parent 0051c181aa
commit a7b5f6de14
2 changed files with 21 additions and 1 deletions

View file

@ -12,3 +12,11 @@
<p>Inspirado en <a href="https://konsthack.se/portfolio/kh000-kopimashin/" rel="noreferrer noopener">Kopimashin</a> de brokep.</p> <p>Inspirado en <a href="https://konsthack.se/portfolio/kh000-kopimashin/" rel="noreferrer noopener">Kopimashin</a> de brokep.</p>
<p><a href="https://es.wikipedia.org/wiki/Kopimismo" rel="noreferrer noopener"><img style="width: 5rem;box-shadow: 0 0 10px #555;border-radius: 10px;background: #555;padding: .5em;" src="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg xmlns='http://www.w3.org/2000/svg' height='602.67' width='579.07' stroke='%23ffffff' stroke-width='1.3028' viewBox='0 0 612 792'%3E%3Cpath d='m441.08 720.52l-93.24 66.61-417.03-295.1 0.004-251.03 93.239-65.58 149.6 104.51v-210.05l93.24-66.6 94.27 66.604v210.05l67.62-47.13 79.93 56.36 80.94-57.39 94.26 66.61v251.03l-94.26 65.58-80.94-57.38-67.63 48.15z'/%3E%3Cpath d='m-43.573 241l67.626 48.16 68.65-48.16-68.65-48.16zm80.948 57.38l67.625 48.15 68.65-48.15-67.62-48.17zm79.925 57.37l68.64 48.16 68.66-48.16-68.66-48.15zm149.59-334.03l-68.65 48.16 68.65 48.156 68.65-48.156zm0 114.76l-68.65 48.16 68.65 48.16 67.63-49.18zm0 113.74l-68.65 48.16 68.65 48.15 67.63-48.15zm-68.65 162.91l68.65 47.14 67.63-48.16-67.63-47.14zm80.95 56.35l68.65 48.16 67.62-48.16-67.62-48.15zm149.59-219.26l-68.65 48.16 67.63 48.15 68.65-48.15zm160.87 0l-67.63 48.16 67.63 48.15 68.65-48.15z' fill='%23fff'/%3E%3C/svg%3E" alt="Kopimi"></a></p> <p><a href="https://es.wikipedia.org/wiki/Kopimismo" rel="noreferrer noopener"><img style="width: 5rem;box-shadow: 0 0 10px #555;border-radius: 10px;background: #555;padding: .5em;" src="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8' standalone='no'%3F%3E%3Csvg xmlns='http://www.w3.org/2000/svg' height='602.67' width='579.07' stroke='%23ffffff' stroke-width='1.3028' viewBox='0 0 612 792'%3E%3Cpath d='m441.08 720.52l-93.24 66.61-417.03-295.1 0.004-251.03 93.239-65.58 149.6 104.51v-210.05l93.24-66.6 94.27 66.604v210.05l67.62-47.13 79.93 56.36 80.94-57.39 94.26 66.61v251.03l-94.26 65.58-80.94-57.38-67.63 48.15z'/%3E%3Cpath d='m-43.573 241l67.626 48.16 68.65-48.16-68.65-48.16zm80.948 57.38l67.625 48.15 68.65-48.15-67.62-48.17zm79.925 57.37l68.64 48.16 68.66-48.16-68.66-48.15zm149.59-334.03l-68.65 48.16 68.65 48.156 68.65-48.156zm0 114.76l-68.65 48.16 68.65 48.16 67.63-49.18zm0 113.74l-68.65 48.16 68.65 48.15 67.63-48.15zm-68.65 162.91l68.65 47.14 67.63-48.16-67.63-47.14zm80.95 56.35l68.65 48.16 67.62-48.16-67.62-48.15zm149.59-219.26l-68.65 48.16 67.63 48.15 68.65-48.15zm160.87 0l-67.63 48.16 67.63 48.15 68.65-48.15z' fill='%23fff'/%3E%3C/svg%3E" alt="Kopimi"></a></p>
</section> </section>
<section>
<h2>Algunos NFTs descargados</h2>
{{range .NFTs}}
<a href="/nfts/{{.}}">
<img src="/static/nfts/{{.}}">
</a>
{{end}}
</section>

14
main.go
View file

@ -7,16 +7,19 @@ import (
"io" "io"
"io/fs" "io/fs"
"log" "log"
"math/rand"
"net/http" "net/http"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
) )
type Status struct { type Status struct {
NFTNum int NFTNum int
TotalUSDValue float64 TotalUSDValue float64
NFTs []string
} }
const NFTS_DIR = "./nfts" const NFTS_DIR = "./nfts"
@ -41,6 +44,10 @@ func getStatus() (Status, error) {
return status, err 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 { for _, val := range entries {
info, err := val.Info() info, err := val.Info()
if err != nil { if err != nil {
@ -50,11 +57,16 @@ func getStatus() (Status, error) {
continue continue
} }
asset, err := getDownloadedOpenSeaAsset(strings.Split(info.Name(), ".")[0]) id := strings.Split(info.Name(), ".")[0]
asset, err := getDownloadedOpenSeaAsset(id)
if err != nil { if err != nil {
return status, err return status, err
} }
if len(status.NFTs) <= 20 {
status.NFTs = append(status.NFTs, id)
}
status.NFTNum += 1 status.NFTNum += 1
status.TotalUSDValue += asset.GetUSDPrice() status.TotalUSDValue += asset.GetUSDPrice()
} }