diff --git a/.gitignore b/.gitignore index 0fad713..85f469c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ alm-prev* alm-dates + +version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..31aa793 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e611070 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# alm-dates + +A little tool to populate the Almanax from the data repository with dates from the Krosmoz Website. + +> [!NOTE] +> This tool is probably of no use to you. It is a part of the dofusdude update pipeline. You are still welcome to use it if you find a use case. + +Environment parameters for the `.env` file: +```sh +DODUAPI_UPDATE_TOKEN="" +POLLING_INTERVAL="1m" +END_DURATION="1y" +GH_AUTH_KEY="" # mandatory +``` + +## License +[MIT](https://choosealicense.com/licenses/mit/) diff --git a/go.mod b/go.mod index 8f0b7eb..a2ad599 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/PuerkitoBio/goquery v1.10.1 github.com/charmbracelet/log v0.4.0 github.com/dofusdude/dodugo v1.0.0-rc.8 - github.com/dofusdude/dodumap v0.6.0 + github.com/dofusdude/dodumap v0.6.1 github.com/google/go-github/v67 v67.0.0 golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 ) diff --git a/go.sum b/go.sum index 18a8192..169a266 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ 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/dofusdude/dodugo v1.0.0-rc.8 h1:C3LCiBag8BaFzMEJ7xnwur0aXAVGMwPH78T3eqt88TQ= github.com/dofusdude/dodugo v1.0.0-rc.8/go.mod h1:R/MZWCsB/+GpFctfckhOWmqpCMgmGkB+YC3N3TS3n6Y= -github.com/dofusdude/dodumap v0.6.0 h1:MUhyT5DEsuJnb1UDkgI1SuqKqIB3I3b0oNkjY/a8dBU= -github.com/dofusdude/dodumap v0.6.0/go.mod h1:51KG2eMd02UJnXErOubAukVftYuJproDHqJcbIHSzIE= +github.com/dofusdude/dodumap v0.6.1 h1:8zaTv6pMfkvN8OY3g2wupcjF3NgQo/KaOFI0gH++ljY= +github.com/dofusdude/dodumap v0.6.1/go.mod h1:51KG2eMd02UJnXErOubAukVftYuJproDHqJcbIHSzIE= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= diff --git a/main.go b/main.go index ac810a5..19b4191 100644 --- a/main.go +++ b/main.go @@ -45,15 +45,16 @@ func isDate(date string) bool { } const ( - AlmanaxUrl = "https://www.krosmoz.com/en/almanax" - CreateUpdateEndpointUrl = "https://alm.dofusdu.de/dofus2/almanax" - AlmanaxSourceRepo = "dofusdude/dofus3-main" - UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7) Gecko/20100101 Firefox/4.0b7" - DataRepoOwner = "dofusdude" - DataRepoName = "dofus3-main" - MappedAlmanaxFileName = "MAPPED_ALMANAX.json" + AlmanaxUrl = "https://www.krosmoz.com/en/almanax" + DoduapiUpdateEndpointUrl = "https://api.dofusdu.de/dofus3/v1/update" + UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7) Gecko/20100101 Firefox/4.0b7" + DataRepoOwner = "dofusdude" + DataRepoName = "dofus3-main" + MappedAlmanaxFileName = "MAPPED_ALMANAX.json" ) +var DoduapiUpdateToken string + // ParseDuration parses a duration string. // examples: "10d", "-1.5w" or "3Y4M5d". // Add time units are "d"="D", "w"="W", "M", "y"="Y". @@ -209,6 +210,19 @@ func updateAlmanaxRelease(almData []mapping.MappedMultilangNPCAlmanaxUnity, vers return err } + if DoduapiUpdateToken != "" { + body := fmt.Sprintf(`{"version":"%s"}`, version) + req, err := http.NewRequest("POST", fmt.Sprintf("%s/%s", DoduapiUpdateEndpointUrl, DoduapiUpdateToken), strings.NewReader(body)) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + _, err = http.DefaultClient.Do(req) + if err != nil { + return err + } + } + return err } @@ -424,6 +438,8 @@ func main() { log.Fatal("no github auth key found") } + DoduapiUpdateToken = os.Getenv("DODUAPI_UPDATE_TOKEN") + pollIntervalStr := os.Getenv("POLLING_INTERVAL") if pollIntervalStr == "" { pollIntervalStr = "1m"