Last active
February 19, 2021 12:04
-
-
Save y-young/031291b39e425472a26d973bd9aa52ee to your computer and use it in GitHub Desktop.
Twitter Followings Exporter
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
/* | |
Twitter Followings Exporter | |
Usage: | |
1. Go to https://twitter.com/username/following | |
2. Scoll down to the end | |
3. Filter requests in the network panel of DevTool like this: | |
https://twitter.com/i/api/graphql/aBcDeFGHijklMNopqRstUV/Following?variables= | |
4. Paste the whole response into `followings.json` | |
5. Run the script: `node twitter-followings-exporter.js` | |
6. Find other requests, repeat 4 and 5 until completed | |
*/ | |
const fs = require("fs/promises"); | |
(async () => { | |
let json = await fs.readFile("followings.json"); | |
json = JSON.parse(json); | |
let entries; | |
for (let instruction of json.data.user.following_timeline.timeline | |
.instructions) { | |
if (instruction.type === "TimelineAddEntries") { | |
entries = instruction.entries; | |
break; | |
} | |
} | |
entries = entries.filter((entry) => entry.entryId.startsWith("user")); | |
const users = []; | |
for (const entry of entries) { | |
const user = entry.content.itemContent.user.legacy; | |
users.push(user.screen_name); | |
} | |
console.log(users); | |
let prevData; | |
try { | |
prevData = await fs.readFile("users.json"); | |
prevData = JSON.parse(prevData); | |
} catch { | |
prevData = []; | |
} | |
await fs.writeFile( | |
"users.json", | |
JSON.stringify(prevData.concat(users), null, 2) | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment