Skip to content

Commit

Permalink
Merge pull request #53 from oarinv/neo
Browse files Browse the repository at this point in the history
feat:合并配置
  • Loading branch information
ludoux authored May 17, 2023
2 parents 6b03207 + 1074b8e commit 8547f2a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
Binary file modified README.assets/edit_config_ini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed README.assets/edit_cookies_json.png
Binary file not shown.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

## 使用指引

1. 确保 `config.ini` `cookies.json` 文件存在且与可执行文件在同一目录下(平级关系)
2. 修改 `config.ini` `cookies.json` 内的 `MODIFY_ME` 内容为相关内容
1. 确保 `config.ini` 文件存在且与可执行文件在同一目录下(平级关系)
2. 修改 `config.ini` 内的 `MODIFY_ME` 内容为相关内容
3. 带参数(参数为帖子 tid)运行可执行文件,如 (Linux) `./app 5935947` 或者 (Windows) `.\app.exe 5935947`

### 图片快速指引

![修改config.ini](README.assets/edit_config_ini.png)
![修改cookies.json](README.assets/edit_cookies_json.png)
<img src="README.assets/edit_config_ini.png" width="700px" alt="修改config.ini">

## 资瓷与不资瓷格式说明

Expand Down
2 changes: 2 additions & 0 deletions assets/config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[network]
base_url="https://bbs.nga.cn"
ua="""MODIFY_ME"""
ngaPassportUid="MODIFY_ME"
ngaPassportCid="MODIFY_ME"
thread=2

[post]
Expand Down
1 change: 0 additions & 1 deletion assets/cookies.json

This file was deleted.

9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"

"github.com/ludoux/ngapost2md/nga"
"github.com/spf13/cast"
Expand All @@ -18,6 +19,14 @@ func main() {
fmt.Printf("Fail to find or read config.ini file: %v", err)
os.Exit(1)
}

//Cookie
var ngaPassportUid = cfg.Section("network").Key("ngaPassportUid").String()
var ngaPassportCid = cfg.Section("network").Key("ngaPassportCid").String()
var cookie strings.Builder
cookie.WriteString("ngaPassportUid="+ngaPassportUid+";"+"ngaPassportCid="+ngaPassportCid)
nga.COOKIE = cookie.String()

nga.BASE_URL = cfg.Section("network").Key("base_url").String()
nga.UA = cfg.Section("network").Key("ua").String()
//默认线程数为2,仅支持1~3
Expand Down
12 changes: 2 additions & 10 deletions nga/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package nga

import (
"fmt"
"log"

"github.com/imroc/req/v3"
cookiejar "github.com/orirawlings/persistent-cookiejar"
)

type NgaClient struct {
Expand All @@ -16,18 +14,12 @@ type NgaClient struct {
var Client *NgaClient
var BASE_URL string
var UA string
var COOKIE string

func NewNgaClient() *NgaClient {
jar, err := cookiejar.New(&cookiejar.Options{
Filename: "cookies.json",
})
if err != nil {
log.Fatalf("failed to create persistent cookiejar: %s\n", err.Error())
}
c := req.C().
SetCookieJar(jar).
SetBaseURL(BASE_URL).
SetCommonHeader("Referer", BASE_URL).
SetCommonHeader("Cookie",COOKIE).
SetUserAgent(UA).
// EnableDump at the request level in request middleware which dump content into
// memory (not print to stdout), we can record dump content only when unexpected
Expand Down

0 comments on commit 8547f2a

Please sign in to comment.