fix mastodon import to work with new format. from Peter Sanchez
Ted Unangst tedu@tedunangst.com
Sun, 17 Jan 2021 19:01:54 -0500
2 files changed,
31 insertions(+),
29 deletions(-)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -2,6 +2,8 @@ changelog
=== next ++ Fix mastodon import. + + Better regex for filters. + Fix hoot to work with Twitter's latest crap.
M
import.go
→
import.go
@@ -45,30 +45,30 @@ if err != nil {
log.Fatal(err) } type Toot struct { - Id string - Type string - To []string - Cc []string - Summary string - Content string - InReplyTo string - Conversation string - Published time.Time - Tag []struct { - Type string - Name string - } - Attachment []struct { - Type string - MediaType string - Url string - Name string + Id string + Type string + To []string + Cc []string + Object struct { + Summary string + Content string + InReplyTo string + Conversation string + Published time.Time + Tag []struct { + Type string + Name string + } + Attachment []struct { + Type string + MediaType string + Url string + Name string + } } } var outbox struct { - OrderedItems []struct { - Object Toot - } + OrderedItems []Toot } fd, err := os.Open(source + "/outbox.json") if err != nil {@@ -93,7 +93,7 @@ }
re_tootid := regexp.MustCompile("[^/]+$") for _, item := range outbox.OrderedItems { - toot := item.Object + toot := item tootid := re_tootid.FindString(toot.Id) xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, tootid) if havetoot(xid) {@@ -104,15 +104,15 @@ UserID: user.ID,
What: "honk", Honker: user.URL, XID: xid, - RID: toot.InReplyTo, - Date: toot.Published, + RID: toot.Object.InReplyTo, + Date: toot.Object.Published, URL: xid, Audience: append(toot.To, toot.Cc...), - Noise: toot.Content, - Convoy: toot.Conversation, + Noise: toot.Object.Content, + Convoy: toot.Object.Conversation, Whofore: 2, Format: "html", - Precis: toot.Summary, + Precis: toot.Object.Summary, } if honk.RID != "" { honk.What = "tonk"@@ -120,7 +120,7 @@ }
if !loudandproud(honk.Audience) { honk.Whofore = 3 } - for _, att := range toot.Attachment { + for _, att := range toot.Object.Attachment { switch att.Type { case "Document": fname := fmt.Sprintf("%s/%s", source, att.Url)@@ -144,7 +144,7 @@ }
honk.Donks = append(honk.Donks, donk) } } - for _, t := range toot.Tag { + for _, t := range toot.Object.Tag { switch t.Type { case "Hashtag": honk.Onts = append(honk.Onts, t.Name)