npm package 'snooshift'

Popularity: Low
Description: A JavaScript wrapper for Reddit Pushshift API based on Snoowrap
Installation: npm install snooshift
Last version: 1.0.2 (Download)
Homepage: https://github.com/eben0/snooshift
Size: 23.32 kB
License: MIT
Keywords: pushshift, reddit, api, wrapper, praw, psaw, snoo

Activity

Last modified: June 18, 2021 6:31 AM (a year ago)
Versions released in one year: 1
Weekly downloads: 9
05/16/202108/01/202110/17/202101/02/202203/20/202201530456001234released versions / week
  • Versions released
  • Weekly downloads

What's new in version 1.0.2

Delta between version 1.0.1 and version 1.0.2

Source: Github
Commits:
  • 0282a62cfa36f98228664436edb603486021a5bf, June 4, 2021 6:42 PM:
    add `before` property to CommentSearchOptions (#1)
  • f8e16dd0382c9d6ec7aa4698d01dc8ec44c9fbd9, June 18, 2021 6:25 AM:
    Fix types (#2)
    
    Co-authored-by: Raphaël MORTIER <rmortier@centralpay.eu>
  • 3be2cbbed53e2c890423f061687f5eef6482afb9, June 18, 2021 6:27 AM:
    Update package.json
    
    bump to 1.0.2
Files changed:
package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "snooshift",
3
- "version": "1.0.1",
4
  "description": "A JavaScript wrapper for Reddit Pushshift API based on Snoowrap",
5
  "scripts": {
6
  "start": "node dist/",
1
  {
2
  "name": "snooshift",
3
+ "version": "1.0.2",
4
  "description": "A JavaScript wrapper for Reddit Pushshift API based on Snoowrap",
5
  "scripts": {
6
  "start": "node dist/",
src/SearchOptions.ts CHANGED
@@ -7,7 +7,8 @@ export declare interface CommentSearchOptions {
7
  aggs?: string[];
8
  author?: string;
9
  subreddit?: string;
10
- after?: number;
 
11
  frequency?: string;
12
  metadata?: boolean;
13
  }
@@ -22,21 +23,21 @@ export declare interface SubmissionSearchOptions {
22
  "selftext:not"?: string;
23
  size?: number;
24
  fields?: string;
25
- sort?: string;
26
- sort_type?: string;
27
  aggs?: string;
28
  author?: string;
29
  subreddit?: string;
30
- after?: number;
31
- before?: number;
32
- score?: number;
33
- num_comments?: number;
34
  over_18?: boolean;
35
  is_video?: boolean;
36
  locked?: boolean;
37
  stickied?: boolean;
38
  spoiler?: boolean;
39
  contest_mode?: boolean;
40
- frequency?: string;
41
  metadata?: boolean;
42
  }
7
  aggs?: string[];
8
  author?: string;
9
  subreddit?: string;
10
+ after?: number | string;
11
+ before?: number | string;
12
  frequency?: string;
13
  metadata?: boolean;
14
  }
23
  "selftext:not"?: string;
24
  size?: number;
25
  fields?: string;
26
+ sort?: "asc" | "desc";
27
+ sort_type?: "score" | "num_comments" | "created_utc";
28
  aggs?: string;
29
  author?: string;
30
  subreddit?: string;
31
+ after?: number | string;
32
+ before?: number | string;
33
+ score?: number | string;
34
+ num_comments?: number | string;
35
  over_18?: boolean;
36
  is_video?: boolean;
37
  locked?: boolean;
38
  stickied?: boolean;
39
  spoiler?: boolean;
40
  contest_mode?: boolean;
41
+ frequency?: "second" | "minute" | "hour" | "day";
42
  metadata?: boolean;
43
  }

Readme

SnooShift

JavaScript wrapper library for Pushshift with Snoowrap support.

Install

npm i -S snooshift

Searching Comments

import { SnooShift } from "snooshift";

// create new object
const snoo = new SnooShift();

// search parameters
// https://github.com/pushshift/api#search-parameters-for-comments

// search comments by author
const searchParams = {
  author: "eben0",
};

// send request
snoo.searchComments(searchParams).then((comments) => {
  console.log(comments);
});

Get Single Comment

// get single comment by id
snoo.getComment("gof4uys").then((comment) => {
  console.log(comment);
});

Searching Submissions

// search parameters
// https://github.com/pushshift/api#search-parameters-for-submissions

// search submissions by author
const searchParams = {
  author: "eben0",
};
snoo.searchSubmissions(searchParams).then((comments) => {
  console.log(comments);
});

Get Single Submission

// get single submission by id
snoo.searchSubmissions("lrufxe").then((submission) => {
  console.log(submission);
});

Interacting with Reddit

You can reply, upvote and interact with reddit using Snoowrap object. You must set up your reddit api credentials to do so.

import { SnooShift } from "snooshift";

// list of supported credentials:
// https://github.com/not-an-aardvark/snoowrap#examples
const credentials = {
  userAgent: "put your user-agent string here",
  clientId: "put your client id here",
  clientSecret: "put your client secret here",
  refreshToken: "put your refresh token here",
};

const snoo = new SnooShift(credentials);

// get comment and reply/upvote/etc...
snoo.getComment("gof4uys").then((comment) => {
  comment.reply("My awesome reply").then(value);
  comment.upvote().then(value);
  comment.delete().then(value);
});

Querying Elasticsearch

You can directly query the elasticsearch server if you are familiar with syntax.

import { SnooShift } from "snooshift";

const snoo = new SnooShift();

// elasticsearch query
// this query searches for all author's data ordered by created_utc
const query = {
  query: {
    term: { author: "eben0" },
  },
  sort: {
    created_utc: "desc",
  }
};

// searches for author's comments
snoo.elasticComments(query).then((result) => {
  console.log(result.hits.hits[0]._source);
});

// searches for author's submissions
snoo.elasticSubmissions(query).then((result) => {
  console.log(result.hits.hits[0]._source);
});