fix mastodon import to work with new format.

from Peter Sanchez
This commit is contained in:
Ted Unangst 2021-01-17 19:01:54 -05:00
parent 9766f208e8
commit 07ae68eae0
2 changed files with 31 additions and 29 deletions

View File

@ -2,6 +2,8 @@ changelog
=== next === next
+ Fix mastodon import.
+ Better regex for filters. + Better regex for filters.
+ Fix hoot to work with Twitter's latest crap. + Fix hoot to work with Twitter's latest crap.

View File

@ -45,30 +45,30 @@ func importMastodon(username, source string) {
log.Fatal(err) log.Fatal(err)
} }
type Toot struct { type Toot struct {
Id string Id string
Type string Type string
To []string To []string
Cc []string Cc []string
Summary string Object struct {
Content string Summary string
InReplyTo string Content string
Conversation string InReplyTo string
Published time.Time Conversation string
Tag []struct { Published time.Time
Type string Tag []struct {
Name string Type string
} Name string
Attachment []struct { }
Type string Attachment []struct {
MediaType string Type string
Url string MediaType string
Name string Url string
Name string
}
} }
} }
var outbox struct { var outbox struct {
OrderedItems []struct { OrderedItems []Toot
Object Toot
}
} }
fd, err := os.Open(source + "/outbox.json") fd, err := os.Open(source + "/outbox.json")
if err != nil { if err != nil {
@ -93,7 +93,7 @@ func importMastodon(username, source string) {
re_tootid := regexp.MustCompile("[^/]+$") re_tootid := regexp.MustCompile("[^/]+$")
for _, item := range outbox.OrderedItems { for _, item := range outbox.OrderedItems {
toot := item.Object toot := item
tootid := re_tootid.FindString(toot.Id) tootid := re_tootid.FindString(toot.Id)
xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, tootid) xid := fmt.Sprintf("%s/%s/%s", user.URL, honkSep, tootid)
if havetoot(xid) { if havetoot(xid) {
@ -104,15 +104,15 @@ func importMastodon(username, source string) {
What: "honk", What: "honk",
Honker: user.URL, Honker: user.URL,
XID: xid, XID: xid,
RID: toot.InReplyTo, RID: toot.Object.InReplyTo,
Date: toot.Published, Date: toot.Object.Published,
URL: xid, URL: xid,
Audience: append(toot.To, toot.Cc...), Audience: append(toot.To, toot.Cc...),
Noise: toot.Content, Noise: toot.Object.Content,
Convoy: toot.Conversation, Convoy: toot.Object.Conversation,
Whofore: 2, Whofore: 2,
Format: "html", Format: "html",
Precis: toot.Summary, Precis: toot.Object.Summary,
} }
if honk.RID != "" { if honk.RID != "" {
honk.What = "tonk" honk.What = "tonk"
@ -120,7 +120,7 @@ func importMastodon(username, source string) {
if !loudandproud(honk.Audience) { if !loudandproud(honk.Audience) {
honk.Whofore = 3 honk.Whofore = 3
} }
for _, att := range toot.Attachment { for _, att := range toot.Object.Attachment {
switch att.Type { switch att.Type {
case "Document": case "Document":
fname := fmt.Sprintf("%s/%s", source, att.Url) fname := fmt.Sprintf("%s/%s", source, att.Url)
@ -144,7 +144,7 @@ func importMastodon(username, source string) {
honk.Donks = append(honk.Donks, donk) honk.Donks = append(honk.Donks, donk)
} }
} }
for _, t := range toot.Tag { for _, t := range toot.Object.Tag {
switch t.Type { switch t.Type {
case "Hashtag": case "Hashtag":
honk.Onts = append(honk.Onts, t.Name) honk.Onts = append(honk.Onts, t.Name)