Import all tweets exported from X/Twitter to a Bluesky account.
at main 34 lines 1.2 kB view raw
1import FS from 'fs'; 2 3export const TWEETS_MAPPING_FILE_NAME = 'tweets_mapping.json'; // store the imported tweets & bsky id mapping 4 5export async function deleteBskyPosts(agent, tweets, minDate: Date, maxDate: Date){ 6// Delete bsky posts with a record in TWEETS_MAPPING_FILE_NAME. 7// If something goes wrong, call this method to clear the previously imported posts. 8// You may also use MIN_DATE and MAX_DATE to limit the range. 9 10 try { 11 for(let i=0; i < tweets.length; i++){ 12 const currentTweet = tweets[i]; 13 const { tweet, bsky } = currentTweet; 14 if(bsky){ 15 16 const tweetDate = new Date(tweet.created_at); 17 18 if (minDate != undefined && tweetDate < minDate) 19 continue; 20 if (maxDate != undefined && tweetDate > maxDate) 21 continue; 22 23 await agent.deletePost(bsky.uri); 24 console.log(tweet.id) 25 delete currentTweet.bsky; 26 } 27 } 28 }catch(e){ 29 throw e; 30 }finally{ 31 FS.writeFileSync(TWEETS_MAPPING_FILE_NAME, JSON.stringify(tweets, null, 4)) 32 } 33 34}