Last active
January 12, 2024 15:15
-
-
Save shibafu528/d4a797a39dcc15f1792426c899a74475 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 token = Deno.env.get("TISSUE_TOKEN"); | |
const col1 = Deno.args[0]; | |
const col2 = Deno.args[1]; | |
const fetchCollectionItems = async (collectionID: string) => { | |
const allItems = []; | |
for (let page = 1;; page++) { | |
const res = await fetch( | |
`https://shikorism.net/api/v1/collections/${collectionID}/items?page=${page}&per_page=100`, | |
{ | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${token}`, | |
}, | |
}, | |
); | |
const items = await res.json(); | |
allItems.push(...items.map((item: { link: string }) => item.link)); | |
if (items.length < 100) { | |
break; | |
} | |
} | |
allItems.sort(); | |
return allItems; | |
}; | |
const col1Items = await fetchCollectionItems(col1); | |
const col2Items = await fetchCollectionItems(col2); | |
const allItemsCount = new Set([...col1Items, ...col2Items]).size; | |
let matchesCount = 0; | |
while (col1Items.length && col2Items.length) { | |
if (col1Items[0] === col2Items[0]) { | |
console.log(`== ${col1Items[0]}`); | |
col1Items.shift(); | |
col2Items.shift(); | |
matchesCount++; | |
} else if (col1Items[0] < col2Items[0]) { | |
console.log(`< ${col1Items[0]}`); | |
col1Items.shift(); | |
} else if (col1Items[0] > col2Items[0]) { | |
console.log(` > ${col2Items[0]}`); | |
col2Items.shift(); | |
} | |
} | |
while (col1Items.length) { | |
console.log(`< ${col1Items[0]}`); | |
col1Items.shift(); | |
} | |
while (col2Items.length) { | |
console.log(` > ${col2Items[0]}`); | |
col2Items.shift(); | |
} | |
console.log('----'); | |
console.log(`match: ${matchesCount}/${allItemsCount} (${(matchesCount * 100 / allItemsCount).toFixed(2)}%)`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment