Email RSS feed

    There is one important RSS feed for me. And I want to quickly find out about the “new news” in it. Unfortunately, this news server does not provide mailing. I’m used to using the Google Reader Web service to read RSS, and it, despite its origin and family ties with Gmail, doesn’t give such an opportunity either. And his mobile client does not notify about the appearance of news in the feeds. Maybe thank God - some feeds are very prolific - but there are times when this is useful. This is how I got out.


    A little google, I found a fairly simple solution. Great automation service - ifttt.com(If This Then That). The service allows you to create if-then rules and supports the darkness of social networks and other services. In particular, you can create a rule that when news appears in a specific feed, an email will be sent to such and such a mailbox. It seems to be what you need, but a few moments haunted. What are the disadvantages I see here:

    1. In Google Reader, you need to create a feed that you don’t have to use in practice. After all, if I receive mail about new events, why do I need this feed in the client?
    2. This means that unread news will accumulate in this feed. Clean them so that they don’t loom ...
    3. You must create a folder specifically for the tape so that ifttt can identify the tape. This is already a feature of ifttt working with Google Reader.
    4. In order to use ifttt, you have to register in it. Another account, how much can you?

    What to come up with? Definitely need a server solution. And here the Good Corporation comes to the rescue, all such in white, if it doesn’t close any service again. I remembered about Google Apps Script and Google Drive. The solution is very simple. Create a table on the Goolge Disk and add the following script to it (menu “Tools” => “Script editor ...”):

    function onTimer() {
      var sheet = SpreadsheetApp.getActiveSheet();
      var maxPubDate = new Date(sheet.getRange(1, 1).getValue());
      var txt = UrlFetchApp.fetch("http://habrahabr.ru/rss/best/").getContentText();
      var doc = Xml.parse(txt, false);
      var channel = doc.getElement().getElement("channel");
      var mailBody = "";
      var items = channel.getElements("item")
      var curMaxPubDate = maxPubDate;
      var hasNews = false;
      for (var i in items) {
        var pubDate = new Date(items[i].getElement("pubDate").getText());
        if (pubDate > maxPubDate) {
          if (pubDate > curMaxPubDate) {
            curMaxPubDate = pubDate
          }
          hasNews = true;
          mailBody += "\nЗаголовок: " + items[i].getElement("title").getText();
          mailBody += "\nСсылка: " + items[i].getElement("link").getText();
          mailBody += "\nДата публикации: " + pubDate;
          mailBody += "\n";
        }
      }
      if (hasNews) {
        GmailApp.sendEmail("xxxxxxxx@gmail.com", "Новости Хабра!", mailBody);
        sheet.getRange(1, 1).setValue(curMaxPubDate);
      }
    }
    

    Yes, we must not forget to enter some ancient date in cell A1, “01/30/2002 13:00:00”, as an option. Then install the script to run, for example, every 10 minutes. To do this, in the script editor, select the menu item “Resources” => “Triggers of the current project ...” and add “dynamic minute timer”.

    The script receives the contents of the feed, parses, selects news whose publication date exceeds the date from cell A1, and sends them to me by mail. Towards the end he puts in A1 the biggest date he found.

    For the sake of simplicity and conciseness, the script lacks parsing of the Atom protocol. Well, it’s worth adding a list of observed feeds to the table, but this is already a technical matter.

    It turns out that I did not need RSS clients, automation servers and additional accounting. Only my Google. Just in case, I emphasize that the above is not a replacement for RSS clients. This is just an email notification of one or two of your favorite feeds.

    To my shame, I must admit that this is the first time it occurred to me to use Google Apps Script. Have you ever used Google Apps Script? If this is not a secret, please share your experience in the comments - for what tasks?

    UPD:
    I added parsing the Atom protocol and monitoring multiple feeds. Details on my blog .

    Also popular now: