Post-Migrator/main.go

38 lines
1.4 KiB
Go
Raw Normal View History

2024-05-07 22:03:15 +00:00
package main
import (
"bytes"
"federated.computer/wp-sync-slowtwitch/utilities"
2024-05-07 22:03:15 +00:00
"fmt"
"io"
"net/http"
2024-05-07 22:03:15 +00:00
)
const baseUrl = "https://go-api-playground.local/wp-json/wp/v2/"
2024-05-08 00:52:47 +00:00
const wordpressKey = "admin"
const wordpressSecret = "S34E keY1 A1uX 6ncs Rx4T f21W"
2024-05-07 22:03:15 +00:00
var appCache AppCache
func main() {
//Get category and cache
//Get single category from cache by name
//Get photo and cache with URL
//Create Category (with parent) + add to cache
//Upload Photo + add to cache
//Use cached data to correctly build post form submissions
resp, err := http.Get("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjPm2ryEM65R2LDKe1ov_2ThSg1Po44Pe6ybLGa9hEeKU9qLptSeYVc_ahRzA3ZiKqm73fdgYGCq2ZsfJTLPKjfCqkNtKF6xYwYfRTje3o2jH9VEKSvLyWZwCctQGHC7zREUBnJFZlI0A/s1600/Dogs+Puppies+Background+wallpaper+%25284%2529.jpg")
utilities.CheckError(err)
defer utilities.CloseBodyAndCheckError(resp.Body)
body, err := io.ReadAll(resp.Body)
utilities.CheckError(err)
request, err := http.NewRequest("POST", "https://go-api-playground.local/wp-json/wp/v2/media", bytes.NewReader(body))
request.Header.Set("Content-Disposition", `attachment;filename="Dogs+Puppies+Background+wallpaper+%25284%2529.jpg"`)
request.SetBasicAuth(wordpressKey, wordpressSecret)
rsp, err := http.DefaultClient.Do(request)
utilities.CheckError(err)
result, err := io.ReadAll(rsp.Body)
utilities.CheckError(err)
fmt.Println(rsp.StatusCode, string(result))
2024-05-07 22:03:15 +00:00
}