From 4b288a59b983a0317d882fbae5447df3d421307f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 4 Oct 2022 16:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20hyaku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data | 2 +- plugin/hyaku/main.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/data b/data index 5ce4b48c..aa8f7eb3 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 5ce4b48c12ea42fc999823ea119b69a9d5dfa451 +Subproject commit aa8f7eb30a360babcbd7d658d4bebc4643d478df diff --git a/plugin/hyaku/main.go b/plugin/hyaku/main.go index 6caf468e..db266e4c 100644 --- a/plugin/hyaku/main.go +++ b/plugin/hyaku/main.go @@ -4,6 +4,7 @@ package hyaku import ( "encoding/csv" "fmt" + "io" "math/rand" "os" "reflect" @@ -12,6 +13,7 @@ import ( "github.com/FloatTech/floatbox/binary" "github.com/FloatTech/floatbox/file" + "github.com/FloatTech/floatbox/web" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" @@ -61,16 +63,25 @@ func init() { }) csvfile := engine.DataFolder() + "hyaku.csv" go func() { + var f *os.File if file.IsNotExist(csvfile) { - err := file.DownloadTo(bed+"小倉百人一首.csv", csvfile, true) + data, err := web.RequestDataWith(web.NewTLS12Client(), bed+"小倉百人一首.csv", "GET", "gitcode.net", web.RandUA()) if err != nil { _ = os.Remove(csvfile) panic(err) } - } - f, err := os.Open(csvfile) - if err != nil { - panic(err) + f, err = os.Create(csvfile) + if err != nil { + panic(err) + } + _, _ = f.Write(data) + _, _ = f.Seek(0, io.SeekStart) + } else { + var err error + f, err = os.Open(csvfile) + if err != nil { + panic(err) + } } records, err := csv.NewReader(f).ReadAll() if err != nil {