diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-03 08:40:43 +0000 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-03 08:40:43 +0000 |
| commit | 1a14309e212a697bae8acd4ddb17723b0f6670a6 (patch) | |
| tree | ea6a255e6170c31b2928f164e4b3329caec091b0 /backend/parser | |
| parent | feat: add moderator status into jwt token (diff) | |
| download | lphub-1a14309e212a697bae8acd4ddb17723b0f6670a6.tar.gz lphub-1a14309e212a697bae8acd4ddb17723b0f6670a6.tar.bz2 lphub-1a14309e212a697bae8acd4ddb17723b0f6670a6.zip | |
feat: parser for getting portal and tick count (#42)
Former-commit-id: 1619ece868b7009a661dcc3b622746cc09981042
Diffstat (limited to 'backend/parser')
| -rw-r--r-- | backend/parser/parser.go | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/backend/parser/parser.go b/backend/parser/parser.go index 6f9a24f..040b94a 100644 --- a/backend/parser/parser.go +++ b/backend/parser/parser.go | |||
| @@ -1,7 +1,42 @@ | |||
| 1 | package parser | 1 | package parser |
| 2 | 2 | ||
| 3 | import "mime/multipart" | 3 | import ( |
| 4 | "bufio" | ||
| 5 | "fmt" | ||
| 6 | "os/exec" | ||
| 7 | "strconv" | ||
| 8 | "strings" | ||
| 9 | ) | ||
| 4 | 10 | ||
| 5 | func ProcessDemo(demo *multipart.FileHeader) (scoreCount int, scoreTime int, err error) { | 11 | func ProcessDemo(demoPath string) (int, int, error) { |
| 6 | return 0, 0, nil | 12 | cmd := exec.Command("bash", "-c", fmt.Sprintf(`echo "FEXBash" && ./parser %s`, demoPath)) |
| 13 | stdout, err := cmd.StdoutPipe() | ||
| 14 | if err != nil { | ||
| 15 | return 0, 0, err | ||
| 16 | } | ||
| 17 | cmd.Start() | ||
| 18 | scanner := bufio.NewScanner(stdout) | ||
| 19 | var cmTicks, portalCount int | ||
| 20 | for scanner.Scan() { | ||
| 21 | line := scanner.Text() | ||
| 22 | if strings.Contains(line, "CM ticks") { | ||
| 23 | cmTicksStr := strings.TrimSpace(strings.Split(line, ":")[1]) | ||
| 24 | cmTicks, err = strconv.Atoi(cmTicksStr) | ||
| 25 | if err != nil { | ||
| 26 | return 0, 0, err | ||
| 27 | } | ||
| 28 | } | ||
| 29 | if strings.Contains(line, "Portal count") { | ||
| 30 | portalCountStr := strings.TrimSpace(strings.Split(line, ":")[1]) | ||
| 31 | portalCount, err = strconv.Atoi(portalCountStr) | ||
| 32 | if err != nil { | ||
| 33 | return 0, 0, err | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | err = cmd.Wait() | ||
| 38 | if err != nil { | ||
| 39 | return 0, 0, err | ||
| 40 | } | ||
| 41 | return cmTicks, portalCount, nil | ||
| 7 | } | 42 | } |