mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-21 17:37:06 +00:00
Add arg for improved scripting affordances
This commit is contained in:
parent
4c0f5ac95d
commit
4158621927
3 changed files with 23 additions and 20 deletions
|
@ -35,6 +35,8 @@ Usage of mastodon-markdown-archive:
|
|||
Location to persist the post id of the first post returned
|
||||
-persist-last string
|
||||
Location to persist the post id of the last post returned
|
||||
-porcelain
|
||||
Prints the amount of fetched posts to stdout in a parsable manner
|
||||
-since-id string
|
||||
Fetch posts greater than this id
|
||||
-template string
|
||||
|
|
|
@ -2,7 +2,6 @@ package client
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -134,8 +133,6 @@ func FetchPosts(baseURL string, accountId string, filters PostsFilter) ([]Post,
|
|||
query,
|
||||
)
|
||||
|
||||
log.Println(fmt.Sprintf("Fetching posts from %s", postsUrl))
|
||||
|
||||
if err := Fetch(postsUrl, &posts); err != nil {
|
||||
return posts, err
|
||||
}
|
||||
|
@ -151,8 +148,6 @@ func FetchStatusContext(baseURL, postId string) (StatusContext, error) {
|
|||
postId,
|
||||
)
|
||||
|
||||
log.Println(statusUrl)
|
||||
|
||||
if err := Fetch(statusUrl, &status); err != nil {
|
||||
return status, err
|
||||
}
|
||||
|
|
36
main.go
36
main.go
|
@ -25,6 +25,7 @@ func main() {
|
|||
templateFile := flag.String("template", "", "Template to use for post rendering, if passed")
|
||||
threaded := flag.Bool("threaded", true, "Thread replies for a post in a single file")
|
||||
filenameTemplate := flag.String("filename", "", "Template for post filename")
|
||||
porcelain := flag.Bool("porcelain", false, "Prints the amount of fetched posts to stdout in a parsable manner")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
@ -45,7 +46,15 @@ func main() {
|
|||
posts := c.Posts()
|
||||
postsCount := len(posts)
|
||||
|
||||
log.Println(fmt.Sprintf("Fetched %d posts", postsCount))
|
||||
if *porcelain {
|
||||
fmt.Println(postsCount)
|
||||
} else {
|
||||
log.Println(fmt.Sprintf("Fetched %d posts", postsCount))
|
||||
}
|
||||
|
||||
if postsCount == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, post := range posts {
|
||||
if post.ShouldSkip() {
|
||||
|
@ -54,27 +63,24 @@ func main() {
|
|||
|
||||
if err := fileWriter.Write(post); err != nil {
|
||||
log.Panicln("error writing post to file: %w", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if postsCount > 0 {
|
||||
if *persistFirst != "" {
|
||||
firstPost := posts[0]
|
||||
err := persistId(firstPost.Id, *persistFirst)
|
||||
if *persistFirst != "" {
|
||||
firstPost := posts[0]
|
||||
err := persistId(firstPost.Id, *persistFirst)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
||||
if *persistLast != "" {
|
||||
lastPost := posts[postsCount-1]
|
||||
err := persistId(lastPost.Id, *persistLast)
|
||||
if *persistLast != "" {
|
||||
lastPost := posts[postsCount-1]
|
||||
err := persistId(lastPost.Id, *persistLast)
|
||||
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue