Skip to content

Commit

Permalink
chore: update sdk to 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
manan19 committed Nov 21, 2024
1 parent 9aaa2ce commit 2c3d5b3
Show file tree
Hide file tree
Showing 10 changed files with 1,225 additions and 2,451 deletions.
2 changes: 2 additions & 0 deletions archiver-script/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

data.ndjson

# Logs

logs
Expand Down
4 changes: 2 additions & 2 deletions archiver-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ rm -rf farcaster-examples
cd archiver-script
```

### Step 3: NPM install
### Step 3: Yarn install

Install the required Nodejs packages:

```sh
npm install
yarn install
```

### Step 4: Edit the FID and the API key
Expand Down
27 changes: 16 additions & 11 deletions archiver-script/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import fs from "fs";

import { NeynarAPIClient } from "@neynar/nodejs-sdk";
const client = new NeynarAPIClient("YOUR_NEYNAR_API_KEY");
import { NeynarAPIClient, Configuration } from "@neynar/nodejs-sdk";
const config = new Configuration({
apiKey: "YOUR_NEYNAR_API_KEY"
})
const client = new NeynarAPIClient(config);

const parser = (cast) => {
return {
fid: parseInt(cast.author.fid),
parentFid: parseInt(cast.parentAuthor.fid)
? parseInt(cast.parentAuthor.fid)
parentFid: parseInt(cast.parent_author.fid)
? parseInt(cast.parent_author.fid)
: undefined,
hash: cast.hash || undefined,
threadHash: cast.threadHash || undefined,
parentHash: cast.parentHash || undefined,
parentUrl: cast.parentUrl || undefined,
threadHash: cast.thread_hash || undefined,
parentHash: cast.parent_hash || undefined,
parentUrl: cast.parent_url || undefined,
text: cast.text || undefined,
};
};
Expand All @@ -25,15 +28,17 @@ const dumpCast = (cast) => {
};

const fetchAndDump = async (fid, cursor) => {
const data = await client.fetchAllCastsCreatedByUser(fid, {
const response = await client.fetchCastsForUser({
fid,
limit: 150,
cursor,
});
data.result.casts.map(dumpCast);
console.log(response.casts.length);
response.casts.map(dumpCast);

// If there is no next cursor, we are done
if (data.result.next.cursor === null) return;
await fetchAndDump(fid, data.result.next.cursor);
if (response.next.cursor === null) return;
await fetchAndDump(fid, response.next.cursor);
};

// save all @rish.eth's casts in a file called data.ndjson
Expand Down
Loading

0 comments on commit 2c3d5b3

Please sign in to comment.