📜 ⬆️ ⬇️

RSS feed by mail

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 a mailing list. I’m used to using the Google Reader web service for reading RSS, and he, in spite of his background and family ties to Gmail, doesn’t provide this feature either. And his mobile client does not notify about the news in the tapes. Maybe thank God - some feeds are very prolific - but there are cases when it is useful. That's how I got out.


A little googling, I found a fairly simple solution. A great automation service is ifttt.com (If This Then That). The service allows you to create rules according to the “if-then” principle and supports the darkness of social networks and other services. In particular, you can create a rule that when news appears in a particular feed, an email will be sent to such and such a box. It seems to be what is necessary, but a few moments did not give rest. What are the flaws I see here:

  1. In Google Reader you need to create a tape that you don’t need 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 still not to loom ...
  3. For the tape, you will have to specifically create a folder so that ifttt can identify this tape. This is already a feature of ifttt with the Google Reader service.
  4. In order to use ifttt, you have to register in it. Another account, how many are you?

What to think of? Definitely need a server solution. And then the Corporation of Good comes to the rescue, all this in white, if again it does not close any service. I remembered 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, one should not forget to enter some ancient date in cell A1, “01/30/2002 13:00:00”, as an option. Then set 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 a “dynamic minute timer”.

The script receives the contents of the tape, parses, selects news, the date of publication of which exceeds the date from cell A1, and sends them to me by mail. Towards the curtain puts in A1 the biggest date that I found.

For the sake of simplicity and brevity, the script lacks Atom protocol parsing. Well, the table should add a list of observed feeds, but this is a matter of technology.

It turns out that I did not need RSS clients, automation servers and additional accounts. Only my google. Just in case, I emphasize - the one described above is not at all a replacement for RSS clients. This is just an email notification of news in one or two favorite tapes.

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

UPD:
I added Atom protocol parsing and monitoring of several feeds. Details in my blog .

Source: https://habr.com/ru/post/168569/


All Articles