Skip to content

Commit

Permalink
v0.1.2 添加源的响应速度测试与建议
Browse files Browse the repository at this point in the history
  • Loading branch information
howie6879 committed Sep 7, 2017
1 parent 298f25e commit 2e9d7c1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./release/NIYT.linux
# 运行下载的`NIYT.linux` 这样就可以直接执行使用
./NIYT.linux

# 若提示无法运行,例如在mac下
chmod a+x NIYT.mac
# 再运行即可
./NIYT.mac

```

首先输入小说名称,调用第三方搜索,利用本地`json`文件解析,终端就会显示小说源:
首先输入小说名称,调用第三方搜索,终端就会显示小说源:

![demo01](./images/demo01.jpg)

利用`get 0`进入第一个源,获取最新章节:
利用`get 2`进入提示相应最快的源,获取最新章节:
![demo02](./images/demo02.jpg)

选择章节进行阅读,如阅读最新章节,`get 0`:
Expand Down
12 changes: 12 additions & 0 deletions common/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ func RequestURL(url string) (*http.Response, error) {
return response, err
}

// QuickestURL return the quickest response
func QuickestURL(index int, url string) int {
// start := time.Now()
_, err := http.Get(url)
if err != nil {
return -1
}
// timeUsed := strconv.FormatFloat(time.Since(start).Seconds(), 'f', 6, 64)
// fmt.Println(url, timeUsed)
return index
}

// DetectBody gbk convert to utf-8
func DetectBody(body []byte) string {
var bodyString string
Expand Down
Binary file modified images/demo01.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/demo02.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/demo03.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/demo04.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/howie6879/NIYT/common"
"github.com/howie6879/NIYT/fetcher"
"github.com/modood/table"
)
Expand All @@ -16,6 +17,7 @@ type novleDemo struct {
Index int
Name string
URL string
Speed string
}

type chapterDemo struct {
Expand Down Expand Up @@ -61,10 +63,18 @@ func main() {
resultData, _ := fetcher.FetchResult(query)
if len(resultData) > 0 {
var novelData []novleDemo
quickest := make(chan int, len(resultData))
for index, data := range resultData {
novelData = append(novelData, novleDemo{Index: index, Name: data.Title, URL: data.URL})
go func() {
quickest <- common.QuickestURL(index, data.URL)
}()
}
currentIndex := <-quickest
if currentIndex != -1 {
novelData[currentIndex].Speed = "响应最快"
table.Output(novelData)
}
table.Output(novelData)
for {
flag := false
fmt.Fprintf(color.Output, "$ %s", color.CyanString(name+" 源 ~ "))
Expand Down

0 comments on commit 2e9d7c1

Please sign in to comment.