![]() Our feed data is now available in feed, as we demonstrated by setting the modified and etag variables from this data. Note that we are sending in the variables on our first fetch of the feed as well: however, since they are simply empty strings, they will not prevent us from fetching the data.įeed = feedparser.parse(url, etag=etag, modified=lm) ![]() (This would cause problems with flooding.) We then parse the feed, using feedparser, and store our conditional get information into the variables we previously defined. We first initialize a count variable, so that we don't send several dozen entries to the IRC server all at once when we first get them. Now that we have our variables defined, we can build the infinite loop that will be controlling our output. The first step is to initialize a set of variables we're going to be using repeatedly, which we don't want to go out of scope when the loop ends: Now that we have a vague idea about how the IRC framework we're using works, we can write the code which will actually scan the RSS and pass the messages along. Note that you will need to consult IRC documentation for information about what these commands require: ircbot.py is a simplistic framework designed around message passing and does not typically offer support for all the intricacies of the IRC protocol. You can see based on the examples, that the way to pass messages is via the bot.msg function call, which will send a message given the sender of the original message - this automatically determines whether the message is in a channel or private message, and includes rate limiting to prevent it from being automatically kicked off a server.Īdditionally, the bot has a bot.todo method, which can be used to pass direct IRC commands: the bye function in the example bot demonstrates how to use this, by directly sending information for a server command. We will use a binding like this to start our bot fetching RSS, after which it will continue automatically until the bot dies. ircbot.py is built around the idea of triggers as starting points for functions: at the end of the ircbot.py code we see function definitions, and rule bindings which match these function definitions to certain regular expressions. Most IRC bots respond to specific ``trigger'' words or phrases from users. Once we have both these files in place, we will learn a little bit about how the IRC framework we're using works. Once you've done this, we can get to work with building the code which will display our updates for us. This Python-based bot framework is easily extended in a number of different ways, making it an ideal starting base for many simple projects. Again, this is a simple, one-file Python program which acts as an IRC bot, available from. Palmer's ircbot.py framework and place it in the same directory. Once you've downloaded the Feedparser code, create a directory to contain your bot, and place the feedparser.py file into this directory. The module is entirely contained in a single file, and the latest version can be downloaded from the website. This library is a well-maintained, well tested Python module for parsing all the types of feeds in the wild today. Mark Pilgrim's Universal Feed Parser is available from. Palmer to create an IRC bot that will deliver the latest news right to any channel you have the bot sit in. With this hack, we'll show how to use Mark Pilgrim's Universal Feedparser package, along with a simple IRC framework, ircbot.py, from Sean B. Given that for many users use IRC as their always-on communication method, critical RSS updates passed into IRC fits right into the workflow for these users. With this in mind, it is easy to see why it might be beneficial to have RSS updates dropped into an IRC channel. For many users, IRC becomes an extension of the shell, a tool to be used to store and pass along information. ![]() With that in mind, IRC has become a haven for small tools to integrate into daily life, everything from reminder bots to message passing bots to weather lookups. For that reason, IRC is a communication method that is popular among these users, in large part due to its extremely cross-platform client base, compared to most other communication protocols. Most everywhere a hacker goes, she'll have trusty access to a shell with her.
0 Comments
Leave a Reply. |