mirror of
https://github.com/adulau/mastodon-markdown-archive.git
synced 2024-11-22 01:47:05 +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
|
Location to persist the post id of the first post returned
|
||||||
-persist-last string
|
-persist-last string
|
||||||
Location to persist the post id of the last post returned
|
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
|
-since-id string
|
||||||
Fetch posts greater than this id
|
Fetch posts greater than this id
|
||||||
-template string
|
-template string
|
||||||
|
|
|
@ -2,7 +2,6 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -134,8 +133,6 @@ func FetchPosts(baseURL string, accountId string, filters PostsFilter) ([]Post,
|
||||||
query,
|
query,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Println(fmt.Sprintf("Fetching posts from %s", postsUrl))
|
|
||||||
|
|
||||||
if err := Fetch(postsUrl, &posts); err != nil {
|
if err := Fetch(postsUrl, &posts); err != nil {
|
||||||
return posts, err
|
return posts, err
|
||||||
}
|
}
|
||||||
|
@ -151,8 +148,6 @@ func FetchStatusContext(baseURL, postId string) (StatusContext, error) {
|
||||||
postId,
|
postId,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Println(statusUrl)
|
|
||||||
|
|
||||||
if err := Fetch(statusUrl, &status); err != nil {
|
if err := Fetch(statusUrl, &status); err != nil {
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
|
12
main.go
12
main.go
|
@ -25,6 +25,7 @@ func main() {
|
||||||
templateFile := flag.String("template", "", "Template to use for post rendering, if passed")
|
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")
|
threaded := flag.Bool("threaded", true, "Thread replies for a post in a single file")
|
||||||
filenameTemplate := flag.String("filename", "", "Template for post filename")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -45,7 +46,15 @@ func main() {
|
||||||
posts := c.Posts()
|
posts := c.Posts()
|
||||||
postsCount := len(posts)
|
postsCount := len(posts)
|
||||||
|
|
||||||
|
if *porcelain {
|
||||||
|
fmt.Println(postsCount)
|
||||||
|
} else {
|
||||||
log.Println(fmt.Sprintf("Fetched %d posts", postsCount))
|
log.Println(fmt.Sprintf("Fetched %d posts", postsCount))
|
||||||
|
}
|
||||||
|
|
||||||
|
if postsCount == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, post := range posts {
|
for _, post := range posts {
|
||||||
if post.ShouldSkip() {
|
if post.ShouldSkip() {
|
||||||
|
@ -54,11 +63,9 @@ func main() {
|
||||||
|
|
||||||
if err := fileWriter.Write(post); err != nil {
|
if err := fileWriter.Write(post); err != nil {
|
||||||
log.Panicln("error writing post to file: %w", err)
|
log.Panicln("error writing post to file: %w", err)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if postsCount > 0 {
|
|
||||||
if *persistFirst != "" {
|
if *persistFirst != "" {
|
||||||
firstPost := posts[0]
|
firstPost := posts[0]
|
||||||
err := persistId(firstPost.Id, *persistFirst)
|
err := persistId(firstPost.Id, *persistFirst)
|
||||||
|
@ -77,7 +84,6 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func persistId(postId string, path string) error {
|
func persistId(postId string, path string) error {
|
||||||
persistPath, err := filepath.Abs(path)
|
persistPath, err := filepath.Abs(path)
|
||||||
|
|
Loading…
Reference in a new issue