81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"e621_to_neo4j/e621/api"
|
|
"e621_to_neo4j/neo4j"
|
|
"e621_to_neo4j/utils"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
config, err := utils.LoadConfig()
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
driver, err := neo4j.NewConnection(config.Neo4jURL, config.Neo4jUsername, config.Neo4jPassword)
|
|
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)
|
|
}
|
|
|
|
err = neo4j.CreateUserNode(ctx, driver, user)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
favs, err := e621Client.GetFavorites(user.Name)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
start := time.Now()
|
|
for i, fav := range favs {
|
|
|
|
log.Printf("The e621 post with the id %d has %d general Tags, %d character Tags, %d copyright Tags, %d artist Tags.", fav.ID, len(fav.Tags.General), len(fav.Tags.Character), len(fav.Tags.Copyright), len(fav.Tags.Artist))
|
|
log.Printf("Uploaded Posts: %d", i)
|
|
|
|
for _, general := range fav.Tags.General {
|
|
log.Printf("TagType: General - Tag: %s", general)
|
|
err := neo4j.CreateTagNode(ctx, driver, general, "general")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
for _, character := range fav.Tags.Character {
|
|
log.Printf("TagType: Character - Tag: %s", character)
|
|
err := neo4j.CreateTagNode(ctx, driver, character, "character")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
for _, copyright := range fav.Tags.Copyright {
|
|
log.Printf("TagType: Copyright - Tag: %s", copyright)
|
|
err := neo4j.CreateTagNode(ctx, driver, copyright, "copyright")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
for _, artist := range fav.Tags.Artist {
|
|
log.Printf("TagType: Artist - Tag: %s", artist)
|
|
err := neo4j.CreateTagNode(ctx, driver, artist, "artist")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
elapsed := time.Since(start)
|
|
log.Printf("This took %s", elapsed)
|
|
}
|