From fe761b5b269d51248c488f1860841220520c91c7 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Sat, 27 Apr 2019 10:58:56 -0500 Subject: [PATCH] init --- .gitignore | 4 +++ main.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 10 +++++++ 3 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100755 main.go create mode 100644 makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebfcd0f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.html +*.exe +*.txt +dist diff --git a/main.go b/main.go new file mode 100755 index 0000000..a8ddc02 --- /dev/null +++ b/main.go @@ -0,0 +1,76 @@ +package main + +import ( + "io/ioutil" + "log" + "os" + "os/signal" + "strconv" + "strings" + "syscall" +) + +var nameCount = map[string]int{} + +func main() { + + files, err := ioutil.ReadDir("./") + + if err != nil { + logError(err) + } + + for _, f := range files { + fileName := f.Name() + if strings.HasSuffix(fileName, ".html") { + processFile(fileName) + } + } + + output := []string{} + + for key, val := range nameCount { + if !strings.HasPrefix(key, "The account has disconnected") { + output = append(output, key+" "+strconv.Itoa(val)) + } + } + + err = ioutil.WriteFile("output.txt", []byte(strings.Join(output, "\n")), 0755) + + if err != nil { + logError(err) + } +} + +func processFile(name string) { + + file, err := ioutil.ReadFile(name) + + if err != nil { + logError(err) + } + + fileContent := string(file) + + lines := strings.Split(fileContent, "\n") + + for _, line := range lines { + i := strings.Split(line, "") + + if len(i) > 1 { + suf := strings.Split(i[1], "") + if len(suf) > 1 { + out := strings.TrimSpace(suf[0]) + out = strings.Trim(out, "\n") + nameCount[out]++ + } + } + } +} + +func logError(err error) { + log.Println(err) + sc := make(chan os.Signal, 1) + signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) + <-sc +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..3232cb9 --- /dev/null +++ b/makefile @@ -0,0 +1,10 @@ +build: + go build -o ./dist/spaghet ./main.go + +windows: + GOOS=windows GOARCH=386 go build -o ./dist/spaghet.exe ./main.go + +clean: + rm -rf ./dist + +all: build windows