mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
[Feature] FTP stat file download
This commit is contained in:
parent
9ced864a48
commit
c3ad00d193
41
app/t2-stat-parser/ftp.go
Normal file
41
app/t2-stat-parser/ftp.go
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
//ShellToUse is...
|
||||||
|
const ShellToUse = "sh"
|
||||||
|
|
||||||
|
func Shellout(command string) (error, string, string) {
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
cmd := exec.Command(ShellToUse, "-c", command)
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
|
return err, stdout.String(), stderr.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func initFTP() {
|
||||||
|
|
||||||
|
ftpHOST := os.Getenv("FTP_HOST")
|
||||||
|
ftpUSER := os.Getenv("FTP_USER")
|
||||||
|
ftpPW := os.Getenv("FTP_PW")
|
||||||
|
|
||||||
|
fmt.Println("Downloading stat files from", ftpHOST)
|
||||||
|
|
||||||
|
err, out, errout := Shellout("wget --recursive -nH --cut-dirs=4 --user=" + ftpUSER + " --no-parent --password=" + ftpPW + " -P /app/serverStats/stats/ ftp://" + ftpHOST + "/" + ftpHOST + "_port_28000/classic/serverStats/stats/")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error: %v\n", err)
|
||||||
|
}
|
||||||
|
fmt.Println("--- FTP stdout ---")
|
||||||
|
fmt.Println(out)
|
||||||
|
fmt.Println("--- FTP stderr ---")
|
||||||
|
fmt.Println(errout)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
/*
|
/*
|
||||||
|
[ T2 Stat Parser for DarkTiger's Stats]
|
||||||
|
|
||||||
Parser for DarkTiger's T2 Server Stats
|
A player stat parser that retrieves stat files via FTP
|
||||||
|
and imports them into a postgres db daily
|
||||||
|
|
||||||
[TODO]
|
|
||||||
- Read Additional GameTypes on the fly
|
|
||||||
- Use go modules
|
|
||||||
- Update to v4 SQL driver
|
|
||||||
- Ability to download stat files from remote server via FTP
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Starting FTP stat file download")
|
||||||
|
initFTP()
|
||||||
|
fmt.Println("Stat files downloaded!")
|
||||||
|
|
||||||
|
fmt.Println("Starting stat parser")
|
||||||
initParser()
|
initParser()
|
||||||
|
fmt.Println("All done!")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
Parser for DarkTiger's T2 Server Stats
|
Parser for DarkTiger's T2 Server Stats
|
||||||
|
|
||||||
[TODO]
|
[TODO]
|
||||||
- Read Additional GameTypes on the fly
|
|
||||||
- Use go modules
|
|
||||||
- Update to v4 SQL driver
|
- Update to v4 SQL driver
|
||||||
- Ability to download stat files from remote server via FTP
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue