use arguments for ids

main
Zynh0722 2024-02-25 13:36:20 -08:00
parent 0682104dc8
commit 92e4d5ed2a
1 changed files with 28 additions and 16 deletions

44
main.go
View File

@ -7,6 +7,7 @@ import (
"log"
"os"
"path"
"strconv"
"time"
"github.com/karashiiro/bingode"
@ -41,25 +42,36 @@ func main() {
log.Fatalln(err)
}
// bingle: 29932586
// dialus: 44540671
var id uint32 = 44540671
data, ok := cache[id]
if !ok || time.Now().After(data.Time.Add(time.Minute*10)) {
cache[id] = refetch_data(id)
data = cache[id]
}
args := os.Args[1:]
cache_as_stored, err := json.Marshal(cache)
if err != nil {
log.Fatalln(err)
}
for _, arg := range args {
id_64, err := strconv.ParseUint(arg, 10, 32)
if err != nil {
log.New(os.Stderr, "", 0).Println(err)
os.Exit(2)
}
err = os.WriteFile(path.Join(CachePath, "cache.json"), cache_as_stored, 0755)
if err != nil {
log.Fatalln(err)
id := uint32(id_64)
// bingle: 29932586
// dialus: 44540671
data, ok := cache[id]
if !ok || time.Now().After(data.Time.Add(time.Minute*10)) {
cache[id] = refetch_data(id)
data = cache[id]
}
cache_as_stored, err := json.Marshal(cache)
if err != nil {
log.Fatalln(err)
}
err = os.WriteFile(path.Join(CachePath, "cache.json"), cache_as_stored, 0755)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%s\n", data.Data)
}
fmt.Printf("%s\n", data.Data)
}
func refetch_data(id uint32) CacheRecord {