-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·138 lines (103 loc) · 2.86 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"fmt"
"github.com/sirupsen/logrus"
"handle-csv/handle"
"io/ioutil"
"log"
"os/exec"
"strings"
)
const (
readDic = "collection"
outputDic = "output"
scriptPath = "./generator-article"
)
func main() {
patchRow := []int{0, 1}
// todo 三个月调用relingo生成一次文件
fmt.Println("start--")
files := searchFile(readDic)
var allWord []string
for _, file := range files {
continueinfo := declareUpdate(file)
if continueinfo {
continue
}
// todo 先获取到当前file的单词,写入新文件
words := handle.GetWordFromFileAndWrite2CSV(readDic, file, outputDic, patchRow, allWord)
// todo 当前单词和存起来的所有单词差集,
// 单词差级
words = handle.UniqueResource(words, allWord)
// todo 文件过滤掉后,单词也需要过滤掉(单词还是需要读的,读完后过滤然后再生成文章)
logrus.Infof("文件名:《%s》,单词组:%v,一共:%v 个\n", file, words, len(words))
appendNewArticle(words, file)
allWord = append(allWord, words...)
}
if len(allWord) == 0 {
logrus.Infof("没有新文件,请检查colleation文件夹")
} else {
logrus.Infof("一共%v个单词\n", len(allWord))
randomWord := handle.RandomWord(allWord)
logrus.Infof("随机单词:%s", optimizeSlice(randomWord))
}
//filePath, _ := fmt.Println("%s%s", path, fileName)
}
func optimizeSlice(randomWord []string) []string {
// 创建一个新的切片,用于存储非空元素
filteredSlice := make([]string, 0)
// 遍历切片,将非空元素添加到新的切片中
for _, s := range randomWord {
if s != "" {
filteredSlice = append(filteredSlice, s)
}
}
// 输出处理后的结果
return filteredSlice
}
func declareUpdate(file string) bool {
// todo 再获取已有的文件
existFiles := searchFile(outputDic)
// todo 选择差集
continueinfo := false
// 文件差
for _, existfile := range existFiles {
if file == existfile {
continueinfo = true
}
}
return continueinfo
}
func appendNewArticle(words []string, file string) {
article := GeneratorArticle(words)
//todo 每个文章生成对应日期的文件夹里
handle.WriteArticle2CSV(outputDic, file, article)
}
func GeneratorArticle(arg1 []string) string {
arg1String := strings.Join(arg1, ",")
args := []string{scriptPath, arg1String}
// 执行 脚本
cmd := exec.Command(args[0], args[1:]...)
output, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
// 输出 Python 脚本的执行结果
return string(output)
}
func searchFile(path string) []string {
// 指定文件夹路径
files, err := ioutil.ReadDir(path)
if err != nil {
log.Fatal(err)
}
var fileNames []string
// 遍历文件列表并输出文件名称
for _, file := range files {
if !file.IsDir() {
fileName := file.Name()
fileNames = append(fileNames, fileName)
}
}
return fileNames
}