FIXED WITH AI (i dont know js)
This commit is contained in:
+56
-17
@@ -1,22 +1,61 @@
|
||||
import bcfetch from 'bandcamp-fetch';
|
||||
const fs = require("fs");
|
||||
|
||||
const username = 'KeksNino';
|
||||
const username = 'noschxl';
|
||||
|
||||
const params = {
|
||||
target: username,
|
||||
imageFormat: 'art_app_large'
|
||||
async function fetchEntireWishlist() {
|
||||
let allWishlistItems = [];
|
||||
|
||||
// Set the initial parameters using the username
|
||||
let currentParams = {
|
||||
target: username,
|
||||
imageFormat: 'art_app_large'
|
||||
};
|
||||
|
||||
let hasMorePages = true;
|
||||
let pageCount = 1;
|
||||
|
||||
console.log(`Starting wishlist scrape for user: ${username}...`);
|
||||
|
||||
// Loop will keep running as long as Bandcamp returns a continuation token
|
||||
while (hasMorePages) {
|
||||
console.log(`Fetching page ${pageCount}...`);
|
||||
|
||||
try {
|
||||
const result = await bcfetch.fan.getWishlist(currentParams);
|
||||
|
||||
// Add the items from the current page to our master list
|
||||
// (Assuming the library returns the array inside an 'items' property)
|
||||
if (result && result.items) {
|
||||
allWishlistItems.push(...result.items);
|
||||
}
|
||||
|
||||
// Check if there are more pages to fetch
|
||||
if (result.continuation) {
|
||||
// Update the target with the continuation object for the next loop iteration
|
||||
currentParams.target = result.continuation;
|
||||
pageCount++;
|
||||
} else {
|
||||
// No continuation token means we've hit the end of the wishlist
|
||||
hasMorePages = false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error fetching page ${pageCount}:`, error);
|
||||
break; // Exit the loop if something goes wrong
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nDone! Successfully scraped ${allWishlistItems.length} items from your wishlist.`);
|
||||
|
||||
// You can now write `allWishlistItems` to a JSON file using Node's 'fs' module
|
||||
// console.log(JSON.stringify(allWishlistItems, null, 2));
|
||||
fs.writeFile('wishlist.json', JSON.stringify(allWishlistItems, null, 2), (err) => {
|
||||
if (err) {
|
||||
console.error('Error writing to file', err);
|
||||
} else {
|
||||
console.log('Data written to file');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
bcfetch.fan.getWishlist(params).then(async (wishlist) => {
|
||||
console.log(JSON.stringify(wishlist, null, 2));
|
||||
|
||||
if (wishlist.continuation) {
|
||||
console.log('Fetching more by continuation...')
|
||||
|
||||
const moreResults = await bcfetch.fan.getWishlist({
|
||||
...params,
|
||||
target: wishlist.continuation
|
||||
});
|
||||
console.log(JSON.stringify(moreResults, null, 2));
|
||||
}
|
||||
});
|
||||
fetchEntireWishlist();
|
||||
|
||||
Reference in New Issue
Block a user