-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilterslackmessages.go
56 lines (44 loc) · 1.28 KB
/
filterslackmessages.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
package main
import (
"bufio"
"fmt"
"os"
"./slackmessage"
"./utilities"
)
var (
root string
files []string
err error
userID string
userMessages []string
)
// function takes 2 args full path to the folder containing all the slack messages dump and the slack userid of the user usually in a format of UXXXXX
func main() {
args := os.Args[1:]
if len(args) > 0 {
root := args[0]
userID := args[1]
//Open file for writing the output
outFile, err := os.Create("./" + userID + ".txt")
utilities.Check(err)
w := bufio.NewWriter(outFile)
//build list of files within the root directory
files, err = utilities.FilePathWalkDir(root)
utilities.Check(err)
//Loop through each file and append the slice of strings returned from the ParseAndFilterSlackMessages function
for _, file := range files {
fmt.Println("Working on ", file)
userMessages = append(userMessages, slackmessage.ParseAndFilterSlackMessages(file, userID)...)
}
//write out the file of the collective slice of string containing the messages from the filtered user
for _, message := range userMessages {
outString := message + "\n"
_, err = w.WriteString(outString)
utilities.Check(err)
}
w.Flush()
} else {
fmt.Println("Not enough args provided.")
}
}