Skip to content

Instantly share code, notes, and snippets.

@bentsai
Created June 29, 2022 18:29
Show Gist options
  • Save bentsai/5014dd575358e7e56d85146aac86a018 to your computer and use it in GitHub Desktop.
Save bentsai/5014dd575358e7e56d85146aac86a018 to your computer and use it in GitHub Desktop.
Script that arranges Kinopio cards in reverse-chronological order
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;
}
@bentsai
Copy link
Author

bentsai commented Jun 29, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment