2023-05-22 11:08:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"e621_to_neo4j/e621/api"
|
2023-05-22 14:00:49 +00:00
|
|
|
"e621_to_neo4j/e621/api/models"
|
|
|
|
"e621_to_neo4j/neo4jAPI"
|
2023-05-22 11:08:08 +00:00
|
|
|
"e621_to_neo4j/utils"
|
2023-05-22 14:00:49 +00:00
|
|
|
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
2023-05-22 11:08:08 +00:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
config, err := utils.LoadConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:00:49 +00:00
|
|
|
driver, err := neo4jAPI.NewConnection(config.Neo4jURL, config.Neo4jUsername, config.Neo4jPassword)
|
2023-05-22 11:08:08 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
defer driver.Close(ctx)
|
|
|
|
|
|
|
|
e621Client := api.NewClient(config.E621APIKey, config.E621Username)
|
|
|
|
user, err := e621Client.GetUserInfo("selloo")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-22 14:00:49 +00:00
|
|
|
err = neo4jAPI.CreateUserNode(ctx, driver, user)
|
2023-05-22 11:08:08 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
favs, err := e621Client.GetFavorites(user.Name)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 11:08:08 +00:00
|
|
|
start := time.Now()
|
2023-05-22 17:53:30 +00:00
|
|
|
uploadTags(favs, ctx, driver)
|
2023-05-22 14:00:49 +00:00
|
|
|
elapsed := time.Since(start)
|
2023-05-22 17:53:30 +00:00
|
|
|
log.Printf("upload of Tags took %d", elapsed)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
start = time.Now()
|
|
|
|
uploadPosts(favs, ctx, driver)
|
|
|
|
elapsed = time.Since(start)
|
|
|
|
log.Printf("upload of Posts took %d", elapsed)
|
2023-05-22 11:08:08 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
start = time.Now()
|
|
|
|
//uploadSources(favs, ctx, driver)
|
|
|
|
elapsed = time.Since(start)
|
|
|
|
log.Printf("upload of Sources took %d", elapsed)
|
2023-05-22 11:08:08 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
}
|
|
|
|
func uploadPosts(favs []models.Post, ctx context.Context, driver neo4j.DriverWithContext) error {
|
|
|
|
for _, fav := range favs {
|
|
|
|
err := neo4jAPI.CreatePostNode(ctx, driver, fav.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-05-22 11:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-05-22 17:53:30 +00:00
|
|
|
return nil
|
|
|
|
|
2023-05-22 14:00:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
func uploadTags(favs []models.Post, ctx context.Context, driver neo4j.DriverWithContext) {
|
|
|
|
uniqueGeneralTags := make([]string, 0)
|
|
|
|
uniqueCharacterTags := make([]string, 0)
|
|
|
|
uniqueCopyrightTags := make([]string, 0)
|
|
|
|
uniqueArtistTags := make([]string, 0)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
|
|
|
allGeneralTags := make([]string, 0)
|
|
|
|
allCharacterTags := make([]string, 0)
|
|
|
|
allCopyrightTags := make([]string, 0)
|
|
|
|
allArtistTags := make([]string, 0)
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// add all tags together
|
2023-05-22 14:00:49 +00:00
|
|
|
for _, fav := range favs {
|
2023-05-22 17:53:30 +00:00
|
|
|
allGeneralTags = append(allGeneralTags, fav.Tags.General...)
|
|
|
|
allCharacterTags = append(allCharacterTags, fav.Tags.Character...)
|
|
|
|
allCopyrightTags = append(allCopyrightTags, fav.Tags.Character...)
|
|
|
|
allArtistTags = append(allArtistTags, fav.Tags.Artist...)
|
|
|
|
}
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process General PostTags
|
|
|
|
uniqueGeneralTags = utils.UniqueNonEmptyElementsOf(allGeneralTags)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Character PostTags
|
|
|
|
uniqueCharacterTags = utils.UniqueNonEmptyElementsOf(allCharacterTags)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Copyright PostTags
|
|
|
|
uniqueCopyrightTags = utils.UniqueNonEmptyElementsOf(allCopyrightTags)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Artist PostTags
|
|
|
|
uniqueArtistTags = utils.UniqueNonEmptyElementsOf(allArtistTags)
|
2023-05-22 14:00:49 +00:00
|
|
|
|
|
|
|
log.Printf("uniqueGeneralTags length: %d", len(uniqueGeneralTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueCharacterTags length: %d", len(uniqueCharacterTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueCopyrightTags length: %d", len(uniqueCopyrightTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueArtistTags length: %d", len(uniqueArtistTags))
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
for _, uniqueGeneralTag := range uniqueGeneralTags {
|
|
|
|
|
2023-05-22 14:00:49 +00:00
|
|
|
log.Printf("TagType: General - Tag: %s", uniqueGeneralTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueGeneralTag, "general")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2023-05-22 17:53:30 +00:00
|
|
|
for _, uniqueCharacterTag := range uniqueCharacterTags {
|
2023-05-22 14:00:49 +00:00
|
|
|
log.Printf("TagType: Character - Tag: %s", uniqueCharacterTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueCharacterTag, "character")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
for _, uniqueCopyrightTag := range uniqueCopyrightTags {
|
2023-05-22 14:00:49 +00:00
|
|
|
log.Printf("TagType: Copyright - Tag: %s", uniqueCopyrightTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueCopyrightTag, "copyright")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
for _, uniqueArtistTag := range uniqueArtistTags {
|
2023-05-22 14:00:49 +00:00
|
|
|
log.Printf("TagType: Artist - Tag: %s", uniqueArtistTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueArtistTag, "artist")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-22 11:08:08 +00:00
|
|
|
}
|
2023-05-22 15:50:26 +00:00
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
func uploadSources(favs []models.Post, ctx context.Context, driver neo4j.DriverWithContext) {
|
2023-05-22 15:50:26 +00:00
|
|
|
uniqueGeneralTags := make([]string, 0)
|
|
|
|
uniqueCharacterTags := make([]string, 0)
|
|
|
|
uniqueCopyrightTags := make([]string, 0)
|
|
|
|
uniqueArtistTags := make([]string, 0)
|
|
|
|
|
|
|
|
allGeneralTags := make([]string, 0)
|
|
|
|
allCharacterTags := make([]string, 0)
|
|
|
|
allCopyrightTags := make([]string, 0)
|
|
|
|
allArtistTags := make([]string, 0)
|
|
|
|
|
|
|
|
// add all tags together
|
|
|
|
for _, fav := range favs {
|
|
|
|
allGeneralTags = append(allGeneralTags, fav.Tags.General...)
|
|
|
|
allCharacterTags = append(allCharacterTags, fav.Tags.Character...)
|
|
|
|
allCopyrightTags = append(allCopyrightTags, fav.Tags.Character...)
|
|
|
|
allArtistTags = append(allArtistTags, fav.Tags.Artist...)
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process General PostTags
|
2023-05-22 15:50:26 +00:00
|
|
|
uniqueGeneralTags = utils.UniqueNonEmptyElementsOf(allGeneralTags)
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Character PostTags
|
2023-05-22 15:50:26 +00:00
|
|
|
uniqueCharacterTags = utils.UniqueNonEmptyElementsOf(allCharacterTags)
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Copyright PostTags
|
2023-05-22 15:50:26 +00:00
|
|
|
uniqueCopyrightTags = utils.UniqueNonEmptyElementsOf(allCopyrightTags)
|
|
|
|
|
2023-05-22 17:53:30 +00:00
|
|
|
// Process Artist PostTags
|
2023-05-22 15:50:26 +00:00
|
|
|
uniqueArtistTags = utils.UniqueNonEmptyElementsOf(allArtistTags)
|
|
|
|
|
|
|
|
log.Printf("uniqueGeneralTags length: %d", len(uniqueGeneralTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueCharacterTags length: %d", len(uniqueCharacterTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueCopyrightTags length: %d", len(uniqueCopyrightTags))
|
|
|
|
|
|
|
|
log.Printf("uniqueArtistTags length: %d", len(uniqueArtistTags))
|
|
|
|
|
|
|
|
for _, uniqueGeneralTag := range uniqueGeneralTags {
|
|
|
|
|
|
|
|
log.Printf("TagType: General - Tag: %s", uniqueGeneralTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueGeneralTag, "general")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, uniqueCharacterTag := range uniqueCharacterTags {
|
|
|
|
log.Printf("TagType: Character - Tag: %s", uniqueCharacterTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueCharacterTag, "character")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, uniqueCopyrightTag := range uniqueCopyrightTags {
|
|
|
|
log.Printf("TagType: Copyright - Tag: %s", uniqueCopyrightTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueCopyrightTag, "copyright")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, uniqueArtistTag := range uniqueArtistTags {
|
|
|
|
log.Printf("TagType: Artist - Tag: %s", uniqueArtistTag)
|
|
|
|
err := neo4jAPI.CreateTagNode(ctx, driver, uniqueArtistTag, "artist")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|