Compare commits

..

No commits in common. "cd2da0aa5c3f012bfbb4710f0decc828eb5ee9f8" and "7fa573613d2224c8961593b23ca93f6cc878f3c5" have entirely different histories.

3 changed files with 40 additions and 58 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
.cache/

View File

@ -1,3 +0,0 @@
#!/bin/sh
rm -rf .cache

94
main.go
View File

@ -1,71 +1,57 @@
package main package main
import ( import (
"encoding/json"
"errors"
"fmt"
"log" "log"
"os" "slices"
"path"
"time"
"github.com/karashiiro/bingode" "github.com/karashiiro/bingode"
"github.com/xivapi/godestone/v2" "github.com/xivapi/godestone/v2"
) )
const CachePath = "./.cache"
type CacheRecord struct {
Time time.Time `json:"time"`
Data string `json:"data"`
}
type Cache map[uint32]CacheRecord
func main() { func main() {
err := os.MkdirAll(CachePath, 0755) ignore := []string{
if err != nil { "Carpenter",
log.Fatal(err) "Blacksmith",
"Armorer",
"Goldsmith",
"Leatherworker",
"Weaver",
"Alchemist",
"Culinarian",
"Miner",
"Botanist",
"Fisher",
} }
raw_cache, err := os.ReadFile(path.Join(CachePath, "cache.json")) base_levels := make(map[string]int)
var cache Cache
if errors.Is(err, os.ErrNotExist) { base_levels["Dark Knight"] = 30
cache = make(Cache) base_levels["Astrologian"] = 30
} else if err == nil { base_levels["Machinist"] = 30
err := json.Unmarshal(raw_cache, &cache) base_levels["Red Mage"] = 50
if err != nil { base_levels["Samurai"] = 50
log.Fatalln(err) base_levels["Gunbreaker"] = 60
base_levels["Dancer"] = 60
base_levels["Reaper"] = 70
base_levels["Sage"] = 70
s := godestone.NewScraper(bingode.New(), godestone.EN)
c, err := s.FetchCharacter(29932586)
if err != nil {
log.Fatalln(err)
}
total := 0
for _, v := range c.ClassJobs {
if v.Name != "Scholar" && !slices.Contains(ignore[:], v.Name) {
base_level, ok := base_levels[v.Name]
if !ok {
base_level = 0
}
total += int(v.Level) - base_level
} }
} else {
log.Fatalln(err)
} }
var id uint32 = 29932586 println(total)
data, ok := cache[id]
if !ok {
log.Printf("Fetching fresh data for %d\n", id)
s := godestone.NewScraper(bingode.New(), godestone.EN)
c, err := s.FetchCharacter(id)
if err != nil {
log.Fatalln(err)
}
raw_data, _ := json.Marshal(c.ClassJobs)
data = CacheRecord{Time: time.Now(), Data: string(raw_data)}
cache[id] = data
}
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)
} }