Skip to content

Commit

Permalink
Add before action for wordChainCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
wuqinqiang committed Feb 21, 2023
1 parent ec79bb6 commit 645ce83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@
Hello Word是我在背单词的过程中想到的一个想法。在学习英语时,词汇量是非常重要的。仅仅死记硬背单词,没有语境感,效率是很低的。虽然一些应用程序可以根据单词的多个词义为单词组成一小段句子,稍微增强语境感。但是单词仍然过于零散。因此,我们是否可以将每天背诵的多个单词组合成一段小短文,以便复习这一批单词呢?这就是Hello Word的初衷。当然,ChatGPT API是实现这个想法的工具。
除此之外,还配套了几个周边小游戏。



### 初始化
#### 环境变量

```shell
HELLO_WORD_PATH # 默认不配置在 ~/.helloword
```

#### 配置文件
配置文件在conf/conf.yml里。
```yaml
gptToken: "xx" #要使用短语推送功能这个是必须的!!!可以先注册openai,然后到platform.openai.com平台申请key

collector:
bbdc: # 不背单词cookie,配置了可以同步不背单词的生词表。
cookie:

# --------------------- Notification Configuration ---------------------
notify: # 通知配置,目前支持telegram,dingtalk,lark可以全配,那么所有平台都会推送一遍
# telegram:
# token: xxxxxxx # Bot Token
# chat_id: -123456789 # Channel / Group ID
# dingtalk:
# webhook: "https://oapi.dingtalk.com/robot/send?access_token=xxxx"
# secret: "" # sign secret if set
lark:
webhook: "xx"
```
### 单词短语推送器
指定单词数量,随机选择单词,生成一段小短文,推送到用户指定平台。
Expand Down Expand Up @@ -33,8 +64,10 @@ go run main.go daemon --files="CET4.txt,CET6.txt" --spec="@every 10s" --word-num

使用
```shell
go run main.go games chain
go run main.go games chain --files="CET4.txt,CET6.txt"
```
**参数说明**
- files 可选,如上

![example](./library/word_chain.png)

Expand Down
22 changes: 22 additions & 0 deletions cmd/games.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"strings"

"github.com/wuqinqiang/helloword/collector"
"github.com/wuqinqiang/helloword/collector/file"

"github.com/wuqinqiang/helloword/games"

"github.com/wuqinqiang/helloword/dao"
Expand All @@ -24,6 +27,25 @@ var GamesCmd = &cli.Command{

var wordChainCmd = &cli.Command{
Name: "chain",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "files",
Usage: "传入要导入的Library目录下的单词文件。例如你可以导入一个文件 damon --files=CET4.txt" +
"或者多个文件用逗号隔开,damon --files=CET4.txt,CET6.txt",
},
},
Before: func(cctx *cli.Context) error {
var collectors []collector.Collector
files := "CET4.txt"
if cctx.String("files") != "" {
files = cctx.String("files")
}

collectors = append(collectors, file.New(files))
importer := collector.NewImporter(collectors...)

return importer.Import(cctx.Context)
},
Action: func(cctx *cli.Context) error {

list, err := dao.NewWord().GetList(cctx.Context)
Expand Down
2 changes: 1 addition & 1 deletion db/sqlite/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Settings struct {
func New(path string) *Settings {
settings := DefaultSettings
if path == "" {
path = "~/.bridge"
path = "~/.helloword"
}
settings.path = path
return settings
Expand Down

0 comments on commit 645ce83

Please sign in to comment.