1
0
mirror of https://github.com/mgerb/spaghet synced 2026-01-08 11:52:49 +00:00
This commit is contained in:
2019-04-27 10:58:56 -05:00
commit fe761b5b26
3 changed files with 90 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.html
*.exe
*.txt
dist

76
main.go Executable file
View File

@@ -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, "<b>")
if len(i) > 1 {
suf := strings.Split(i[1], "</b>")
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
}

10
makefile Normal file
View File

@@ -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