mirror of
https://git.keinpfusch.net/loweel/zorg
synced 2024-12-18 15:08:42 +01:00
Compare commits
7 Commits
bd8e7af264
...
2ea8bf202b
Author | SHA1 | Date | |
---|---|---|---|
2ea8bf202b | |||
6978287809 | |||
1b2fa17294 | |||
5644a4fb3c | |||
a50d6c91ea | |||
fedc958926 | |||
34caf24f6c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
*.sh
|
*.sh
|
||||||
zorg.conf
|
zorg.conf
|
||||||
zorg
|
zorg
|
||||||
|
feeds.conf
|
||||||
.vscode/*
|
.vscode/*
|
35
README.md
35
README.md
@ -12,47 +12,18 @@ go build
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
in order to use it, you need app credentials for your specific pod, which you obtain when you register your app.
|
|
||||||
In case your pod makes it too complicate, you can just use the following go :
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/mattn/go-mastodon"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
|
||||||
Server: "https://yourpodhere.put",
|
|
||||||
ClientName: "client-name",
|
|
||||||
Scopes: "read write follow",
|
|
||||||
Website: "whereyour application has a website",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Printf("client-id : %s\n", app.ClientID)
|
|
||||||
fmt.Printf("client-secret: %s\n", app.ClientSecret)
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
just change the values to match your pod, and it will print a new ClientID and ClientSecret.
|
just change the values to match your pod, and it will print a new ClientID and ClientSecret.
|
||||||
|
|
||||||
Once you have both, you can just feed the zorg configuration file, which is a JSON, and change his name as zorg.conf
|
Once you have both, you can just feed the zorg configuration file, which is a JSON, and change his name as zorg.conf
|
||||||
|
Just leave "default" on your ClientID and secret.
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"ZorgServer": "https://example-pleroma.net",
|
"ZorgServer": "https://example-pleroma.net",
|
||||||
"ZorgClientID": "aqwfgqubvqerb348hü13vhnrqvqerg1ü3ohrgvqervq",
|
"ZorgClientID": "default",
|
||||||
"ZorgClientSecret": "qergerinqieorjhgqrijhg+3higqirgqirjgqerjgqq",
|
"ZorgClientSecret": "default",
|
||||||
"ZorgUname": "johndoe",
|
"ZorgUname": "johndoe",
|
||||||
"ZorgPass" : "lalalalalalalala",
|
"ZorgPass" : "lalalalalalalala",
|
||||||
"ZorgInterval": 7200
|
"ZorgInterval": 7200
|
||||||
|
BIN
createtoken/createtoken
Executable file
BIN
createtoken/createtoken
Executable file
Binary file not shown.
23
createtoken/gettoken.go
Normal file
23
createtoken/gettoken.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/mattn/go-mastodon"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
||||||
|
Server: "https://boseburo.ddns.net",
|
||||||
|
ClientName: "zorg",
|
||||||
|
Scopes: "read write follow",
|
||||||
|
Website: "https://git.keinpfusch.net/loweel/zorg.git",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("client-id : %s\n", app.ClientID)
|
||||||
|
fmt.Printf("client-secret: %s\n", app.ClientSecret)
|
||||||
|
}
|
25
env.go
25
env.go
@ -1,11 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattn/go-mastodon"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ZorgConfig is the configuration of Zorg.
|
// ZorgConfig is the configuration of Zorg.
|
||||||
@ -40,6 +44,27 @@ func init() {
|
|||||||
|
|
||||||
Zint = time.Duration(time.Duration(ZorgConfig.ZorgInterval) * time.Second)
|
Zint = time.Duration(time.Duration(ZorgConfig.ZorgInterval) * time.Second)
|
||||||
|
|
||||||
|
ZorgCreateToken()
|
||||||
|
|
||||||
log.Println("Inizialized ZORG")
|
log.Println("Inizialized ZORG")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ZorgCreateToken() {
|
||||||
|
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
||||||
|
Server: ZorgConfig.ZorgServer,
|
||||||
|
ClientName: "Zorg",
|
||||||
|
Scopes: "read write follow",
|
||||||
|
Website: ZorgConfig.ZorgServer,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ZorgConfig.ZorgClientID = app.ClientID
|
||||||
|
ZorgConfig.ZorgClientSecret = app.ClientSecret
|
||||||
|
|
||||||
|
fmt.Printf("Zorg new client-id : %s\n", ZorgConfig.ZorgClientID)
|
||||||
|
fmt.Printf("Zorg new client-secret: %s\n", ZorgConfig.ZorgClientSecret)
|
||||||
|
|
||||||
|
}
|
||||||
|
27
feed.go
27
feed.go
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
strip "github.com/grokify/html-strip-tags-go"
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ func forwardLastFeed(url string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var b *gofeed.Item
|
var b *gofeed.Item
|
||||||
|
var postAge time.Time
|
||||||
|
|
||||||
if len(feed.Items) > 0 {
|
if len(feed.Items) > 0 {
|
||||||
b = feed.Items[0]
|
b = feed.Items[0]
|
||||||
@ -34,12 +36,27 @@ func forwardLastFeed(url string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Since(*b.PublishedParsed) < Zint {
|
if b.PublishedParsed != nil {
|
||||||
|
postAge = *b.PublishedParsed
|
||||||
postOnMastodon(b.Link, "["+feed.Title+"] "+b.Title)
|
} else if b.UpdatedParsed != nil {
|
||||||
log.Println("New content from: ", feed.Title, b.Title)
|
log.Println("Ops, no Published in the feed. Using Update Date")
|
||||||
|
postAge = *b.UpdatedParsed
|
||||||
} else {
|
} else {
|
||||||
log.Println("No new content from: ", feed.Title)
|
log.Println("No Published date or update date. This feed is crap, giving up")
|
||||||
|
postAge = time.Now().Add(Zint + (1 * time.Hour))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Last Post Age: ", postAge)
|
||||||
|
|
||||||
|
if time.Since(postAge) < Zint {
|
||||||
|
|
||||||
|
TheTitle := fmt.Sprintf("[News from %s ]", strip.StripTags(feed.Title))
|
||||||
|
TheBody := fmt.Sprintf("%s \n\n%s \n\n%s", strip.StripTags(b.Author.Name), strip.StripTags(b.Description), b.Link)
|
||||||
|
|
||||||
|
postOnMastodon(TheBody, TheTitle)
|
||||||
|
log.Println("New content from: ", feed.Title, b.Title, feed.Description)
|
||||||
|
} else {
|
||||||
|
log.Println("No new content from: ", feed.Title, feed.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module zorg
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1
|
||||||
github.com/mattn/go-mastodon v0.0.4
|
github.com/mattn/go-mastodon v0.0.4
|
||||||
github.com/mmcdole/gofeed v1.0.0
|
github.com/mmcdole/gofeed v1.0.0
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||||
|
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
3
zorg.go
3
zorg.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -10,7 +11,7 @@ func main() {
|
|||||||
// Just a nice way to wait until the Operating system sends a kill signal.
|
// Just a nice way to wait until the Operating system sends a kill signal.
|
||||||
// select{} was just horrible.
|
// select{} was just horrible.
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt, os.Kill)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
<-c
|
<-c
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user