sopel-rss is an RSS module for the IRC bot framework sopel.
The Ansible role ansible-role-sopel-runit-debian can be used to deploy the bot from Github to Debian using runit.
Put rss.py in your ~/.sopel/modules directory.
The rss module posts items of rss feeds to irc channels. It hashes the feed items and stores the hashes in a ring buffer in memory and in a sqlite database on disk. It uses one ring buffer and one database table per feed in order to avoid reposting old feed items.
All commands require owner or admin privileges.
Add the feed <url> to <channel> and call it <name>. Options may be specified, see Formats and Templates. The feed will be read approximately every minute and new items will be automatically posted to <channel>.
Print the color code and the name of each color and use the color as background color and print the codes and names for bold, italic and underline.
Get a <key> from the configuration file or set a <value> of a <key> and the consequences will be applied immediately. Use .rss help config to see which keys are available. Use .rss help config <key> to get a detailed explanation of <key>.
Delete the feed called <name>.
Get the item fields of the feed <name>.
Get the format of the feed <name>. Or set the format of the feed <name> to <format>.
Post all items of the feed to the channel of the feed. Mainly useful for debugging.
Get a list of available commands or get a detailed explanation of a command. Have a look at .rss help config.
List properties of <feed> or list all feeds in <channel>.
Every feed must have a channel associated to it and .rss join joins these channels. This command is only needed in case of problems as channels are automatically joind after adding a feed or restarting the bot.
Get the templates of the feed <name>. Or set templates of the feed <name>.
Calls the internal function which updates the feed every minute. This command is only needed if you want new feed items to be posted immediately.
The following options can be set in the configuration file or via .rss config <key> <value>. The configuration file will be read when the bot is (re)started or when the owner or an admin issues the command .reload rss in a query with the bot. Be aware that the bot mustn't be running when editing the configuration file. Otherwise, your edits may be overwritten!
Synopsis: .rss config feeds <channel1>;<name1>;<url1>[;<options1>],<channel2>;<name2>;<url2>[;<options2>]...
Comma separated list of feed definitions with channel, feedname, url and optionally format separated by semicolons.
Semicolon separated list of default formats which will be used if the fields of the feed fit the format.
Semicolon separated list of template strings which will override the default template strings. Curly brackets will be replaced by the actual string. In the template strings the field and template are separated by a pipe.
A format string defines which feed item fields be be hashed, i.e. when two feed items will be considered equal, and which field item fields will be output by the bot. Both definitions are separated by a '+'. Each valid rss feed must have at least a title or a description field, all other item fields are optional. These fields can be configured for sopel-rss:
field | caption |
---|---|
f | feedname |
a | author |
d | description |
g | guid |
l | link |
p | published |
s | summary |
t | title |
y | tinyurl |
The field f references the feedname and is not a feed item field, guid is a unique identifiert and published is the date and time of publication. tinyurl will work like the field link but it will shorten the url through tinyurl first.
The feedname and the link of the rss feed item will be used to hash the feed item. If an item of a different feed has the same link it will be posted again by the bot. The bot will post the feed item title followed by the feed item link.
The feedname, link, summary and title will be used to hash the feed item. If any of these fields change in the feed the feed item will be posted again. The bot will post the title, author and link of the feed item but not the feedname.
Template strings define how the different fields of a feed item will be posted to the irc channel. You may override some or all of the default template strings. Curly brackets {} will be replaced by the field value. These are the default templates:
field | template |
---|---|
f | %16[{}]%20 |
a | {} |
d | {} |
g | {} |
l | %16→%20 {} |
p | {} |
s | {} |
t | {} |
y | %16→%20 {} |
You can use nearly any character you like but the percent sign % has a special meaning: it is the escape sign. If you want the bot to print a percent sign then you have to specify it twice: if the title of an item is "itemtitle" then t=t|%%{} will output "%itemtitle". The same is true for a comma after an escape sequence: if the title of an item is "itemtitle" then t=t|%17%,{}%20 will output ",itemtitle" in italics.
To print colors you have to use the percent sign and the color code of a foreground color. Optionally you can add a dollar sign and the color code of a background color. Here is a list of all valid color and other formatting codes:
code | name |
---|---|
00 | white |
01 | black |
02 | blue |
03 | green |
04 | red |
05 | brown (maroon) |
06 | purple |
07 | orange (olive) |
08 | yellow |
09 | light green (lime) |
10 | teal (a green/blue cyan) |
11 | light cyan (cyan / aqua) |
12 | light blue (royal) |
13 | pink (light purple / fuchsia) |
14 | grey |
15 | light grey (silver) |
16 | bold |
17 | italic |
18 | underline |
19 | switch colors / "reverse video" |
20 | reset formatting |
(Unfortunately, GitHub does not allow colors in Markdown. Have a look at mirc.com the see real colors.)
The command .rss config templates will show you the current template strings and a matching example output. This is the output of .rss config templates for the default template string (i.e. the value of templates in the config file is empty):
t=a|<{}>;t=d|{};t=f|%16[{}]%16;t=g|{};t=l|%16→%16 {};t=p|({});t=s|{};t=t|{};t=y|%16→%16 {}
Description [Feedname] http://www.example.com/GUID → https://github.com/RebelCodeBase/sopel-rss (2016-09-03 10:00) Description Title → https://tinyurl.com/govvpmm
Underline the title and print it in italics.
Print the time in parentheses and in bright green. Stop the formatting afterwards so that the following fields are not affected by the color change.
Include spaces in a template by using quotes.
Print the feedname in pink on silver in bold. The %16 will stop the bold formatting but as there is no %20 to reset formatting, everything after the field f (depending on the format) will be printed in pink on silver as well.
This module is extensively tested through py.test:
python3 -m pytest -v sopel/modules/rss.py test/test_rss.py
This project is licensed under the GNU General Public License.
I came across f4bio/sopel-rss when I was looking for an rss2irc app. First, I've forked his repo but then the coding took a very different turn so I decided to create a new repository. f4bio, thanks a lot for your inspiration!