Skip to content

Commit

Permalink
feat: adding top10 referral script
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Dec 21, 2023
1 parent 48d2286 commit ed710cc
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ cmd/data/wallet.json
cmd/data/config.json
cmd/data/validators.json
cmd/bin
__pycache__
__pycache__
/scripts/go/referral.json
/scripts/go/top10.json
58 changes: 58 additions & 0 deletions scripts/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"encoding/json"
"os"
"sort"

"github.com/kehiy/RoboPac/discord"
)

func main() {
referrals, err := LoadReferralData("./referral.json")
if err != nil {
panic(err)
}

sort.Slice(referrals, func(i, j int) bool { // sort referrals based on points in descending order
return referrals[i].Points > referrals[j].Points
})

top10 := [10]discord.Referral{}
for i, r := range referrals {
if i >= 10 {
break
}
top10[i] = r
}

data, err := json.Marshal(top10)
if err != nil {
panic(err)
}

err = os.WriteFile("top10.json", data, 0o600)
if err != nil {
panic(err)
}
}

func LoadReferralData(path string) ([]discord.Referral, error) {
file, err := os.ReadFile(path)
if err != nil {
return nil, err
}

referrals := map[string]discord.Referral{}
err = json.Unmarshal(file, &referrals)
if err != nil {
return nil, err
}

result := []discord.Referral{}
for _, r := range referrals {
result = append(result, r)
}

return result, nil
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ed710cc

Please sign in to comment.