all repos — honk @ 872643426e479fc756020f0d8a60bfcd5cf7d337

my fork of honk

start working on an export command
Ted Unangst tedu@tedunangst.com
Fri, 18 Aug 2023 11:51:28 -0400
commit

872643426e479fc756020f0d8a60bfcd5cf7d337

parent

75d50653d5d11dce7a63f350e50ac937396ae18b

2 files changed, 66 insertions(+), 0 deletions(-)

jump to
M import.goimport.go

@@ -16,6 +16,7 @@

package main import ( + "archive/zip" "encoding/csv" "encoding/json" "fmt"

@@ -27,6 +28,8 @@ "regexp"

"sort" "strings" "time" + + "humungus.tedunangst.com/r/webs/junk" ) func importMain(username, flavor, source string) {

@@ -513,3 +516,61 @@ err := savehonk(&honk)

log.Printf("honk saved %v -> %v", xid, err) } } + +func export(username, file string) { + user, err := butwhatabout(username) + if err != nil { + elog.Fatal(err) + } + fd, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + if err != nil { + elog.Fatal(err) + } + zd := zip.NewWriter(fd) + donks := make(map[string]bool) + { + w, err := zd.Create("outbox.json") + if err != nil { + elog.Fatal(err) + } + var jonks []junk.Junk + rows, err := stmtUserHonks.Query(0, 3, user.Name, "0", 1234567) + honks := getsomehonks(rows, err) + for _, honk := range honks { + noise := honk.Noise + j, jo := jonkjonk(user, honk) + if honk.Format == "markdown" { + jo["source"] = noise + } + for _, donk := range honk.Donks { + donks[donk.XID] = true + } + jonks = append(jonks, j) + } + j := junk.New() + j["@context"] = itiswhatitis + j["id"] = user.URL + "/outbox" + j["attributedTo"] = user.URL + j["type"] = "OrderedCollection" + j["totalItems"] = len(jonks) + j["orderedItems"] = jonks + j.Write(w) + } + zd.Create("media/") + for donk := range donks { + var media string + var data []byte + w, err := zd.Create("media/" + donk) + if err != nil { + elog.Fatal(err) + } + row := stmtGetFileData.QueryRow(donk) + err = row.Scan(&media, &data) + if err != nil { + elog.Fatal(err) + } + w.Write(data) + } + zd.Close() + fd.Close() +}
M main.gomain.go

@@ -122,6 +122,11 @@ if len(args) != 4 {

elog.Fatal("import username mastodon|twitter srcdir") } importMain(args[1], args[2], args[3]) + case "export": + if len(args) != 3 { + elog.Fatal("export username destdir") + } + export(args[1], args[2]) case "devel": if len(args) != 2 { elog.Fatal("need an argument: devel (on|off)")