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

sromg-api

v2.1.2

Published

A scraper based api for SRoMG comics and authors

Downloads

4

Readme

SRoMG API v2


About

v2.X.X brings about a complete rework of how the API works, previously it was a bodged together mess that didn't bother to render the html rather just did a bunch of linear searches which caused problems in that some comic pages would be formatted differently than others.

This new API is also an API wrapper and is packaged up into a node module, though the API will still function through calls to http://garfield-comics.glitch.me/API.

What's new?

  1. Improved performance.
  2. Promise based event-driven wrapper included.
  3. Gets all the information regardless of how the page is formatted.
  4. Can now get information on authors.

How to use the module

To run the API locally rather than making requests to my site you need to install it from npm or GitHub: npm i sromg-api

When you have downloaded the module you can include it in your project through require() as shown:

// setting up constants
const sromg_api = require('sromg-api');
const META      = new sromg_api.META();
const FLAGS     = sromg_api.FLAGS;
const util      = require('util');
const { JSDOM } = require('jsdom');
const got       = require('got');

// PROMISE BASED EXAMPLE

Client.on("message", async msg => {

    if(!msg.content.equals("sromg")) return;

    let latest_sromg = await got(`http://www.mezzacotta.net/garfield/`)
    const { DOM } = (new JSDOM(latest_sromg.body)).window;

    let NUMBER_OF_SROMG_COMICS = (new sromg_api.Comic(DOM)).number

    msg.reply({attachment: await META.getComic(Math.random() * NUMBER_OF_SROMG_COMICS) });
});


// EVENT DRIVEN EXAMPLE
// event listeners, you can also listen for error events as detailed in the documentation

META.on("AUTH_INIT_SUCCESS", author => {
    // do something with author object, shown below this code snippet
})

META.on("COMIC_INIT_SUCCESS", comic => {
    // do something with comic object, shown below this code snippet
})




// init for author "Roytheshort" with no event logs, this will trigger the AUTH_INIT_SUCCESS event once complete
META.init({
    n: 464,
    FLAGS: FLAGS.META_PARSER_PARSE_AUTHOR | FLAGS.META_PARSER_NO_EVENT_LOGS
})

// init for author "Andrew Kepple"
META.init({
    n: 103,
    FLAGS: FLAGS.META_PARSER_PARSE_AUTHOR
})


// init for comic 2828 with no flags
META.init({
    n: 2828,
    FLAGS: 0
})

Author and Comic objects in detail

AUTHOR

{
    "name":   "Authors name",
    "number": <Number of author>,
    "bio":    "Authors biography if they have one",
    "comics": {
        "comics": [<Array>, <of>, <comic>, <numbers>],
        "buffer": <number of comics in the buffer>
    }
}

COMIC

{
    "name":   "Comic title",
    "number": <Number of comic>,
    "image":  {
        "src": "url of the comic image",
        "x":   <number of pixels wide>,
        "y":   <number of pixels tall>
    },
    "author": {
        "name":   "name of author",
        "number": <number of author>
    },
    "transcription": "The provided transcription, no guarantee that this is accurate",
    "authorWrites":  "The authors notes on the comic WITH ALL HTML TAGS STILL INCLUDED, you may want to translate this to markdown applicable to your solution",
    "originalStrips": [
        {"strip": "date of strip", "href": "link to strip"},
        {"strip": "date of strip", "href": "link to strip"},
        ...
        ...
        {"strip": "date of strip", "href": "link to strip"}
    ]
}