diff --git a/.gitignore b/.gitignore index e0f7ecc..057b692 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,10 @@ go.work go.work.sum +# Command directories +SlackMessages +slack_records.csv + # IDE directories and misc. files .idea .vscode diff --git a/Makefile b/Makefile index 1c050c8..33df1d4 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,7 @@ lint: go fmt ./... go vet ./... staticcheck ./... + +.PHONY: parse-slack-data +parse-slack-data: + go run ./cmd/slackMessageParser/main.go diff --git a/README.md b/README.md index 223d684..15ac263 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,19 @@ Various scripts written in Golang. ## Scripts ### Slack Message Parser +This tool is used to parse the `json`-formatted data that comes from [exporting Slack workspace data](https://slack.com/help/articles/201658943-Export-your-workspace-data) into a `csv` file named: `slack_records.csv`. +`csv` format: +TimeStamp,UserID,UserName,RealName,MessageType,Text,Attachments,Files + +| TimeStamp | UserID | UserName | RealName | MessageType | Text | Attachments | Files | +|:---------:|:------:|:--------:|:--------:|:-----------:|:------:|:-----------:|:--------:| +| string | string | string | string | string | string | []string | []string | #### Instructions -```console -cp [YOUR_ARCHIVE_PATH_HERE]/*.json ./SlackMessages/ -go run slack_message_parser.go -``` +1. Move your files to the `SlackMessages` directory. + ```console + mkdir -p ./SlackMessages + cp [SLACK_WORKSPACE_DATA_PATH_HERE]/*.json ./SlackMessages/ + ``` +2. Run the Slack message parser using the command: `make parse-slack-data`. diff --git a/cmd/slackMessageParser/main.go b/cmd/slackMessageParser/main.go index aea22af..f721755 100644 --- a/cmd/slackMessageParser/main.go +++ b/cmd/slackMessageParser/main.go @@ -74,11 +74,11 @@ type CSVRecord struct { } func main() { - if _, err := os.Stat("../../SlackMessages"); os.IsNotExist(err) { + if _, err := os.Stat("./SlackMessages"); os.IsNotExist(err) { log.Fatal("the ./SlackMessages directory does not exist") } - files, err := filepath.Glob("../../SlackMessages/*.json") + files, err := filepath.Glob("./SlackMessages/*.json") if err != nil { log.Fatal(err) } @@ -156,7 +156,7 @@ func main() { csvRecords = append(csvRecords, record) } - csvFile, err := os.Create("../../slack_records.csv") + csvFile, err := os.Create("slack_records.csv") if err != nil { log.Fatal(err) }