-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit caca272
Showing
10 changed files
with
1,057 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
|
||
# builds | ||
build | ||
dist | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.cache | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.vscode/settings.json | ||
|
||
.next/ | ||
.vercel/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"semi": false, | ||
"useTabs": false, | ||
"tabWidth": 2, | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": false, | ||
"arrowParens": "always", | ||
"trailingComma": "none" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import got from 'got' | ||
|
||
export class ClubhouseClient { | ||
_apiBaseUrl = '' | ||
_headers = {} | ||
|
||
_deviceId = null | ||
_userId = null | ||
_token = null | ||
|
||
constructor(opts) { | ||
if (!opts) throw new Error('Missing required ClubhouseClient opts') | ||
|
||
const { deviceId, userId, token } = opts | ||
if (!deviceId) | ||
throw new Error('Missing required ClubhouseClient opts.deviceId') | ||
if (!userId) throw new Error('Missing required ClubhouseClient opts.userId') | ||
if (!token) throw new Error('Missing required ClubhouseClient opts.token') | ||
|
||
this._apiBaseUrl = opts.apiBaseUrl || 'https://api.hipster.house/api' | ||
|
||
// TODO: figure out why accessing the clubhouse API directly fails with 403 errors | ||
// 'https://www.clubhouseapi.com/api' | ||
|
||
this._deviceId = deviceId | ||
this._userId = userId | ||
this._token = token | ||
|
||
this._headers = { | ||
accept: '*/*', | ||
'accept-language': 'en-US,en;q=0.9', | ||
'ch-appbuild': '269', | ||
'ch-appversion': '0.1.15', | ||
'ch-languages': 'en-US', | ||
'ch-locale': 'en_US', | ||
'sec-ch-ua': | ||
'"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"', | ||
'sec-ch-ua-mobile': '?0', | ||
'sec-fetch-dest': 'empty', | ||
'sec-fetch-mode': 'cors', | ||
'sec-fetch-site': 'same-site', | ||
...opts.headers | ||
} | ||
} | ||
|
||
getProfile(userId) { | ||
return this._fetch({ | ||
endpoint: `/get_profile`, | ||
method: 'POST', | ||
body: { | ||
user_id: userId | ||
} | ||
}) | ||
} | ||
|
||
getMe() { | ||
return this._fetch({ | ||
endpoint: `/me`, | ||
method: 'POST', | ||
body: {} | ||
}) | ||
} | ||
|
||
checkWaitlistStatus() { | ||
return this._fetch({ | ||
endpoint: `/check_waitlist_status` | ||
}) | ||
} | ||
|
||
getFollowers(userId, opts = {}) { | ||
const { pageSize = 400, page = 1 } = opts | ||
|
||
return this._fetch({ | ||
endpoint: `/get_followers`, | ||
method: 'GET', | ||
searchParams: { | ||
user_id: userId, | ||
page_size: pageSize, | ||
page: page | ||
} | ||
}) | ||
} | ||
|
||
getFollowing(userId, opts = {}) { | ||
const { pageSize = 400, page = 1 } = opts | ||
|
||
return this._fetch({ | ||
endpoint: `/get_following`, | ||
method: 'GET', | ||
searchParams: { | ||
user_id: userId, | ||
page_size: pageSize, | ||
page: page | ||
} | ||
}) | ||
} | ||
|
||
_fetch({ endpoint, method = 'GET', body, gotOptions, headers, ...rest }) { | ||
const apiUrl = `${this._apiBaseUrl}${endpoint}` | ||
|
||
const params = { | ||
method, | ||
...gotOptions, | ||
headers: { | ||
...this._headers, | ||
authorization: `Token ${this._token}`, | ||
'ch-deviceid': this._deviceId, | ||
'ch-userid': this._userId, | ||
...headers | ||
}, | ||
...rest | ||
} | ||
|
||
if (method === 'POST' || method === 'PUT') { | ||
params.json = body | ||
} | ||
|
||
return got(apiUrl, params).json() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require = require('esm')(module) | ||
module.exports = require('./main.js') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Travis Fischer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ClubhouseClient } from './clubhouse-client' | ||
import PQueue from 'p-queue' | ||
|
||
async function main() { | ||
const token = 'a1bcd2983dd921fefc428f3bba55bbf79f3e7fc3' | ||
const deviceId = '3EE60C75-C867-4BEC-86D5-2B9ED33844D2' | ||
const userId = '2481724' | ||
|
||
const clubhouse = new ClubhouseClient({ | ||
token, | ||
deviceId, | ||
userId | ||
}) | ||
|
||
const seedUserId = '13870' | ||
|
||
// const profile = await clubhouse.getProfile(seedUserId) | ||
// console.log(JSON.stringify(profile, null, 2)) | ||
|
||
const followers = await clubhouse.getFollowers(seedUserId) | ||
console.log(JSON.stringify(followers, null, 2)) | ||
|
||
// const following = await clubhouse.getFollowing(seedUserId) | ||
// console.log(JSON.stringify(following, null, 2)) | ||
} | ||
|
||
async function crawlSocialGraph(clubhouse, seedUserId, opts = {}) { | ||
const { concurrency = 4 } = opts | ||
const queue = new PQueue({ concurrency }) | ||
const pendingUserIds = new Set() | ||
const users = {} | ||
|
||
async function processUser(userId) { | ||
if (userId && users[userId] === undefined && !pendingUserIds.has(userId)) { | ||
pendingUserIds.add(userId) | ||
|
||
queue.add(async () => { | ||
try { | ||
const user = await clubhouse.getProfile(userId) | ||
if (!user) { | ||
return | ||
} | ||
|
||
users[userId] = user | ||
|
||
// const following = | ||
} catch (err) { | ||
console.warn('error crawling user', userId, err) | ||
if (!users[userId]) { | ||
users[userId] = null | ||
} | ||
} | ||
|
||
pendingUserIds.delete(userId) | ||
}) | ||
} | ||
} | ||
|
||
await processUser(seedUserId) | ||
await queue.onIdle() | ||
|
||
return users | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "clubhouse-social-graph", | ||
"version": "0.1.0", | ||
"private": true, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "run-s test:*", | ||
"test:prettier": "prettier '**/*.{js,jsx,ts,tsx}' --check" | ||
}, | ||
"dependencies": { | ||
"dotenv-safe": "^8.2.0", | ||
"esm": "^3.2.25", | ||
"got": "^11.8.2", | ||
"p-map": "^4.0.0", | ||
"p-queue": "^6.6.2" | ||
}, | ||
"devDependencies": { | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.2.1" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Clubhouse Social Graph | ||
|
||
> Crawler for the Clubhouse social graph using their unofficial API. | ||
[![Prettier Code Formatting](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io) | ||
|
||
## Disclaimer | ||
|
||
This code is intended purely for educational purposes. It may go against the Clubhouse ToS, so use at your own discretion. We recommend against using this API / crawler with your personal Clubhouse account — you may get banned. | ||
|
||
Happy Hacking 🙃 | ||
|
||
## Usage | ||
|
||
**TODO** | ||
|
||
## License | ||
|
||
MIT © [Travis Fischer](https://transitivebullsh.it) | ||
|
||
Support my OSS work by <a href="https://twitter.com/transitive_bs">following me on twitter <img src="https://storage.googleapis.com/saasify-assets/twitter-logo.svg" alt="twitter" height="24px" align="center"></a> |
Oops, something went wrong.