project structure started
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package eve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func suffixTrim(s, suffix string) string {
|
||||
if strings.HasSuffix(s, suffix) {
|
||||
s = s[:len(s)-len(suffix)]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
var filesFound []string
|
||||
var filesPotential []string
|
||||
var searchPath []string
|
||||
|
||||
func FileSearchUnix() []string {
|
||||
fmt.Println("looking for chat log files..")
|
||||
|
||||
searchPath = append(searchPath, "~/.local/share/Steam/steamapps/compatdata/8500/pfx/drive_c/users/steamuser/My Documents/EVE/logs/Chatlogs")
|
||||
|
||||
userName, _ := user.Current()
|
||||
homeDir := userName.HomeDir
|
||||
|
||||
for _, d := range searchPath {
|
||||
|
||||
// if has trailing slash, remove it
|
||||
d = suffixTrim(d, "/")
|
||||
|
||||
// do a unix like expansion if the path starts like `~/`
|
||||
if strings.HasPrefix(d, "~/") {
|
||||
d = filepath.Join(homeDir, d[2:])
|
||||
}
|
||||
f, err := os.Open(d)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
files, err := f.Readdir(-1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
fullFilePath := fmt.Sprintf("%v/%v", d, file.Name())
|
||||
filesPotential = append(filesPotential, fullFilePath)
|
||||
}
|
||||
|
||||
}
|
||||
return filesPotential
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package eve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// GetActiveChannels will parse a list of files for ones with today's timestamps
|
||||
// This really just returns a list of human-readable channel names so
|
||||
// there will be some eve specific logic to guess the channel name
|
||||
// ..also it'll ignore "Private Chats" and any without todays YYYYMMDD timestamp
|
||||
func GetActiveChannels(fileList []string) []string {
|
||||
|
||||
var chanList []string
|
||||
var candidateFiles []string
|
||||
t := time.Now()
|
||||
|
||||
layout := "20060102"
|
||||
todayString := fmt.Sprintf(t.Format(layout))
|
||||
|
||||
for _, file := range fileList {
|
||||
if !strings.Contains(file, "Corp") {
|
||||
if !strings.Contains(file, "Alliance") {
|
||||
if !strings.Contains(file, "Local") {
|
||||
if !strings.Contains(file, "Private Chat") {
|
||||
if strings.Contains(file, todayString) {
|
||||
candidateFiles = append(candidateFiles, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for _, file := range candidateFiles {
|
||||
fmt.Println(file)
|
||||
chanList = append(chanList, chatNameFromFile(file))
|
||||
}
|
||||
|
||||
fmt.Printf("searched %v files.. found %v chanels\n", len(fileList), len(chanList))
|
||||
|
||||
return chanList
|
||||
}
|
||||
|
||||
|
||||
func chatNameFromFile(fname string) string {
|
||||
a := strings.Split(fname, "/")
|
||||
b := a[len(a)-1] // returns file name without any "/" prefixes
|
||||
|
||||
// create a rune of the file name only
|
||||
c := []rune(b)
|
||||
|
||||
// count how many characters.. minus the 20 at the end
|
||||
// EG:
|
||||
// "Rookie Help_20191218_161504.txt"
|
||||
// becomes: "Rookie Help"
|
||||
chars := len(c) - 20
|
||||
myShortString := string(c[0:chars])
|
||||
|
||||
return myShortString
|
||||
}
|
||||
|
||||
|
||||
// TODO: run a uniq pass on the list of channels maybe
|
||||
//func unique(intSlice []int) []int {
|
||||
// keys := make(map[int]bool)
|
||||
// list := []int{}
|
||||
// for _, entry := range intSlice {
|
||||
// if _, value := keys[entry]; !value {
|
||||
// keys[entry] = true
|
||||
// list = append(list, entry)
|
||||
// }
|
||||
// }
|
||||
// return list
|
||||
//}
|
||||
//
|
||||
//func uniqueTest() {
|
||||
// intSlice := []int{1,5,3,6,9,9,4,2,3,1,5}
|
||||
// fmt.Println(intSlice)
|
||||
// uniqueSlice := unique(intSlice)
|
||||
// fmt.Println(uniqueSlice)
|
||||
//}
|
||||
Reference in New Issue
Block a user