Make seed dogfood the api
authorJacob Casper <dev@jacobcasper.com>
Tue, 14 Apr 2020 04:46:57 +0000 (23:46 -0500)
committerJacob Casper <dev@jacobcasper.com>
Tue, 14 Apr 2020 04:52:20 +0000 (23:52 -0500)
scrape/seed/seed.go

index 017c2dd..f4145df 100644 (file)
@@ -2,18 +2,14 @@ package main
 
 import (
        "git.jacobcasper.com/brackets/client"
-       "git.jacobcasper.com/brackets/db"
        _ "github.com/mattn/go-sqlite3"
        "log"
+       "net/http"
+       "net/url"
 )
 
 func main() {
 
-       db, err := db.New()
-       if err != nil {
-               log.Fatal("Could not open db: ", err.Error())
-       }
-
        client, err := client.Get()
        if err != nil {
                log.Fatal("Could not get client: ", err.Error())
@@ -25,12 +21,11 @@ func main() {
                tracks, err := client.GetPlaylistTracks(playlist.ID)
                if err != nil {
                        log.Printf("Couldn't retrieve playlist %s.", string(playlist.ID))
+                       continue
                }
                for _, trackPage := range tracks.Tracks {
                        for _, artist := range trackPage.Track.Artists {
-                               db.Mu.Lock()
-                               db.Db.Exec("INSERT INTO ARTIST (ID, NAME) VALUES (?, ?)", artist.ID, artist.Name)
-                               db.Mu.Unlock()
+                               http.PostForm("http://localhost:8080/artist/add", url.Values{"artist_id": {string(artist.ID)}})
                        }
                }
        }