fix mastodon import to work with new format.

from Peter Sanchez
master
Ted Unangst 3 years ago
parent 9766f208e8
commit 07ae68eae0

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

@ -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)

Loading…
Cancel
Save