Skip to content

cameronmurphy/checker

Repository files navigation

Checker

Lint and test

Get notified when stuff changes.

Dev setup (macOS)

Install Homebrew.

brew bundle

Configure your shell for asdf. Restart your terminal session.

asdf plugin install deno
asdf install

Configuration

Copy the example config to the default location and customise as necessary.

mkdir -p ~/.config/checker
cp config.example.yml ~/.config/checker/config.yml
vim ~/.config/checker/config.yml # Set up at least one source and destination

Writing a plugin

Sources

Source plugins by default go in ~/.config/checker/plugins/source. Here's an example, sheeran.ts, which is a plugin that checks whether Ed Sheeran is playing in certain countries any time soon.

import BaseSourcePlugin, {
  zod as z,
} from 'https://raw.githubusercontent.com/cameronmurphy/checker/main/src/plugins/source/base.ts';
import StrlenComparator from 'https://raw.githubusercontent.com/cameronmurphy/checker/main/src/comparator/strlen.ts';
import { DOMParser } from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts';

export default class SheeranSource extends BaseSourcePlugin {
  private schema = BaseSourcePlugin.ConfigSchema.extend({
    items: z.array(z.string()).min(1, 'Sheeran plugin requires at least one country name'),
  });

  public getSchema() {
    return this.schema;
  }

  public async read(item: string) {
    const response = await fetch('https://www.edsheeran.com/#tour');
    const text = await response.text();
    const doc = new DOMParser().parseFromString(text, 'text/html');

    const locations = Array.from(doc?.querySelectorAll('.event_location') || []);
    const relevantLocations = locations.filter((el) => el.textContent?.includes(item));
    const dates = relevantLocations.map((el) => el.parentElement?.querySelector('.event_dates')?.textContent?.trim());
    return dates.filter(Boolean).join();
  }

  public updated(before: string, after: string) {
    return new StrlenComparator().updated(before, after);
  }

  public message(_before: string, after: string, item?: string) {
    return `Ed Sheeran is playing in ${item} on ${after}!`;
  }
}

Then you would configure this plugin like so:

config:
  sources:
    sheeran:
      items:
        - 'Australia'

Scripts

Dev

Run the app and automatically reload when the code changes.

deno task dev

Run

Run the app.

deno task run

Run the app against a different config file.

deno task run --config-file /usr/local/etc/checker/config.yml

Upgrade deps

To upgrade all dependencies:

deno task upgrade-deps

About

Get notified when stuff changes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published