Post-Migrator/main.go

83 lines
2.5 KiB
Go

package main
import (
"federated.computer/wp-sync-slowtwitch/services/migration"
"federated.computer/wp-sync-slowtwitch/services/slowtwitch"
"fmt"
"github.com/PuerkitoBio/goquery"
"io"
"log"
"net/http"
"strings"
)
const baseUrl = "https://slowtwitch.cloud/"
const wordpressKey = "admin@slowtwitch.cloud"
const wordpressSecret = "6zY7 xsKZ dGIt l1Lp ypIK 6TWh"
const slowtwitchAdminUser = "admin"
const slowtwitchAdminPass = "yxnh93Ybbz2Nm8#mp28zCVv"
const slowtwitchDbName = "slowtwitch"
const migrationDbName = "slowtwitch_transfer"
const federatedDbUrl = "slowtwitch.northend.network"
const federatedDbPort = "3306"
var appCache AppCache
func main() {
// TODO Article migration
slowtwitchDB, slowtwitchDbErr := migration.Connect(slowtwitchAdminUser, slowtwitchAdminPass, federatedDbUrl, federatedDbPort, slowtwitchDbName+"?parseTime=true")
if slowtwitchDbErr != nil {
fmt.Println(slowtwitchDbErr)
}
resultsDB, resultsDBerr := migration.Connect(slowtwitchAdminUser, slowtwitchAdminPass, federatedDbUrl, federatedDbPort, migrationDbName)
if resultsDBerr != nil {
fmt.Println(resultsDBerr)
}
//EXPERIMENT START
res, err := http.Get("https://www.slowtwitch.com/Products/Components/SRAM_Drops_New_RED_AXS_Groupset_8950.html")
if err != nil {
log.Fatalf("http.Get -> %v", err)
}
defer res.Body.Close()
// Read the HTML content
htmlContent, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalf("ioutil.ReadAll -> %v", err)
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(string(htmlContent)))
if err != nil {
log.Fatalf("goquery.NewDocumentFromReader -> %v", err)
}
// Find all image tags and extract their 'src' attributes
doc.Find(".detail_text img").Each(func(i int, img *goquery.Selection) {
imgUrl, exists := img.Attr("src")
if exists {
log.Printf("Image URL %d: %s", i+1, slowtwitch.GetURL(imgUrl))
}
})
blog, err := doc.Find(".detail_text").Html()
if err != nil {
log.Fatalf("goquery.NewDocumentFromReader -> %v", err)
}
fmt.Println(blog)
//EXPERIMENT END
editorMigration := migration.MigrateAuthors{
SlowtwitchDatabase: slowtwitchDB,
ResultsDatabase: resultsDB,
WordpressBaseUrl: baseUrl,
WordpressUser: wordpressKey,
WordpressPassword: wordpressSecret,
}
editorMigration.Execute()
categoryMigration := migration.MigrateCategories{
SlowtwitchDatabase: slowtwitchDB,
ResultsDatabase: resultsDB,
WordpressBaseUrl: baseUrl,
WordpressUser: wordpressKey,
WordpressPassword: wordpressSecret,
}
categoryMigration.Execute()
}