Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX ERROR ASYNC FUNC #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,43 @@ async function main() {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
});

// Use the previous client to fetch the bearer token
// This method gives you an application-only token specifically for read-only access to public information.
const bearer = await client.getBearerToken();

// Create a new twitter client with this token.
// We assign this client to a global variable so we can access it in the api module
globalThis.TwitterClient = new Twitter({
bearer_token: bearer.access_token,
});

// fetch the information of the logged in user
// instead of getMe you could replace it with another method to get a third user to generate their circles
const user = await getUser("WHATEVER_USERNAME_YOU_WANT");

// this is how many users we will have for each layer from the inside out
const layers = [8, 15, 26];

// fetch the interactions
const data = await getInteractions(user.screen_name.toLowerCase(), layers);

// render the image
await render([
{distance: 0, count: 1, radius: 110, users: [user]},
{distance: 200, count: layers[0], radius: 64, users: data[0]},
{distance: 330, count: layers[1], radius: 58, users: data[1]},
{distance: 450, count: layers[2], radius: 50, users: data[2]},
]);

// Look at the arguments passed to the cli. If one of them is --text then we want to render a text version of the image too
const shouldRenderText = process.argv.find((arg) => arg === "--text");
if (shouldRenderText) await renderText(data);
try {
const bearer = await client.getBearerToken();
// Create a new twitter client with this token.
// We assign this client to a global variable so we can access it in the api module
globalThis.TwitterClient = new Twitter({
bearer_token: bearer.access_token,
});

// fetch the information of the logged in user
// instead of getMe you could replace it with another method to get a third user to generate their circles
const user = await getUser("foliverofficial");

// this is how many users we will have for each layer from the inside out
const layers = [8, 15, 26];

// fetch the interactions
const data = await getInteractions(
user.screen_name.toLowerCase(),
layers
);

// render the image
await render([
{distance: 0, count: 1, radius: 110, users: [user]},
{distance: 200, count: layers[0], radius: 64, users: data[0]},
{distance: 330, count: layers[1], radius: 58, users: data[1]},
{distance: 450, count: layers[2], radius: 50, users: data[2]},
]);

// Look at the arguments passed to the cli. If one of them is --text then we want to render a text version of the image too
const shouldRenderText = process.argv.find((arg) => arg === "--text");
if (shouldRenderText) await renderText(data);
} catch (err) {
console.log(err.errors[0]);
}
}

// entry point
Expand Down