From 9114204a3cc11784a396bb46e1519868a6005812 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:20:48 +0100 Subject: [PATCH 01/15] Add cobra dependency --- go.mod | 6 ++++++ go.sum | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/go.mod b/go.mod index ff8e90c..2e4d1f1 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,9 @@ module go.cpmachado.pt/gelo go 1.25.1 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/cobra v1.10.1 // indirect + github.com/spf13/pflag v1.0.9 // indirect +) diff --git a/go.sum b/go.sum index e69de29..e613680 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= +github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 325f67e3eb5e7f7ac7282100a19d2c513f7291b9 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:27:25 +0100 Subject: [PATCH 02/15] Add base structure --- cmd/root.go | 20 ++++++ main.go | 188 ++-------------------------------------------------- 2 files changed, 26 insertions(+), 182 deletions(-) create mode 100644 cmd/root.go diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..9e51c71 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "gelo", + Short: "A tool to keep up with ratings", +} + +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} diff --git a/main.go b/main.go index 3c0afa3..0fe1454 100644 --- a/main.go +++ b/main.go @@ -1,187 +1,11 @@ -package main - -import ( - "archive/zip" - "encoding/csv" - "encoding/xml" - "flag" - "fmt" - "io" - "log/slog" - "net/http" - "net/url" - "os" - "path" - - "go.cpmachado.pt/gelo/fide" - "go.cpmachado.pt/gelo/internal/config" -) - -var Version string = "0.2.0" +/* +Copyright © 2025 NAME HERE -const ( - PlayersNumberCap = 100000000 - PlayersNumberLog = 500000 -) +*/ +package main -func init() { - cfg := config.GetConfig() - parseFlags(cfg) - cfg.Apply() - slog.Info("INIT", slog.Any("config", cfg)) -} +import "go.cpmachado.pt/gelo/cmd" func main() { - cfg := config.GetConfig() - - slog.Info("MAIN", slog.String("message", "Creating directory"), slog.String("destination", cfg.Destination)) - if err := os.MkdirAll(cfg.Destination, os.ModePerm); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - xurl, err := url.Parse(fide.XmlURL) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - _, filename := path.Split(xurl.Path) - file, err := os.OpenFile(path.Join(cfg.Destination, filename), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - slog.Info("MAIN", - slog.String("message", "Retrieving records"), - slog.String("origin", fide.XmlURL), - slog.String("filename", filename), - ) - resp, err := http.Get(fide.XmlURL) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - _, err = io.Copy(file, resp.Body) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - err = file.Close() - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - err = resp.Body.Close() - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - slog.Info("MAIN", slog.String("message", "Open zip")) - archive, err := zip.OpenReader(path.Join(cfg.Destination, filename)) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - slog.Info("MAIN", slog.String("message", "Opening records"), slog.String("file", archive.File[0].Name)) - xmlFile, err := archive.File[0].Open() - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - decoder := xml.NewDecoder(xmlFile) - - file, err = os.OpenFile(path.Join(cfg.Destination, "players.csv"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) - if err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - w := csv.NewWriter(file) - - slog.Info("MAIN", slog.String("message", "Decoding XML, and encoding csv")) - - if err = w.Write(fide.PlayerCsvHeader); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - var player fide.Player - - for i := 0; i < PlayersNumberCap; { - tok, err := decoder.Token() - if err != nil { - if err == io.EOF { - slog.Info("MAIN", - slog.String("message", "Number of parsed players"), - slog.Int("parsed", i)) - break - } - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - switch v := tok.(type) { - case xml.StartElement: - if v.Name.Local == "player" { - i++ - if err := decoder.DecodeElement(&player, &v); err != nil { - fmt.Println("Error decoding player element:", err) - return - } - player.CorrectRecord() - if err = w.Write(player.ToCsvRecord()); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - // log each 100k - if i%PlayersNumberLog == 0 { - slog.Info("MAIN", - slog.String("message", "Number of parsed players"), - slog.Int("parsed", i)) - } - } - } - } - - if err = xmlFile.Close(); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - if err = archive.Close(); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - w.Flush() - if err = w.Error(); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - - if err = file.Close(); err != nil { - slog.Error("MAIN", slog.Any("error", err)) - os.Exit(1) - } - slog.Info("MAIN", slog.String("message", "Operation Complete")) -} - -func parseFlags(cfg *config.Config) { - var version bool - flag.StringVar(&cfg.Destination, "d", cfg.Destination, "Destination directory for resources") - flag.BoolVar(&version, "v", false, "Display version") - flag.Parse() - - if version { - displayVersion() - os.Exit(0) - } -} - -func displayVersion() { - fmt.Printf("gelo-%s Copyright (c) 2025 cpmachado", Version) + cmd.Execute() } From c416ce3000e347ecf9eee57ed2b24359cf4a62c0 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:41:54 +0100 Subject: [PATCH 03/15] Add version command --- cmd/root.go | 20 ++++++++++++++++++++ main.go | 4 ---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9e51c71..4c2f1c9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,15 +1,31 @@ package cmd import ( + "fmt" "os" + "runtime/debug" "github.com/spf13/cobra" ) +var runVersionFlag bool + // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "gelo", Short: "A tool to keep up with ratings", + RunE: func(cmd *cobra.Command, args []string) error { + if !runVersionFlag { + return cmd.Help() + } + progBuildInfo, ok := debug.ReadBuildInfo() + if ok { + fmt.Printf("%s-%s", cmd.Use, progBuildInfo.Main.Version) + } else { + fmt.Printf("%s-unknown", cmd.Use) + } + return nil + }, } func Execute() { @@ -18,3 +34,7 @@ func Execute() { os.Exit(1) } } + +func init() { + rootCmd.Flags().BoolVarP(&runVersionFlag, "version", "v", false, "Display version") +} diff --git a/main.go b/main.go index 0fe1454..4acfdb7 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,3 @@ -/* -Copyright © 2025 NAME HERE - -*/ package main import "go.cpmachado.pt/gelo/cmd" From 1a047f77ef14196accedac351f157b47be7392b3 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:43:32 +0100 Subject: [PATCH 04/15] Tidy deps --- go.mod | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 2e4d1f1..9f0f91d 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,9 @@ module go.cpmachado.pt/gelo go 1.25.1 +require github.com/spf13/cobra v1.10.1 + require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.10.1 // indirect github.com/spf13/pflag v1.0.9 // indirect ) From 27380a6f5b105eabb70e69bb0befca4721066483 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:44:57 +0100 Subject: [PATCH 05/15] completely bomb previous implementation --- fide/types.go | 94 --------------------------------------- fide/urls.go | 8 ---- internal/config/config.go | 49 -------------------- 3 files changed, 151 deletions(-) delete mode 100644 fide/types.go delete mode 100644 fide/urls.go delete mode 100644 internal/config/config.go diff --git a/fide/types.go b/fide/types.go deleted file mode 100644 index 185da8d..0000000 --- a/fide/types.go +++ /dev/null @@ -1,94 +0,0 @@ -package fide - -import ( - _ "encoding/csv" - "encoding/xml" - "regexp" - "strconv" -) - -type Players struct { - XMLName xml.Name `xml:"playerslist"` - Players []Player `xml:"player"` -} - -type Player struct { - XMLName xml.Name `xml:"player" csv:"xml_name"` - Id int `xml:"fideid" csv:"id"` - Name string `xml:"name" csv:"name"` - Country string `xml:"country" csv:"country"` - Sex string `xml:"sex" csv:"sex"` - Title string `xml:"title" csv:"title"` - W_title string `xml:"w_title" csv:"w_title"` - O_title string `xml:"o_title" csv:"o_title"` - Foa_title string `xml:"foa_title" csv:"foa_title"` - Rating int `xml:"rating" csv:"rating"` - Games int `xml:"games" csv:"games"` - K int `xml:"k" csv:"k"` - Rapid_rating int `xml:"rapid_rating" csv:"rapid_rating"` - Rapid_games int `xml:"rapid_games" csv:"rapid_games"` - Rapid_k int `xml:"rapid_k" csv:"rapid_k"` - Blitz_rating int `xml:"blitz_rating" csv:"blitz_rating"` - Blitz_games int `xml:"blitz_games" csv:"blitz_games"` - Blitz_k int `xml:"blitz_k" csv:"blitz_k"` - Birthday string `xml:"birthday" csv:"birthday"` - Flag string `xml:"flag" csv:"flag"` -} - -var ( - spaceBeforeComma = regexp.MustCompile(`\s+,`) - multipleSpacesForSingle = regexp.MustCompile(`\s\s+`) - duplicatedCommas = regexp.MustCompile(`,,`) -) - -func (p *Player) CorrectRecord() { - p.Name = multipleSpacesForSingle.ReplaceAllString(p.Name, " ") - p.Name = spaceBeforeComma.ReplaceAllString(p.Name, ",") - p.Name = duplicatedCommas.ReplaceAllString(p.Name, ",") -} - -var PlayerCsvHeader = []string{ - "id", - "name", - "country", - "sex", - "title", - "w_title", - "o_title", - "foa_title", - "rating", - "games", - "k", - "rapid_rating", - "rapid_games", - "rapid_k", - "blitz_rating", - "blitz_games", - "blitz_k", - "birthday", - "flag", -} - -func (p *Player) ToCsvRecord() []string { - return []string{ - strconv.Itoa(p.Id), - p.Name, - p.Country, - p.Sex, - p.Title, - p.W_title, - p.O_title, - p.Foa_title, - strconv.Itoa(p.Rating), - strconv.Itoa(p.Games), - strconv.Itoa(p.K), - strconv.Itoa(p.Rapid_rating), - strconv.Itoa(p.Rapid_games), - strconv.Itoa(p.Rapid_k), - strconv.Itoa(p.Blitz_rating), - strconv.Itoa(p.Blitz_games), - strconv.Itoa(p.Blitz_k), - p.Birthday, - p.Flag, - } -} diff --git a/fide/urls.go b/fide/urls.go deleted file mode 100644 index e38e7e8..0000000 --- a/fide/urls.go +++ /dev/null @@ -1,8 +0,0 @@ -package fide - -const ( - // XmlURL refers to the current FIDE rating List in XML - XmlURL = "https://ratings.fide.com/download/players_list_xml.zip" - // TxtURL refers to the current FIDE rating List - TxtURL = "https://ratings.fide.com/download/players_list.zip" -) diff --git a/internal/config/config.go b/internal/config/config.go deleted file mode 100644 index f01229c..0000000 --- a/internal/config/config.go +++ /dev/null @@ -1,49 +0,0 @@ -package config - -import ( - "log/slog" - "os" -) - -// LogConfig stores Logger Configuration -type LogConfig struct { - Level slog.Level - Group string -} - -func (lc LogConfig) Apply() { - logger := slog.New( - slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ - Level: lc.Level, - }), - ).WithGroup(lc.Group) - - slog.SetDefault(logger) -} - -type Config struct { - Destination string - Log LogConfig -} - -func (c Config) Clone() Config { - return c -} - -func (c Config) Apply() { - c.Log.Apply() -} - -var config = &DefaultConfig - -func GetConfig() *Config { - return config -} - -var DefaultConfig = Config{ - Destination: "output", - Log: LogConfig{ - Level: slog.LevelInfo, - Group: "data", - }, -} From 1283af41e22702559303413a3eaaea8e0e668410 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:46:17 +0100 Subject: [PATCH 06/15] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a3e8ccb..f8dc3c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ output *.zip *.txt *.xml +/target From 61402628b10741185771468b5681b65c10f98f0a Mon Sep 17 00:00:00 2001 From: cpmachado Date: Wed, 1 Oct 2025 23:49:13 +0100 Subject: [PATCH 07/15] FPX data --- doc/FPX.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 doc/FPX.md diff --git a/doc/FPX.md b/doc/FPX.md new file mode 100644 index 0000000..c0cdda7 --- /dev/null +++ b/doc/FPX.md @@ -0,0 +1,11 @@ +# FPX + +Portuguese federation data: + +- blitz: +- classic: +- rapid: + +It's a simple csv using ";" as separator and the fields, still to be studied. + +It contains club data. From 1ecb2c0f283ae82167216628ddcf8dfb342e0a8f Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 00:25:48 +0100 Subject: [PATCH 08/15] Update FPX documentation --- doc/FPX.md | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/doc/FPX.md b/doc/FPX.md index c0cdda7..7686163 100644 --- a/doc/FPX.md +++ b/doc/FPX.md @@ -1,4 +1,6 @@ -# FPX +# FPX (Federação Portuguesa de Xadrez) + +Website: Portuguese federation data: @@ -6,6 +8,32 @@ Portuguese federation data: - classic: - rapid: -It's a simple csv using ";" as separator and the fields, still to be studied. +It's a simple csv using ";" as separator and the fields. + +It has some issues with encoding and random Carriage return in some records. -It contains club data. +So far it appears, by order: +- FPX id +- Name +- Federation +- Sex +- Club ID +- Club Name +- Date of Birth: only year in format (2006-_-_) +- Number of games? (Still not sure) +- FIDE ID +- Rating +- Title +- Age Group + + U08 + + U10 + + U12 + + U14 + + U16 + + U18 + + U20 + + Sen + + S50 + + S65 +- Flags: Only inactive? +- K factor? (appears so, but some are 0 and empty, are these unrated?) From d47e3a5375937743553cf6eebc37e8bfe45b9ab3 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 00:36:34 +0100 Subject: [PATCH 09/15] Add xdg and viper dependencies --- go.mod | 15 ++++++++++++++- go.sum | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9f0f91d..860ab96 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,19 @@ go 1.25.1 require github.com/spf13/cobra v1.10.1 require ( + github.com/adrg/xdg v0.5.3 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/pflag v1.0.9 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/sagikazarmark/locafero v0.12.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/spf13/viper v1.21.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.29.0 // indirect ) diff --git a/go.sum b/go.sum index e613680..9c0e87f 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,38 @@ +github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= +github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.12.0 h1:/NQhBAkUb4+fH1jivKHWusDYFjMOOKU88eegjfxfHb4= +github.com/sagikazarmark/locafero v0.12.0/go.mod h1:sZh36u/YSZ918v0Io+U9ogLYQJ9tLLBmM4eneO6WwsI= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From d8ae1ad4e35d0cdbf28b5c7b53248a408c0eef50 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 00:42:14 +0100 Subject: [PATCH 10/15] Add default config file --- internal/config/consts.go | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 internal/config/consts.go diff --git a/internal/config/consts.go b/internal/config/consts.go new file mode 100644 index 0000000..96d3674 --- /dev/null +++ b/internal/config/consts.go @@ -0,0 +1,9 @@ +package config + +import ( + "path" + + "github.com/adrg/xdg" +) + +var DefaultConfigFile string = path.Join(xdg.ConfigHome, "gelo", "config.json") From 0ee3811d1dba0d3131db4104bbab67168deeb5de Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 00:58:23 +0100 Subject: [PATCH 11/15] Add config consts --- internal/config/consts.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/config/consts.go b/internal/config/consts.go index 96d3674..dabc1ff 100644 --- a/internal/config/consts.go +++ b/internal/config/consts.go @@ -6,4 +6,7 @@ import ( "github.com/adrg/xdg" ) -var DefaultConfigFile string = path.Join(xdg.ConfigHome, "gelo", "config.json") +var ( + DefaultConfigHome string = path.Join(xdg.ConfigHome, "gelo") + DefaultConfigFile string = path.Join(DefaultConfigHome, "config.json") +) From 283bd06d0944aaacda8a62a8b53e3664408d2875 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 00:58:40 +0100 Subject: [PATCH 12/15] add config options --- cmd/root.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 4c2f1c9..77d1d83 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,9 +6,14 @@ import ( "runtime/debug" "github.com/spf13/cobra" + "github.com/spf13/viper" + "go.cpmachado.pt/gelo/internal/config" ) -var runVersionFlag bool +var ( + runVersionFlag bool + cfgFile string = config.DefaultConfigFile +) // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ @@ -31,10 +36,32 @@ var rootCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { + fmt.Fprint(os.Stderr, err.Error()) os.Exit(1) } } func init() { + cobra.OnInitialize(initConfig) rootCmd.Flags().BoolVarP(&runVersionFlag, "version", "v", false, "Display version") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", config.DefaultConfigFile, "config file") +} + +func initConfig() { + if cfgFile != "" { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) + } else { + + // Search config in home directory with name ".cobra" (without extension). + viper.AddConfigPath(config.DefaultConfigHome) + viper.SetConfigType("json") + viper.SetConfigName("config") + } + + viper.AutomaticEnv() + + if err := viper.ReadInConfig(); err == nil { + fmt.Println("Using config file:", viper.ConfigFileUsed()) + } } From ba8c944741de087357f84e8e61daaa90c28ff3da Mon Sep 17 00:00:00 2001 From: cpmachado Date: Thu, 2 Oct 2025 01:01:32 +0100 Subject: [PATCH 13/15] Tidy go.mod --- go.mod | 10 ++++++---- go.sum | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 860ab96..58cdb29 100644 --- a/go.mod +++ b/go.mod @@ -2,22 +2,24 @@ module go.cpmachado.pt/gelo go 1.25.1 -require github.com/spf13/cobra v1.10.1 +require ( + github.com/adrg/xdg v0.5.3 + github.com/spf13/cobra v1.10.1 + github.com/spf13/viper v1.21.0 +) require ( - github.com/adrg/xdg v0.5.3 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/sagikazarmark/locafero v0.12.0 // indirect - github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect github.com/spf13/afero v1.15.0 // indirect github.com/spf13/cast v1.10.0 // indirect github.com/spf13/pflag v1.0.10 // indirect - github.com/spf13/viper v1.21.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/sys v0.36.0 // indirect golang.org/x/text v0.29.0 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/go.sum b/go.sum index 9c0e87f..70386f3 100644 --- a/go.sum +++ b/go.sum @@ -1,31 +1,44 @@ github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.12.0 h1:/NQhBAkUb4+fH1jivKHWusDYFjMOOKU88eegjfxfHb4= github.com/sagikazarmark/locafero v0.12.0/go.mod h1:sZh36u/YSZ918v0Io+U9ogLYQJ9tLLBmM4eneO6WwsI= -github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= -github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= -github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= @@ -35,4 +48,7 @@ golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 56e4f0244fba213a1636311026f342792f152b53 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 28 Dec 2025 15:07:55 +0000 Subject: [PATCH 14/15] Update dependencies --- go.mod | 6 +++--- go.sum | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 58cdb29..181a273 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.25.1 require ( github.com/adrg/xdg v0.5.3 - github.com/spf13/cobra v1.10.1 + github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.21.0 ) @@ -19,7 +19,7 @@ require ( github.com/spf13/pflag v1.0.10 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/sys v0.36.0 // indirect - golang.org/x/text v0.29.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/go.sum b/go.sum index 70386f3..1b32ffc 100644 --- a/go.sum +++ b/go.sum @@ -32,6 +32,8 @@ github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -45,8 +47,12 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 3d85daa657f1994eb876b264871126c937c3e698 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 28 Dec 2025 15:23:05 +0000 Subject: [PATCH 15/15] Add fide anyway --- fide/types.go | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ fide/urls.go | 8 +++++ 2 files changed, 102 insertions(+) create mode 100644 fide/types.go create mode 100644 fide/urls.go diff --git a/fide/types.go b/fide/types.go new file mode 100644 index 0000000..185da8d --- /dev/null +++ b/fide/types.go @@ -0,0 +1,94 @@ +package fide + +import ( + _ "encoding/csv" + "encoding/xml" + "regexp" + "strconv" +) + +type Players struct { + XMLName xml.Name `xml:"playerslist"` + Players []Player `xml:"player"` +} + +type Player struct { + XMLName xml.Name `xml:"player" csv:"xml_name"` + Id int `xml:"fideid" csv:"id"` + Name string `xml:"name" csv:"name"` + Country string `xml:"country" csv:"country"` + Sex string `xml:"sex" csv:"sex"` + Title string `xml:"title" csv:"title"` + W_title string `xml:"w_title" csv:"w_title"` + O_title string `xml:"o_title" csv:"o_title"` + Foa_title string `xml:"foa_title" csv:"foa_title"` + Rating int `xml:"rating" csv:"rating"` + Games int `xml:"games" csv:"games"` + K int `xml:"k" csv:"k"` + Rapid_rating int `xml:"rapid_rating" csv:"rapid_rating"` + Rapid_games int `xml:"rapid_games" csv:"rapid_games"` + Rapid_k int `xml:"rapid_k" csv:"rapid_k"` + Blitz_rating int `xml:"blitz_rating" csv:"blitz_rating"` + Blitz_games int `xml:"blitz_games" csv:"blitz_games"` + Blitz_k int `xml:"blitz_k" csv:"blitz_k"` + Birthday string `xml:"birthday" csv:"birthday"` + Flag string `xml:"flag" csv:"flag"` +} + +var ( + spaceBeforeComma = regexp.MustCompile(`\s+,`) + multipleSpacesForSingle = regexp.MustCompile(`\s\s+`) + duplicatedCommas = regexp.MustCompile(`,,`) +) + +func (p *Player) CorrectRecord() { + p.Name = multipleSpacesForSingle.ReplaceAllString(p.Name, " ") + p.Name = spaceBeforeComma.ReplaceAllString(p.Name, ",") + p.Name = duplicatedCommas.ReplaceAllString(p.Name, ",") +} + +var PlayerCsvHeader = []string{ + "id", + "name", + "country", + "sex", + "title", + "w_title", + "o_title", + "foa_title", + "rating", + "games", + "k", + "rapid_rating", + "rapid_games", + "rapid_k", + "blitz_rating", + "blitz_games", + "blitz_k", + "birthday", + "flag", +} + +func (p *Player) ToCsvRecord() []string { + return []string{ + strconv.Itoa(p.Id), + p.Name, + p.Country, + p.Sex, + p.Title, + p.W_title, + p.O_title, + p.Foa_title, + strconv.Itoa(p.Rating), + strconv.Itoa(p.Games), + strconv.Itoa(p.K), + strconv.Itoa(p.Rapid_rating), + strconv.Itoa(p.Rapid_games), + strconv.Itoa(p.Rapid_k), + strconv.Itoa(p.Blitz_rating), + strconv.Itoa(p.Blitz_games), + strconv.Itoa(p.Blitz_k), + p.Birthday, + p.Flag, + } +} diff --git a/fide/urls.go b/fide/urls.go new file mode 100644 index 0000000..e38e7e8 --- /dev/null +++ b/fide/urls.go @@ -0,0 +1,8 @@ +package fide + +const ( + // XmlURL refers to the current FIDE rating List in XML + XmlURL = "https://ratings.fide.com/download/players_list_xml.zip" + // TxtURL refers to the current FIDE rating List + TxtURL = "https://ratings.fide.com/download/players_list.zip" +)