Flawless Victory
Signed-off-by: Aoi K <koizumi.aoi@kyoko-project.wer.ee> git-svn-id: file:///srv/svn/repo/suwako/trunk@3 0b558ee1-521d-8b46-a41b-40029c97c055
This commit is contained in:
3
README
Normal file
3
README
Normal file
@@ -0,0 +1,3 @@
|
||||
stcli-go
|
||||
========
|
||||
Command-line client for SimplyTranslate in Go.
|
||||
2
go.mod
2
go.mod
@@ -1,3 +1,5 @@
|
||||
module git.kyoko-project.wer.ee/koizumi.aoi/stcli-go
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/astaxie/bat v0.0.2
|
||||
|
||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/astaxie/bat v0.0.2 h1:EOl52CfuFEnFqu9/mzex93mh7JWdtEGbGQlpih00GWQ=
|
||||
github.com/astaxie/bat v0.0.2/go.mod h1:poAI7wDJd5LpfwfBXsGWYIqmVO66dhBx31zhn0ZXdMI=
|
||||
47
main.go
47
main.go
@@ -1,11 +1,12 @@
|
||||
// Yet another command-line client for SimplyTranslate
|
||||
// All Rites Reversed (ĸ) 3188 Aoi Koizumi, Czar of KST, mutefall, shokara
|
||||
// All Rites Reversed (ĸ) 3188 Aoi Koizumi, Czar of KST, mutefall, shokara, Baobab
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -14,14 +15,17 @@ import (
|
||||
|
||||
var (
|
||||
instanceURL string
|
||||
engine string
|
||||
fromLang string
|
||||
toLang string
|
||||
text string
|
||||
engine string
|
||||
fromLang string
|
||||
toLang string
|
||||
text string
|
||||
)
|
||||
|
||||
type TranslateAPI struct {
|
||||
OutText string `json:"translated-text"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Point flags to variables
|
||||
flag.StringVar(&instanceURL, "i", "https://translate.bus-hit.me/api/translate/", "Instance for SimplyTranslate (default: https://translate.bus-hit.me)")
|
||||
flag.StringVar(&engine, "e", "google", "Translation engine (default: google)")
|
||||
flag.StringVar(&fromLang, "f", "auto", "Source language (default: auto)")
|
||||
@@ -29,10 +33,8 @@ func init() {
|
||||
flag.StringVar(&text, "T", "", "Text to translate (default: unset)")
|
||||
}
|
||||
func main() {
|
||||
// Start parsing
|
||||
flag.Parse()
|
||||
|
||||
// I assume this works?
|
||||
if len(text) == 0 {
|
||||
log.Printf("Text to translate is required. \n")
|
||||
os.Exit(1)
|
||||
@@ -40,26 +42,25 @@ func main() {
|
||||
log.Printf("Target language is missing. \n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Hand-craft the request URL
|
||||
queryURL := instanceURL + "?engine=" + engine + "&from=" + fromLang + "&to=" + toLang + "&text=" + text
|
||||
|
||||
// Make a request to said URL
|
||||
resp, err1 := http.Get(queryURL)
|
||||
var queryURL = instanceURL + "?engine=" + engine + "&from=" + fromLang + "&to=" + toLang + "&text=" + text
|
||||
|
||||
req, err1 := http.Get(queryURL)
|
||||
var o TranslateAPI
|
||||
|
||||
if err1 != nil {
|
||||
log.Printf("Request could not be processed due to %s\n", err1)
|
||||
log.Printf("Couldn't process request %s\n", err1)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
output, err2 := io.ReadAll(resp.Body)
|
||||
defer req.Body.Close()
|
||||
resp, err2 := io.ReadAll(req.Body)
|
||||
|
||||
if err2 != nil {
|
||||
panic(errno)
|
||||
log.Printf("Couldn't process response %s\n", err2)
|
||||
}
|
||||
|
||||
// Well...
|
||||
fmt.Printf("Input: %s \n", text)
|
||||
fmt.Printf("Output: %s \n", output)
|
||||
_ = json.Unmarshal([]byte(resp), &o)
|
||||
|
||||
fmt.Printf("Input: %s (%s)\n",text,fromLang)
|
||||
fmt.Printf("Output: %s (%s)\n",o.OutText,toLang)
|
||||
}
|
||||
|
||||
28
stcli-go.1
Normal file
28
stcli-go.1
Normal file
@@ -0,0 +1,28 @@
|
||||
.Dd Aftermath 55, 3188
|
||||
.Dt STCLI-GO 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm stcli-go
|
||||
.Nd Command-line client for SimplyTranslate in Go
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Fl e Ar engine
|
||||
.Fl f Ar from
|
||||
.Fl i Ar instance
|
||||
.Fl t Ar to
|
||||
.Fl T Ar text
|
||||
.Sh DESCRIPTION
|
||||
Self-explanatory, besides, this was made as
|
||||
a rewrite from a shell script that had curl
|
||||
and awk for dependencies. It fully serves
|
||||
as a drop-in replacement.
|
||||
.Sh AUTHORS
|
||||
.An Aoi K. Aq Mt koizumi.aoi@kyoko-project.wer.ee
|
||||
.Pp
|
||||
.An Czar of KST Aq Mt czar@kalli.st
|
||||
.Pp
|
||||
.An mutefall
|
||||
.Pp
|
||||
.An Shokara Kou Aq Mt kou@clearnet.fqdn
|
||||
.Pp
|
||||
.An Baobab Aq Mt baobab@honeypot.im
|
||||
Reference in New Issue
Block a user