From 129c9913856e57903bcfb8a2cfdfe353c9682854 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Fri, 12 Apr 2024 15:32:51 +0100 Subject: [PATCH] Sort interactions with earliest first --- data/interactions/notes/twitter/5653892614.json | 2 +- data/interactions/posts/chef-gpt.json | 2 +- data/interactions/posts/easy-appreciation.json | 2 +- tools/import/webmentionio/interactions.go | 7 +++++++ tools/import/webmentionio/main.go | 3 +++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/data/interactions/notes/twitter/5653892614.json b/data/interactions/notes/twitter/5653892614.json index ec8a5996..517ccd18 100644 --- a/data/interactions/notes/twitter/5653892614.json +++ b/data/interactions/notes/twitter/5653892614.json @@ -1 +1 @@ -{"interactions":[{"guid":"webmentions.io#1799435","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112183980587832116#favorited-by-112139367222387976","author":{"name":"shellsharks","url":"https://shellsharks.social/@shellsharks"},"timestamp":"2024-03-30T12:41:28Z"},{"guid":"webmentions.io#1799436","emoji":"💬","url":"https://hachyderm.io/@byjp/112183987371889835","comment":"Perhaps, now my generation lives in a world where more of us can connect with the informality and emotion of our younger selves, we’ll see these digital generations have more empathy for the generations after us than has been easy for those that went before us?","author":{"name":"JP","url":"https://hachyderm.io/@byjp"},"timestamp":"2024-03-30T09:43:19Z"}]} +{"interactions":[{"guid":"webmentions.io#1799436","emoji":"💬","url":"https://hachyderm.io/@byjp/112183987371889835","comment":"Perhaps, now my generation lives in a world where more of us can connect with the informality and emotion of our younger selves, we’ll see these digital generations have more empathy for the generations after us than has been easy for those that went before us?","author":{"name":"JP","url":"https://hachyderm.io/@byjp"},"timestamp":"2024-03-30T09:43:19Z"},{"guid":"webmentions.io#1799435","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112183980587832116#favorited-by-112139367222387976","author":{"name":"shellsharks","url":"https://shellsharks.social/@shellsharks"},"timestamp":"2024-03-30T12:41:28Z"}]} diff --git a/data/interactions/posts/chef-gpt.json b/data/interactions/posts/chef-gpt.json index 0a874d78..293936c3 100644 --- a/data/interactions/posts/chef-gpt.json +++ b/data/interactions/posts/chef-gpt.json @@ -1 +1 @@ -{"interactions":[{"guid":"webmentions.io#1795504","emoji":"💬","url":"https://bsky.app/profile/davidcondemarin.bsky.social/post/3ko2zz752p72q","comment":"Ha! Just read this and I have to say I’m not impressed at all. I like my cooking a bit too much to let ChatGPT getting anywhere near it! I don’t think my commitment to science would have been as good as yours, I draw the line at throwing almonds and chickpeas on salmon 😂","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-03-19T18:53:44Z"},{"guid":"webmentions.io#1795367","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3knrhqsj6ac23#liked_by_did:plc:yqsc5vd6x67yofv5fmu5qkax","author":{"name":"","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-03-19T18:53:14Z"},{"guid":"webmentions.io#1794075","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112102305952063134#favorited-by-109290756203712091","author":{"name":"Maria Neumayer","url":"https://androiddev.social/@marianeum"},"timestamp":"2024-03-17T02:11:11Z"}]} +{"interactions":[{"guid":"webmentions.io#1794075","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112102305952063134#favorited-by-109290756203712091","author":{"name":"Maria Neumayer","url":"https://androiddev.social/@marianeum"},"timestamp":"2024-03-17T02:11:11Z"},{"guid":"webmentions.io#1795367","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3knrhqsj6ac23#liked_by_did:plc:yqsc5vd6x67yofv5fmu5qkax","author":{"name":"","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-03-19T18:53:14Z"},{"guid":"webmentions.io#1795504","emoji":"💬","url":"https://bsky.app/profile/davidcondemarin.bsky.social/post/3ko2zz752p72q","comment":"Ha! Just read this and I have to say I’m not impressed at all. I like my cooking a bit too much to let ChatGPT getting anywhere near it! I don’t think my commitment to science would have been as good as yours, I draw the line at throwing almonds and chickpeas on salmon 😂","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-03-19T18:53:44Z"}]} diff --git a/data/interactions/posts/easy-appreciation.json b/data/interactions/posts/easy-appreciation.json index 976ba1b0..f45f94a8 100644 --- a/data/interactions/posts/easy-appreciation.json +++ b/data/interactions/posts/easy-appreciation.json @@ -1 +1 @@ -{"interactions":[{"guid":"webmentions.io#1803505","emoji":"💬","url":"https://bsky.app/profile/davidcondemarin.bsky.social/post/3kpnjtnalz62x","comment":"Working links and all 🎉🎉🎉","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-04-08T20:50:04Z"},{"guid":"webmentions.io#1803506","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:yqsc5vd6x67yofv5fmu5qkax","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-04-08T20:52:44Z"},{"guid":"webmentions.io#1803381","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:5leipvle6iboocgqyfxmwzyr","author":{"name":"from jason","url":"https://bsky.app/profile/fromjason.xyz"},"timestamp":"2024-04-08T16:58:06Z"},{"guid":"webmentions.io#1803143","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:7r5c5jhtphcpkg3y55xu2y64","author":{"name":"dietrich","url":"https://bsky.app/profile/burrito.space"},"timestamp":"2024-04-08T07:36:20Z"},{"guid":"webmentions.io#1802889","emoji":"💬","url":"https://fosstodon.org/@nohans/112232032090656662","comment":"@byjp ????","author":{"name":"Nohan Sanders","url":"https://fosstodon.org/@nohans"},"timestamp":"2024-04-07T21:21:43Z"},{"guid":"webmentions.io#1802818","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-112016215941920799","author":{"name":"Julik Tarkhanov","url":"https://ruby.social/@julik"},"timestamp":"2024-04-07T16:39:03Z"},{"guid":"webmentions.io#1802816","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109390033241778368","author":{"name":"???? Devon","url":"https://techhub.social/@RadDevon"},"timestamp":"2024-04-07T16:39:01Z"},{"guid":"webmentions.io#1802817","emoji":"♥️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109303710428386973","author":{"name":"Jamie Tanna","url":"https://fed.brid.gy/r/https://www.jvt.me"},"timestamp":"2024-04-07T16:39:01Z"},{"guid":"webmentions.io#1802756","emoji":"♥️","url":"https://www.jvt.me/mf2/2024/04/pd7dd/","author":{"name":"Jamie Tanna","url":"https://www.jvt.me"},"timestamp":"2024-04-07T14:08:00+01:00"},{"guid":"webmentions.io#1802749","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109761392958430727","author":{"name":"Pete Rijks","url":"https://fedi.esgeroth.org/@prijks"},"timestamp":"2024-04-07T12:04:42Z"},{"guid":"webmentions.io#1802750","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-108728869388404920","author":{"name":"panigrc","url":"https://mastodon.social/@panigrc"},"timestamp":"2024-04-07T12:04:42Z"},{"guid":"webmentions.io#1802747","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-111584147840298413","author":{"name":"Henrik Jernevad","url":"https://mastodon.social/@henrikjernevad"},"timestamp":"2024-04-07T12:04:39Z"},{"guid":"webmentions.io#1802748","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109344010117626087","author":{"name":"Mike","url":"https://mastodon.social/@sass"},"timestamp":"2024-04-07T12:04:39Z"}]} +{"interactions":[{"guid":"webmentions.io#1802748","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109344010117626087","author":{"name":"Mike","url":"https://mastodon.social/@sass"},"timestamp":"2024-04-07T12:04:39Z"},{"guid":"webmentions.io#1802747","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-111584147840298413","author":{"name":"Henrik Jernevad","url":"https://mastodon.social/@henrikjernevad"},"timestamp":"2024-04-07T12:04:39Z"},{"guid":"webmentions.io#1802750","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-108728869388404920","author":{"name":"panigrc","url":"https://mastodon.social/@panigrc"},"timestamp":"2024-04-07T12:04:42Z"},{"guid":"webmentions.io#1802749","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109761392958430727","author":{"name":"Pete Rijks","url":"https://fedi.esgeroth.org/@prijks"},"timestamp":"2024-04-07T12:04:42Z"},{"guid":"webmentions.io#1802756","emoji":"♥️","url":"https://www.jvt.me/mf2/2024/04/pd7dd/","author":{"name":"Jamie Tanna","url":"https://www.jvt.me"},"timestamp":"2024-04-07T14:08:00+01:00"},{"guid":"webmentions.io#1802816","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109390033241778368","author":{"name":"😷 Devon","url":"https://techhub.social/@RadDevon"},"timestamp":"2024-04-07T16:39:01Z"},{"guid":"webmentions.io#1802817","emoji":"♥️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-109303710428386973","author":{"name":"Jamie Tanna","url":"https://fed.brid.gy/r/https://www.jvt.me"},"timestamp":"2024-04-07T16:39:01Z"},{"guid":"webmentions.io#1802818","emoji":"⭐️","url":"https://hachyderm.io/@byjp/112229385641236069#favorited-by-112016215941920799","author":{"name":"Julik Tarkhanov","url":"https://ruby.social/@julik"},"timestamp":"2024-04-07T16:39:03Z"},{"guid":"webmentions.io#1802889","emoji":"💬","url":"https://fosstodon.org/@nohans/112232032090656662","comment":"@byjp 👏","author":{"name":"Nohan Sanders","url":"https://fosstodon.org/@nohans"},"timestamp":"2024-04-07T21:21:43Z"},{"guid":"webmentions.io#1803143","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:7r5c5jhtphcpkg3y55xu2y64","author":{"name":"dietrich","url":"https://bsky.app/profile/burrito.space"},"timestamp":"2024-04-08T07:36:20Z"},{"guid":"webmentions.io#1803381","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:5leipvle6iboocgqyfxmwzyr","author":{"name":"from jason","url":"https://bsky.app/profile/fromjason.xyz"},"timestamp":"2024-04-08T16:58:06Z"},{"guid":"webmentions.io#1803505","emoji":"💬","url":"https://bsky.app/profile/davidcondemarin.bsky.social/post/3kpnjtnalz62x","comment":"Working links and all 🎉🎉🎉","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-04-08T20:50:04Z"},{"guid":"webmentions.io#1803506","emoji":"♥️","url":"https://bsky.app/profile/byjp.me/post/3kpm2zmp6ok2p#liked_by_did:plc:yqsc5vd6x67yofv5fmu5qkax","author":{"name":"David","url":"https://bsky.app/profile/davidcondemarin.bsky.social"},"timestamp":"2024-04-08T20:52:44Z"}]} diff --git a/tools/import/webmentionio/interactions.go b/tools/import/webmentionio/interactions.go index 9d8ee37d..069c0293 100644 --- a/tools/import/webmentionio/interactions.go +++ b/tools/import/webmentionio/interactions.go @@ -7,3 +7,10 @@ import ( type InteractionFile struct { Interactions []synd.Interaction `json:"interactions"` } + +type ByTimestamp []synd.Interaction + +// Implement the sort.Interface - Len, Less, and Swap methods +func (a ByTimestamp) Len() int { return len(a) } +func (a ByTimestamp) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByTimestamp) Less(i, j int) bool { return a[i].Timestamp.Unix() < a[j].Timestamp.Unix() } diff --git a/tools/import/webmentionio/main.go b/tools/import/webmentionio/main.go index ad4ed6f3..651e4d5f 100644 --- a/tools/import/webmentionio/main.go +++ b/tools/import/webmentionio/main.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "path" + "sort" "strings" "time" @@ -96,6 +97,8 @@ func addInteraction(jsonPath string, newIn synd.Interaction) error { inf.Interactions = append(inf.Interactions, newIn) } + sort.Sort(ByTimestamp(inf.Interactions)) + if err := os.MkdirAll(path.Dir(jsonPath), 0755); err != nil { return err }