Improved forum database
This commit is contained in:
29
patches/post-texts/main.go
Normal file
29
patches/post-texts/main.go
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get a stream of all posts
|
||||
allPosts, err := arn.AllPosts()
|
||||
arn.PanicOnError(err)
|
||||
|
||||
// Iterate over the stream
|
||||
for post := range allPosts {
|
||||
// Fix text
|
||||
color.Yellow(post.Text)
|
||||
post.Text = arn.FixPostText(post.Text)
|
||||
color.Green(post.Text)
|
||||
|
||||
// Tags
|
||||
if post.Tags == nil {
|
||||
post.Tags = []string{}
|
||||
}
|
||||
|
||||
// Save
|
||||
err = post.Save()
|
||||
arn.PanicOnError(err)
|
||||
}
|
||||
}
|
34
patches/thread-posts/main.go
Normal file
34
patches/thread-posts/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Get a stream of all posts
|
||||
allPosts, err := arn.AllPosts()
|
||||
arn.PanicOnError(err)
|
||||
|
||||
threadToPosts := make(map[string][]string)
|
||||
|
||||
// Iterate over the stream
|
||||
for post := range allPosts {
|
||||
_, found := threadToPosts[post.ThreadID]
|
||||
|
||||
if !found {
|
||||
threadToPosts[post.ThreadID] = []string{post.ID}
|
||||
} else {
|
||||
threadToPosts[post.ThreadID] = append(threadToPosts[post.ThreadID], post.ID)
|
||||
}
|
||||
}
|
||||
|
||||
// Save new post ID lists
|
||||
for threadID, posts := range threadToPosts {
|
||||
thread, err := arn.GetThread(threadID)
|
||||
arn.PanicOnError(err)
|
||||
|
||||
thread.Posts = posts
|
||||
err = thread.Save()
|
||||
arn.PanicOnError(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user