Created
January 28, 2019 07:17
-
-
Save tosuke/8db324efa85743a9b823368fdc4a414a to your computer and use it in GitHub Desktop.
misskeyのAPI使ってフォローリスト生成するやつ
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 axios = require('axios') | |
const fs = require('fs') | |
const originHost = 'misskey.xyz' | |
const i = 'YOUR_TOKEN' | |
const origin = `https://${originHost}/api` | |
async function main() { | |
const status = await fetchStatus() | |
const id = status.id | |
console.log(id) | |
const accounts = [] | |
for await(const user of fetchFollowers(id)) { | |
const screenname = user.username | |
const host = user.host || originHost | |
const account = `${screenname}@${host}` | |
console.log(user.name, account) | |
accounts.push(account) | |
} | |
const csv = accounts.join('\n') | |
fs.writeFileSync('following_accounts.csv', csv) | |
} | |
async function fetchStatus() { | |
const { data } = await axios.post(`${origin}/i`, { i }) | |
return data | |
} | |
async function* fetchFollowers(id) { | |
let cursor = undefined | |
do { | |
const { data } = await axios.post(`${origin}/users/following`, { | |
i, | |
userId: id, | |
cursor, | |
limit: 100 | |
}) | |
cursor = data.next | |
yield* data.users | |
} while(cursor !== null) | |
} | |
main().catch(err => console.error(err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment