Script that arranges Kinopio cards in reverse-chronological order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jsonResponse = await fetch( | |
"https://api.kinopio.club/space/<space ID>", | |
); | |
const spaceJson = await jsonResponse.json(); | |
// console.log(spaceJson); | |
const cards = spaceJson.cards; | |
const sortedCards = cards.sort((a: any, b: any) => a.createdAt < b.createdAt); | |
console.log(sortedCards); | |
const patchCard = async (card: any) => { | |
const headers = new Headers({ | |
"Content-Type": "application/json", | |
"Cache-Control": "must-revalidate, no-store, no-cache, private", | |
"Authorization": "<API KEY>", | |
}); | |
try { | |
const response = await fetch("https://api.kinopio.club/card", { | |
method: "PATCH", | |
headers, | |
body: JSON.stringify(card), | |
}); | |
await response.json(); | |
} catch (error) { | |
console.error(error); | |
} | |
}; | |
let currentY = 200; | |
const PADDING = 24; | |
for (const card of sortedCards) { | |
console.log(card.id, card.y, currentY); | |
if (card.x !== 100 || card.y !== currentY) { | |
patchCard({ ...card, x: 100, y: currentY }); | |
} | |
currentY += card.height + PADDING; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires https://deno.land