wip
This commit is contained in:
@@ -59,3 +59,42 @@ func FileSearchUnix() []string {
|
||||
return filesPotential
|
||||
}
|
||||
|
||||
// returns paths with eve chat log files
|
||||
func PathSearch() []string {
|
||||
var pathsWithLogs []string
|
||||
fmt.Println("PathSearch 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)
|
||||
}
|
||||
if len(files) > 0 {
|
||||
pathsWithLogs = append(pathsWithLogs, d)
|
||||
}
|
||||
fmt.Println(len(files))
|
||||
|
||||
}
|
||||
return pathsWithLogs
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package eve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// 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
|
||||
@@ -35,7 +33,6 @@ func GetActiveChannels(fileList []string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for _, file := range candidateFiles {
|
||||
fmt.Println(file)
|
||||
chanList = append(chanList, chatNameFromFile(file))
|
||||
@@ -46,10 +43,30 @@ func GetActiveChannels(fileList []string) []string {
|
||||
return chanList
|
||||
}
|
||||
|
||||
// IsCurrentLog will return True if the logfile has a timestamp that looks like
|
||||
// Today or Yesterdays (there is an assumption that the eve client won't be run for more than 24hrs strait)
|
||||
func IsCurrentLog(file string) bool {
|
||||
timeToday := time.Now()
|
||||
timeYesterday := time.Now().Add(-24 * time.Hour)
|
||||
layout := "20060102"
|
||||
todayString := fmt.Sprintf(timeToday.Format(layout))
|
||||
yesterdayString := fmt.Sprintf(timeYesterday.Format(layout))
|
||||
fileNameSplit := strings.Split(file, "/")
|
||||
fileName := fileNameSplit[len(fileNameSplit)-1] // returns file name without any "/" prefixes
|
||||
|
||||
if strings.Contains(fileName, todayString) {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(fileName, yesterdayString) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func chatNameFromFile(fname string) string {
|
||||
a := strings.Split(fname, "/")
|
||||
b := a[len(a)-1] // returns file name without any "/" prefixes
|
||||
b := a[len(a)-1] // returns file name without any "/" prefixes
|
||||
|
||||
// create a rune of the file name only
|
||||
c := []rune(b)
|
||||
@@ -64,7 +81,6 @@ func chatNameFromFile(fname string) string {
|
||||
return myShortString
|
||||
}
|
||||
|
||||
|
||||
// TODO: run a uniq pass on the list of channels maybe
|
||||
//func unique(intSlice []int) []int {
|
||||
// keys := make(map[int]bool)
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package eve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpcloud/tail"
|
||||
"github.com/radovskyb/watcher"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Tail(file string) {
|
||||
// https://godoc.org/github.com/hpcloud/tail#Config
|
||||
t, err := tail.TailFile(
|
||||
file,
|
||||
tail.Config{
|
||||
Follow: true,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
//totalLines := 0
|
||||
//for _ = range t.Lines {
|
||||
// totalLines ++
|
||||
//}
|
||||
|
||||
//currentLine := 0
|
||||
for line := range t.Lines {
|
||||
//fmt.Printf("%v/%v", currentLine, totalLines)
|
||||
//currentLine ++
|
||||
//if currentLine > totalLines {
|
||||
fmt.Printf("##%v##%v##\n", line.Time, line.Text)
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// sends newly created files for tail'ing
|
||||
// WIP
|
||||
func WatchPath(dir string) {
|
||||
w := watcher.New()
|
||||
|
||||
w.FilterOps()
|
||||
w.FilterOps(watcher.Create, watcher.Remove, watcher.Write)
|
||||
|
||||
//r := regexp.MustCompile("^abc$")
|
||||
//w.AddFilterHook(watcher.RegexFilterHook(r, false))
|
||||
|
||||
// dispatch creation/removal events here
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case event := <-w.Event:
|
||||
// fmt.Println(event)
|
||||
fmt.Printf("%s (%s)\n", event.Path, event.Op)
|
||||
case err := <-w.Error:
|
||||
log.Fatalln(err)
|
||||
case <-w.Closed:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err := w.Add(dir); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
for path, f := range w.WatchedFiles() {
|
||||
fmt.Printf("%s: %s\n", path, f.Name())
|
||||
}
|
||||
|
||||
fmt.Println("=== startup complete ===")
|
||||
|
||||
// go func() {
|
||||
// w.Wait()
|
||||
// w.TriggerEvent(watcher.Create, nil)
|
||||
// }()
|
||||
|
||||
if err := w.Start(time.Millisecond * 100); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user