npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reddit-scheduler

v1.1.1

Published

A Reddit scheduler for posts

Downloads

208

Readme

reddit-scheduler

A Reddit scheduler for posts

Set up

Create a .env file in the project root directory in this format where username and password are the Reddit credentials. The HEADLESS variable, which is passed into Puppeteer, defaults to true if missing.

USERNAME=username
PASSWORD=password
HEADLESS=true

Then, create the ~/.reddit/pending/ directory.

Now, for each scheduled post, create a folder containing a string in the format YYYY-mm-dd HH-MM-SS in ~/.reddit/pending/ where the folder name corresponds to the scheduled time. The folder name can include extra characters as identification such as 2024-01-28 11-23-00 an interesting post, which are ignored by the script.

Create a JSON file at ~/.reddit/pending/YYYY-mm-dd HH-MM-SS/data.json with these fields:

| fields | description | |---------------|--------------------------------------------------------------------------------------------------------------------------| | .subreddit | The name of subreddit with the r/ part. This could start with u/ or user/ instead if we're posting to a user page. | | .title | The title of the post. | | .type | The type of post. Check the subsections below for more info. | | .oc | Whether or not to mark post as OC. Defaults to false. | | .spoiler | Whether or not to mark post as spoiler. Defaults to false. | | .nsfw | Whether or not to mark post as NSFW. Defaults to false. | | .flair | A string representing the flair or null for no flair. Defaults to no flair. | | .comments | An array of comments to add as strings, or null for no comments. Defaults to no comments. | | .maxRetries | The maximum number of retries. Defaults to 0. |

You can also refer to the data.schema.json schema file.

Here's an example data.json. 1.png and 2.png are in the same directory as data.json.

{
  "subreddit": "r/subreddit",
  "title": "title",
  "type": "gallery",
  "images": [
    {
      "file": "1.png",
      "caption": "caption",
      "link": "https://example.com"
    },
    {
      "file": "2.png",
      "caption": null,
      "link": null
    }
  ],
  "oc": false,
  "spoiler": false,
  "nsfw": false,
  "flair": "flair",
  "comments": [
    "comment 1",
    "comment 2"
  ]
}

Text posts

For text posts, the .type field should be text or post. Additionally, there are these fields:

| fields | description | |---------|--------------------------------------------| | .body | The body of the post. Defaults to no body. |

Image posts

For image posts, the .type field should be image. Additionally, there are these fields:

| fields | description | |---------|--------------------------------------------------------------| | .file | The path to the file of the image relative to the JSON file. |

Gallery posts

For gallery posts, the .type field should be gallery or images. Additionally, there are these fields:

| fields | description | |----------------------|----------------------------------------------------------------------------| | .images | An array specifying the file, caption, and link for each image. | | .images[i].file | The path to the file of the image post relative to the JSON file. | | .images[i].caption | The caption of the image or null for no caption. Defaults to no caption. | | .images[i].link | The link of the image or null for no link. Defaults to no link. |

Video posts

For video posts, the .type field should be video. Additionally, there are these fields:

| fields | description | |--------------|------------------------------------------------------------------------------------------------| | .file | The path to the file of the video relative to the JSON file. | | .thumbnail | An integer from 1 to 10 inclusive indicating the thumbnail to choose. Defaults to first image. | | .gif | Whether or not to convert video to GIF. Defaults to false. |

Link posts

For link posts, the .type field should be link or url. Additionally, there are these fields:

| fields | description | |--------|-----------------------| | .url | The url for the post. |

Running

# To run in the foreground, run this
npm run start:fg

# To run in the background, run this
npm run start:bg
# or this
npm start

# To stop the script, run this
npm stop

# To schedule a post using the GUI, run this
npm run schedule

# To reschedule all tasks in ~/.reddit/pending/, run this
npm run reschedule

If an instance is already running, that instance will be stopped.

New folders added to ~/.reddit/pending/ are automatically scheduled.

After the post is made, its folder will be moved to ~/.reddit/done/, or if it failed, its folder will be moved to ~/.reddit/failed/.

Using npm install -g reddit-scheduler

It is also possible to install this package using npm install -g reddit-scheduler, in which case there is a different way to run the scripts:

# To run in the foreground, run this
reddit start:fg

# To run in the background, run this
reddit start:bg
# or this
reddit start
# or this
reddit

# To stop the script, run this
reddit stop

# To schedule a post using the GUI, run this
reddit schedule

# To reschedule all tasks in ~/.reddit/pending/, run this
reddit reschedule

Running at startup

It may be useful to run this script at startup. Note that you may use reddit as the program name instead of npm start prefix=/path/to/reddit-scheduler if you used npm install to install this package.

Windows

Create a task in Task Scheduler to run at log in with npm as the program and start prefix=/path/to/reddit-scheduler where /path/to/reddit-scheduler is the path to the project root as the arguments.

macOS

Go to System Settings > General > Login Items, and add the run.sh script to Open at Login.

Linux

Create the file ~/.config/autostart/reddit-scheduler.desktop with this content (remember to change the Exec path):

[Desktop Entry]
Type=Application
Name=reddit-scheduler
Exec=npm start prefix=/path/to/reddit-scheduler
StartupNotify=false
Terminal=false