From 2befb888653bd70e826088b1be61bf4a53f067fe Mon Sep 17 00:00:00 2001 From: sundy-li <543950155@qq.com> Date: Sat, 13 Jan 2018 11:04:17 +0800 Subject: [PATCH] use coreos/goproxy to fix ios websocket proxy --- README.md | 4 +- cmd/question_utils.go | 110 ++++++++++++++++++++++++++++++++++++++++-- questions.data | Bin 1048576 -> 1048576 bytes 3 files changed, 108 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ebaac4..f627f73 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,10 @@ - 运行方法二: 安装go(>=1.8)环境后, clone本repo源码到对应`$GOPATH/src/github.com/sundy-li/`下, 进入源码目录后,执行 `go run cmd/main.go` - 手机wifi设置代理为pc的ip和端口,启动小程序王者头脑 - ## 问题 -- ios端由于goproxy无法代理websocket问题,暂时无法使用,希望大家可以来完善这个问题,见[这个issue](https://github.com/sundy-li/wechat_brain/issues/18) +- 感谢@HsiangHo, @milkmeowo 的贡献,修复了ios代理问题,更新新版本后,最好重新安装证书,重启微信进程 + ~~ios端由于goproxy无法代理websocket问题,暂时无法使用,希望大家可以来完善这个问题,见[这个issue](https://github.com/sundy-li/wechat_brain/issues/18) ~~ ## 合并题库 diff --git a/cmd/question_utils.go b/cmd/question_utils.go index 2be0b88..8858641 100644 --- a/cmd/question_utils.go +++ b/cmd/question_utils.go @@ -1,33 +1,135 @@ package main import ( + "archive/zip" "flag" + "io" "log" + "net/http" + "os" + "path/filepath" "strings" brain "github.com/sundy-li/wechat_brain" + + "github.com/PuerkitoBio/goquery" ) var ( - action string - fs string + source string + fs string + issueUrl = "https://github.com/sundy-li/wechat_brain/issues/17" + tmpDir = "/data/tmp/" ) func init() { - flag.StringVar(&action, "a", "show", "action value -> show | merge") + flag.StringVar(&source, "s", "show", "source value -> show | file | issue") flag.StringVar(&fs, "fs", "", "merge data files") flag.Parse() } func main() { - if action == "merge" { + if source == "file" { files := strings.Split(fs, " ") if len(files) < 1 { log.Println("empty files") return } brain.MergeQuestions(files...) + } else if source == "issue" { + doc, _ := goquery.NewDocument(issueUrl) + doc.Find("div.comment").Each(func(index int, comment *goquery.Selection) { + comment.Find("td.d-block p a").Each(func(i int, s *goquery.Selection) { + if strings.Contains(s.Text(), "questions.zip") { + href, _ := s.Attr("href") + if href != "" { + handleZipUrl(href) + } + } + }) + }) } total := brain.CountQuestions() log.Println("total questions =>", total) } + +func handleZipUrl(url string) error { + resp, err := http.Get(url) + if err != nil { + return err + } + defer resp.Body.Close() + out, err := os.Create(tmpDir + "questions.zip") + if err != nil { + return err + } + defer out.Close() + io.Copy(out, resp.Body) + _, err = Unzip(tmpDir+"questions.zip", tmpDir) + if err != nil { + return err + } + + //merge data + brain.MergeQuestions(tmpDir + "questions.data") + log.Println("merged", url) + return nil +} + +// Unzip will un-compress a zip archive, +// moving all files and folders to an output directory +func Unzip(src, dest string) ([]string, error) { + + var filenames []string + + r, err := zip.OpenReader(src) + if err != nil { + return filenames, err + } + defer r.Close() + + for _, f := range r.File { + + rc, err := f.Open() + if err != nil { + return filenames, err + } + defer rc.Close() + + // Store filename/path for returning and using later on + fpath := filepath.Join(dest, f.Name) + filenames = append(filenames, fpath) + + if f.FileInfo().IsDir() { + // Make Folder + os.MkdirAll(fpath, os.ModePerm) + + } else { + + // Make File + var fdir string + if lastIndex := strings.LastIndex(fpath, string(os.PathSeparator)); lastIndex > -1 { + fdir = fpath[:lastIndex] + } + + err = os.MkdirAll(fdir, os.ModePerm) + if err != nil { + log.Fatal(err) + return filenames, err + } + f, err := os.OpenFile( + fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) + if err != nil { + return filenames, err + } + defer f.Close() + + _, err = io.Copy(f, rc) + if err != nil { + return filenames, err + } + + } + } + return filenames, nil +} diff --git a/questions.data b/questions.data index dc5c2c75e1d694187ad9c35a3b3885202bea2ebc..65e57011808a1085045921f274d6f0873f0ca585 100644 GIT binary patch delta 7564 zcmeI0`*&2;702)7Ik__-6V#fRl1v~Nv05ey8t^qBD2T{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