ctl

command module
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

README

Cloudcat Ctl

ctl is a command line client for cloudcat.

Usage

run the Model

cat << EOF | cloudcat run -m -
source:
  name: HackerNews
  http: https://news.ycombinator.com/best
  timeout: 60s
schema:
  type: array
  init:
    - gq: "#hnmain tbody -> slice(2) -> child('tr:not(.spacer,.morespace,:last-child)')"
      js: |
        content?.reduce((acc, v, i, arr) => {
          if (i % 2 === 0) {
            acc.push(arr.slice(i, i + 2).join(''));
          }
          return acc;
        }, []);
  properties:
    index:
      type: integer
      rule:
        - gq: .rank
          regex: /[^\d]/
    title: { gq: .titleline>:first-child }
    by: { gq: .hnuser }
    age: { gq: .age }
    comments:
      type: integer
      rule:
        - gq: .subline>:last-child
          regex: /[^\d]/
EOF

run the JavaScript

cat << EOF | cloudcat run -s -
const http = require('cloudcat/http');
let res = http.get('https://news.ycombinator.com/best');
let stories = cat.getElements('gq', "#hnmain tbody -> slice(2) -> child('tr:not(.spacer,.morespace,:last-child)')", res.string());
stories?.reduce((acc, v, i, arr) => {
    if (i % 2 === 0) {
        let item = arr.slice(i, i + 2).join('');
        let index = cat.getString('gq', '.rank', item);
        let title = cat.getString('gq', '.titleline>:first-child', item);
        let by = cat.getString('gq', '.hnuser', item);
        let age = cat.getString('gq', '.age', item);
        let comments = cat.getString('gq', '.subline>:last-child', item);
        acc.push({
            index: parseInt(index?.replace(/[^\d]+/g, ''), 10),
            title: title,
            by: by,
            age: age,
            comments: parseInt(comments?.replace(/[^\d]+/g, ''), 10)
        });
    }
    return acc;
}, []);
EOF

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
Package api the api service
Package api the api service
v1
Package v1 the version 1 api
Package v1 the version 1 api
Package cache a low-level key/value store in pure Go
Package cache a low-level key/value store in pure Go
Package cmd implements the command-line.
Package cmd implements the command-line.
Package config the configuration
Package config the configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL