Skip to content

Commit

Permalink
Merge pull request #53 from skx/feat/rss
Browse files Browse the repository at this point in the history
Added 'rss' sub-command because it is easier than sed/awk
  • Loading branch information
skx authored Nov 6, 2024
2 parents aebfb97 + d07f876 commit 3a49ea6
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 36 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* [Github Setup](#github-setup)




# SysBox

This repository is the spiritual successor to my previous [sysadmin-utils repository](https://github.com/skx/sysadmin-util)
Expand All @@ -20,7 +22,6 @@ The idea here is to collect simple utilities and package them as a single binary




## Installation

Installation upon a system which already contains a go-compiler should be as simple as:
Expand All @@ -40,7 +41,6 @@ Finally may find binary releases for various systems upon our [download page](ht




## Bash Completion

The [subcommand library](https://github.com/skx/subcommands) this application uses has integrated support for the generation of a completion script for the bash shell.
Expand Down Expand Up @@ -88,6 +88,7 @@ More complete help for each command should be available like so:
Examples are included where useful.



## calc

A simple calculator, which understands floating point-operations, unlike `expr`, and has some simple line-editing facilities built into its REPL-mode.
Expand All @@ -112,6 +113,7 @@ $
Here you see the magic variable `result` is always updated to store the value of the previous calculation.



## choose-file

This subcommand presents a console-based UI to select a file. The file selected will be displayed upon STDOUT. The list may be filtered via an input-field.
Expand All @@ -126,6 +128,7 @@ Useful for launching videos, emulators, etc:
The first form is preferred, because if the selection is canceled nothing happens. In the second-case `xine` would be launched with no argument.



## choose-stdin

Almost identical to `choose-file`, but instead of allowing the user to choose from a filename it allows choosing from the contents read on STDIN. For example you might allow choosing a directory:
Expand All @@ -135,18 +138,21 @@ $ find ~/Repos -type d | sysbox choose-stdin -execute="firefox {}"
```



## chronic

The chronic command is ideally suited to wrap cronjobs, it runs the command you specify as a child process and hides the output produced __unless__ that process exits with a non-zero exit-code.



## comments

This is a simple utility which outputs the comments found in the files named upon the command-line. Supported comments include C-style single-line comments (prefixed with `//`), C++-style multi-line comments (between `/*` and `*/`), and shell-style comments prefixed with `#`.

Used for submitting pull-requests to projects about typos - as discussed [here upon my blog](https://blog.steve.fi/i_m_a_bit_of_a_git__hacker__.html).



## collapse

This is a simple tool which will read STDIN, and output the content without any extra white-space:
Expand All @@ -155,6 +161,7 @@ This is a simple tool which will read STDIN, and output the content without any
* Empty lines will be skipped entirely.



## cpp

Something _like_ the C preprocessor, but supporting only the ability to include files, and run commands via `#include` and `#execute` respectively:
Expand All @@ -165,6 +172,7 @@ Something _like_ the C preprocessor, but supporting only the ability to include
See also `env-template` which allows more flexibility in running commands, and including files (or parts of files) via templates.



## env-template

Perform expansion of golang `text/template` files, with support for getting environmental variables, running commands, and reading other files.
Expand All @@ -185,6 +193,7 @@ see it is possible to execute arbitrary commands and read their output. This fa
See also `cpp` for a less flexible alternative which is useful for mere file inclusion and command-execution.



## exec-stdin

Read STDIN, and allow running a command for each line. You can refer to
Expand All @@ -199,6 +208,7 @@ $ ps -ef | sysbox exec-stdin echo field1:{1} field2:{2} line:{}
See the usage-information for more details (`sysbox help exec-stdin`), but consider this a simple union of `awk`, `xargs`, and GNU parallel (since we can run multiple commands in parallel).



## expect

expect allows you to spawn a process, and send input in response to given output read from that process. It can be used to perform simple scripting operations against remote routers, etc.
Expand All @@ -217,6 +227,7 @@ For examples please consult the output of `sysbox help expect`, but a simple exa
```



## find

The find sub-command allows finding files/directories that match a given number
Expand All @@ -233,28 +244,33 @@ By default the names of files are shown, but you can view either files, director
/etc/sane.d/magicolor.conf



## fingerd

A trivial finger-server.



## html2text

A simple tool for converting from HTML to Text, added when I realized I'd
connected to a system over `ssh` and there were no console viewers installed,
(such as `lynx`, `links`, or `w3m`).



## httpd

A simple HTTP-server. Allows serving to localhost, or to the local LAN.



## http-get

Very much "curl-lite", allows you to fetch the contents of a remote URL. SSL errors, etc, are handled, but only minimal options are supported.



## ips

This tool lets you easily retrieve a list of local, or global, IPv4 and
Expand All @@ -263,83 +279,104 @@ than trying to parse `ip -4 addr list`, although that is also the
common approach.



## markdown-toc

This tool creates a simple Markdown table-of-contents, which is useful
for the `README.md` files as used on github.



## make-password

This tool generates a single random password each time it is executed, it is designed to be quick and simple to use, rather than endlessly configurable.



## rss

Show a summary of the contents of the given RSS feed. By default the links to the individual entries are shown, but it is possible to use a format-string to show more.



## run-directory

Run every executable in the given directory, optionally terminate if any command returns a non-zero exit-code.

> The exit-code handling is what inspired this addition; the Debian version of `run-parts` supports this, but the CentOS version does not.


## splay

This tool allows sleeping for a random amount of time. This solves the problem when you have a hundred servers all running a task at the same time, triggered by `cron`, and you don't want to overwhelm a central resource that they each consume.



## ssl-expiry

A simple utility to report upon the number of hours, and days, until a given TLS certificate (or any intermediary in the chain) expires.

Ideal for https-servers, but also TLS-protected SMTP hosts, etc.



## timeout

Run a command, but kill it after the given number of seconds. The command is executed with a PTY so you can run interactive things such as `top`, `mutt`, etc.



## todo

A command to look for TODO items which contain dates in the past, the idea
being that you can record notes for yourself, along with deadlines, in your
code. Later you can see which deadlines have been exceeded.



## tree

Trivial command to display the contents of a filesystem, as a nested tree. This is similar to the standard `tree` command, without the nesting and ASCII graphics.



## urls

Extract URLs from the named files, or STDIN. URLs are parsed naively with a simple regular expression and only `http` and `https` schemes are recognized.



## validate-json

Validate JSON files for correctness and syntax-errors.



## validate-xml

Validate XML files for correctness and syntax-errors.



## version

Report the version of the binary, when downloaded from our [release page](https://github.com/skx/sysbox/releases).



## validate-yaml

Validate YAML files for correctness and syntax-errors.



## watch

Execute the same command constantly, with a small delay. Useful to observe a command-completing.



## with-lock

Allow running a command with a lock-file to prevent parallel executions.
Expand All @@ -348,11 +385,14 @@ This is perfect if you fear your cron-jobs will start slowing down and overlappi




# Future Additions?

Unlike the previous repository I'm much happier to allow submissions of new utilities, or sub-commands, in this repository.




# Github Setup

This repository is configured to run tests upon every commit, and when
Expand Down
95 changes: 95 additions & 0 deletions cmd_rss.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/mmcdole/gofeed"
)

// Structure for our options and state.
type rssCommand struct {
// format contains the format-string to display for entries.
// We recognize "$link" and "$title". More might be added in the future.
format string
}

// Arguments adds per-command args to the object.
func (r *rssCommand) Arguments(f *flag.FlagSet) {
f.StringVar(&r.format, "format", "$link", "Specify the format-string to display for entries")
}

// Info returns the name of this subcommand.
func (r *rssCommand) Info() (string, string) {
return "rss", `Show details from an RSS feed.
Details:
This command fetches the specified URLs as RSS feeds, and shows
their contents in a simple fashion. By default only the entry URLs
are shown, but a format-string may be used to specify the output.
For example to show the link and title of entries:
$ sysbox rss -format='$link $title' http://,..
Suggestions for additional fields/details to be displayed are
welcome via issue-reports.
Usage:
$ sysbox rss url1 url2 .. urlN
Note:
Care must be taken to escape, or quote, the '$' character which
is used in the format-string.
`
}

// Process each specified feed.
func (r *rssCommand) processFeed(url string) error {

fp := gofeed.NewParser()
feed, err := fp.ParseURL(url)
if err != nil {
return err
}

for _, ent := range feed.Items {
txt := os.Expand(
r.format,
func(s string) string {
switch s {
case "content":
return ent.Content
case "link":
return ent.Link
case "title":
return ent.Title
default:
return s
}
},
)

fmt.Println(txt)
}
return err
}

// Execute is invoked if the user specifies `rss` as the subcommand.
func (r *rssCommand) Execute(args []string) int {

for _, u := range args {

err := r.processFeed(u)
if err != nil {
fmt.Printf("Failed to process %s: %s\n", u, err)
}
}

return 0
}
Loading

0 comments on commit 3a49ea6

Please sign in to comment.