Skip to content
This repository was archived by the owner on Aug 2, 2018. It is now read-only.

Commit 2befb88

Browse files
committed
use coreos/goproxy to fix ios websocket proxy
1 parent 9675863 commit 2befb88

File tree

3 files changed

+108
-6
lines changed

3 files changed

+108
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
- 运行方法二: 安装go(>=1.8)环境后, clone本repo源码到对应`$GOPATH/src/github.com/sundy-li/`下, 进入源码目录后,执行 `go run cmd/main.go`
1313
- 手机wifi设置代理为pc的ip和端口,启动小程序王者头脑
1414

15-
1615
## 问题
1716

18-
- ios端由于goproxy无法代理websocket问题,暂时无法使用,希望大家可以来完善这个问题,见[这个issue](https://github.com/sundy-li/wechat_brain/issues/18)
17+
- 感谢@HsiangHo, @milkmeowo 的贡献,修复了ios代理问题,更新新版本后,最好重新安装证书,重启微信进程
18+
~~ios端由于goproxy无法代理websocket问题,暂时无法使用,希望大家可以来完善这个问题,见[这个issue](https://github.com/sundy-li/wechat_brain/issues/18) ~~
1919

2020

2121
## 合并题库

cmd/question_utils.go

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,135 @@
11
package main
22

33
import (
4+
"archive/zip"
45
"flag"
6+
"io"
57
"log"
8+
"net/http"
9+
"os"
10+
"path/filepath"
611
"strings"
712

813
brain "github.com/sundy-li/wechat_brain"
14+
15+
"github.com/PuerkitoBio/goquery"
916
)
1017

1118
var (
12-
action string
13-
fs string
19+
source string
20+
fs string
21+
issueUrl = "https://github.com/sundy-li/wechat_brain/issues/17"
22+
tmpDir = "/data/tmp/"
1423
)
1524

1625
func init() {
17-
flag.StringVar(&action, "a", "show", "action value -> show | merge")
26+
flag.StringVar(&source, "s", "show", "source value -> show | file | issue")
1827
flag.StringVar(&fs, "fs", "", "merge data files")
1928
flag.Parse()
2029
}
2130

2231
func main() {
23-
if action == "merge" {
32+
if source == "file" {
2433
files := strings.Split(fs, " ")
2534
if len(files) < 1 {
2635
log.Println("empty files")
2736
return
2837
}
2938
brain.MergeQuestions(files...)
39+
} else if source == "issue" {
40+
doc, _ := goquery.NewDocument(issueUrl)
41+
doc.Find("div.comment").Each(func(index int, comment *goquery.Selection) {
42+
comment.Find("td.d-block p a").Each(func(i int, s *goquery.Selection) {
43+
if strings.Contains(s.Text(), "questions.zip") {
44+
href, _ := s.Attr("href")
45+
if href != "" {
46+
handleZipUrl(href)
47+
}
48+
}
49+
})
50+
})
3051
}
3152
total := brain.CountQuestions()
3253
log.Println("total questions =>", total)
3354
}
55+
56+
func handleZipUrl(url string) error {
57+
resp, err := http.Get(url)
58+
if err != nil {
59+
return err
60+
}
61+
defer resp.Body.Close()
62+
out, err := os.Create(tmpDir + "questions.zip")
63+
if err != nil {
64+
return err
65+
}
66+
defer out.Close()
67+
io.Copy(out, resp.Body)
68+
_, err = Unzip(tmpDir+"questions.zip", tmpDir)
69+
if err != nil {
70+
return err
71+
}
72+
73+
//merge data
74+
brain.MergeQuestions(tmpDir + "questions.data")
75+
log.Println("merged", url)
76+
return nil
77+
}
78+
79+
// Unzip will un-compress a zip archive,
80+
// moving all files and folders to an output directory
81+
func Unzip(src, dest string) ([]string, error) {
82+
83+
var filenames []string
84+
85+
r, err := zip.OpenReader(src)
86+
if err != nil {
87+
return filenames, err
88+
}
89+
defer r.Close()
90+
91+
for _, f := range r.File {
92+
93+
rc, err := f.Open()
94+
if err != nil {
95+
return filenames, err
96+
}
97+
defer rc.Close()
98+
99+
// Store filename/path for returning and using later on
100+
fpath := filepath.Join(dest, f.Name)
101+
filenames = append(filenames, fpath)
102+
103+
if f.FileInfo().IsDir() {
104+
// Make Folder
105+
os.MkdirAll(fpath, os.ModePerm)
106+
107+
} else {
108+
109+
// Make File
110+
var fdir string
111+
if lastIndex := strings.LastIndex(fpath, string(os.PathSeparator)); lastIndex > -1 {
112+
fdir = fpath[:lastIndex]
113+
}
114+
115+
err = os.MkdirAll(fdir, os.ModePerm)
116+
if err != nil {
117+
log.Fatal(err)
118+
return filenames, err
119+
}
120+
f, err := os.OpenFile(
121+
fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
122+
if err != nil {
123+
return filenames, err
124+
}
125+
defer f.Close()
126+
127+
_, err = io.Copy(f, rc)
128+
if err != nil {
129+
return filenames, err
130+
}
131+
132+
}
133+
}
134+
return filenames, nil
135+
}

questions.data

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)