mirror of
https://codeberg.org/hyperreal/go-transmission-stats
synced 2024-11-25 12:13:42 +01:00
Add support for Gemini files
This commit is contained in:
parent
d5b6595e6f
commit
7f2d82bf18
@ -8,6 +8,8 @@ For other people using this, change the stylesheet in `template.html` to your pr
|
|||||||
export RPC_HOST="<ip address of Transmission server>"
|
export RPC_HOST="<ip address of Transmission server>"
|
||||||
export RPC_USER="<rpc username>"
|
export RPC_USER="<rpc username>"
|
||||||
export RPC_PASSWORD="<rpc password>"
|
export RPC_PASSWORD="<rpc password>"
|
||||||
|
export HTML_FILE="/path/to/html/output/file.html"
|
||||||
|
export GMI_FILE="/path/to/gemini/output/file.gmi"
|
||||||
```
|
```
|
||||||
|
|
||||||
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.
|
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.
|
||||||
@ -33,13 +35,15 @@ Description=go-transmission-stats service
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=sh -c '/usr/local/bin/go-transmission-stats > /home/user/public/html/torrentstats.html'
|
ExecStart=/usr/local/bin/go-transmission-stats
|
||||||
User=<your user>
|
User=<your user>
|
||||||
Group=<your user's group>
|
Group=<your user's group>
|
||||||
WorkingDirectory=/home/user/go-transmission-stats
|
WorkingDirectory=/home/user/go-transmission-stats
|
||||||
Environment="RPC_HOST=<ip address of Transmission server>"
|
Environment="RPC_HOST=<ip address of Transmission server>"
|
||||||
Environment="RPC_USER=<rpc username>"
|
Environment="RPC_USER=<rpc username>"
|
||||||
Environment="RPC_PASSWORD=<rpc password>"
|
Environment="RPC_PASSWORD=<rpc password>"
|
||||||
|
Environment="HTML_FILE=/path/to/html/output/file.html"
|
||||||
|
Environment="GMI_FILE=/path/to/gemini/output/file.gmi"
|
||||||
```
|
```
|
||||||
|
|
||||||
Create the systemd timer:
|
Create the systemd timer:
|
||||||
|
35
main.go
35
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
@ -82,12 +83,12 @@ type TorrentStatsPageData struct {
|
|||||||
func main() {
|
func main() {
|
||||||
transmissionbt, err := transmissionrpc.New(os.Getenv("RPC_HOST"), os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWD"), nil)
|
transmissionbt, err := transmissionrpc.New(os.Getenv("RPC_HOST"), os.Getenv("RPC_USER"), os.Getenv("RPC_PASSWD"), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stats, err := transmissionbt.SessionStats()
|
stats, err := transmissionbt.SessionStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionStats := []SessionStat{
|
sessionStats := []SessionStat{
|
||||||
@ -138,6 +139,32 @@ func main() {
|
|||||||
TorrentInfo: torrentInfo,
|
TorrentInfo: torrentInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.ParseFiles("template.html")
|
htmlTemplate, err := template.ParseFiles("template.html")
|
||||||
err = t.Execute(os.Stdout, data)
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
htmlFile, err := os.Create(os.Getenv("HTML_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
defer htmlFile.Close()
|
||||||
|
|
||||||
|
if err = htmlTemplate.Execute(htmlFile, data); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gmiTemplate, err := template.ParseFiles("template.gmi")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gmiFile, err := os.Create(os.Getenv("GMI_FILE"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = gmiTemplate.Execute(gmiFile, data); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
template.gmi
Normal file
26
template.gmi
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Torrent Stats
|
||||||
|
As of {{.Date}}
|
||||||
|
|
||||||
|
## Session Stats
|
||||||
|
{{range .SessionStats}}
|
||||||
|
{{.Label}}: {{.Value}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
## Current Stats
|
||||||
|
{{range .CurrentStats}}
|
||||||
|
{{.Label}}: {{.Value}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
## Cumulative Stats
|
||||||
|
{{range .CumulativeStats}}
|
||||||
|
{{.Label}}: {{.Value}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
## Torrent Info
|
||||||
|
{{range .TorrentInfo}}
|
||||||
|
Name: {{.Name}}
|
||||||
|
Date Added: {{.DateAdded}}
|
||||||
|
Total Size: {{.TotalSize}}
|
||||||
|
Peers Connected: {{.PeersConnected}}
|
||||||
|
Peers Getting From Us: {{.PeersGettingFromUs}}
|
||||||
|
{{end}}
|
Loading…
Reference in New Issue
Block a user