Created
October 11, 2024 18:33
-
-
Save lleyton/6a3db54d80835b3fa29deca4c9db1485 to your computer and use it in GitHub Desktop.
Deno script for finding Mastodon accounts from an account's followers list.
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
import { Rettiwt } from "npm:rettiwt-api"; | |
const fediHandle = /@[\w.-]+@[\w.-]+/; | |
const apiKey = Deno.env.get("TWITTER_API_KEY"); | |
const username = Deno.args.at(-1); | |
if (username === undefined) | |
throw new Error("You must pass your Twitter username as an argument."); | |
if (apiKey === undefined) | |
throw new Error( | |
"You must pass your Twitter API key, with the environment variable TWITTER_API_KEY. Use https://chromewebstore.google.com/detail/x-auth-helper/igpkhkjmpdecacocghpgkghdcmcmpfhp." | |
); | |
const rettiwt = new Rettiwt({ | |
apiKey: apiKey, | |
}); | |
const user = await rettiwt.user.details(username); | |
if (!user) { | |
throw new Error("User with that username not found."); | |
} | |
const following = []; | |
let cursor = undefined; | |
while (true) { | |
const chunk = await rettiwt.user.following(user.id, 100, cursor?.value); | |
if (chunk.list.length === 0) break; | |
following.push(...chunk.list); | |
cursor = chunk.next; | |
// wait a second before getting the next chunk, I don't want to risk getting banned | |
await new Promise((r) => setTimeout(r, 1000)); | |
} | |
const handles = following | |
.map((u) => u.fullName.match(fediHandle) ?? u.description?.match(fediHandle)) | |
.filter((h) => h); | |
const entries = handles.map((h) => `${h},true,false,`); | |
await Deno.writeTextFile("following.csv", entries.join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment