From 07ae68eae04921328bac48404855ee03bf75714c Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 17 Jan 2021 19:01:54 -0500 Subject: [PATCH] fix mastodon import to work with new format. from Peter Sanchez --- docs/changelog.txt | 2 ++ import.go | 58 +++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index eaebdc5..07608bd 100644 --- a/docs/changelog.txt +++ b/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. diff --git a/import.go b/import.go index 32cc411..60a16da 100644 --- a/import.go +++ b/import.go @@ -45,30 +45,30 @@ func importMastodon(username, source string) { 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 @@ func importMastodon(username, source string) { 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 @@ func importMastodon(username, source string) { 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 @@ func importMastodon(username, source string) { 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 @@ func importMastodon(username, source string) { 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)