From 90bc1df230206fe4ffce0629974ae8cd7c1d376a Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Sat, 25 Mar 2023 17:33:51 -0500 Subject: [PATCH] Use env variables for RPC auth --- README.md | 2 +- main.go | 6 +++--- template.html | 17 +---------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index eb9d241..7b4d8a8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ For other people using this, change the stylesheet in `template.html` to your pr transmissionbt, err := transmissionrpc.New("", "username", "password", nil) ``` -My personal use case for this involves running the Go binary `go-transmission-stats` on a systemd timer that triggers the corresponding service every 12 hours. The systemd service looks like this: +My personal use case for this involves running the Go binary `go-transmission-stats` on a systemd timer that triggers the corresponding service every 12 hours. First build the binary: diff --git a/main.go b/main.go index 938cbd5..ba4b8dd 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ type TorrentStatsPageData struct { } func main() { - transmissionbt, err := transmissionrpc.New("", "", "", nil) + transmissionbt, err := transmissionrpc.New(os.Getenv("RPC_HOST"), os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWD"), nil) if err != nil { panic(err) } @@ -103,7 +103,7 @@ func main() { {Label: "Uploaded/Downloaded ratio", Value: fmt.Sprintf("%d", *&stats.CurrentStats.UploadedBytes / *&stats.CurrentStats.DownloadedBytes)}, {Label: "Files added", Value: fmt.Sprintf("%d", *&stats.CurrentStats.FilesAdded)}, {Label: "Session count", Value: fmt.Sprintf("%d", *&stats.CurrentStats.SessionCount)}, - {Label: "Seconds active", Value: convertTime(*&stats.CurrentStats.SecondsActive)}, + {Label: "Time active", Value: convertTime(*&stats.CurrentStats.SecondsActive)}, } cumulativeStats := []SessionStat{ @@ -112,7 +112,7 @@ func main() { {Label: "Uploaded/Downloaded ratio", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.UploadedBytes / *&stats.CumulativeStats.DownloadedBytes)}, {Label: "Files added", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.FilesAdded)}, {Label: "Session count", Value: fmt.Sprintf("%d", *&stats.CumulativeStats.SessionCount)}, - {Label: "Seconds active", Value: convertTime(*&stats.CumulativeStats.SecondsActive)}, + {Label: "Time active", Value: convertTime(*&stats.CumulativeStats.SecondsActive)}, } var torrentInfo = []TorrentInfo{} diff --git a/template.html b/template.html index bca2590..b002206 100644 --- a/template.html +++ b/template.html @@ -5,22 +5,7 @@ - +

Torrent Stats