diff --git a/README.md b/README.md index 4d5a090..d37907e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## TODO - [x] input for the users handle or did -- [ ] that input will look up the users posts for that day a year ago +- [x] that input will look up the users posts for that day a year ago - [ ] show the posts using bluesky's embed (keep it nice and simple) - [ ] add in oauth login to repost the post - [ ] publish on tangled diff --git a/index.html b/index.html index 186ef3b..64e9200 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@
@@ -33,6 +33,11 @@ import * as TID from "https://cdn.jsdelivr.net/npm/@atcute/tid/+esm"; + import { + Client, + simpleFetchHandler, + } from "https://cdn.jsdelivr.net/npm/@atcute/client/+esm"; + const handleResolver = new CompositeHandleResolver({ methods: { dns: new DohJsonHandleResolver({ @@ -80,6 +85,48 @@ const lastYearTimestamp = thisDayLastYear.getTime() * 1_000; const lastYearTid = TID.create(lastYearTimestamp, 23); console.log(lastYearTid); + + const rpc = new Client({ + handler: simpleFetchHandler({ + service: pds, + }), + }); + // https://selfhosted.social/xrpc/com.atproto.repo.listRecords?repo=did%3Aplc%3Arnpkyqnmsw4ipey6eotbdnnf&collection=app.bsky.feed.post&limit=100&reverse=false&cursor=3lnmguhip222r + const response = await rpc.get( + "com.atproto.repo.listRecords", + { + params: { + repo: did, + collection: "app.bsky.feed.post", + limit: 100, + reverse: true, + cursor: lastYearTid, + }, + }, + ); + + const posts = response.data.records; + const postsFromThatDay = posts.filter((post) => { + let postedDate = new Date(post.value.createdAt); + // console.log( + // postedDate.getDate(), + // thisDayLastYear.getDate(), + // ); + + // console.log( + // postedDate.getMonth(), + // thisDayLastYear.getMonth(), + // ); + + return ( + postedDate.getDate() === + thisDayLastYear.getDate() && + postedDate.getMonth() === + thisDayLastYear.getMonth() && + post.value.reply == null + ); + }); + console.log(postsFromThatDay); } catch (e) { console.error(e); alert("Failed to find posts from that day: " + e.message);