Skip to main content

Parse Stack Exchange RSS Feeds Easy Guide!

This tutorial demonstrates how you can Parse Stack Exchange RSS Feeds.

This Google Script will fetch and Parse Stack Exchange RSS Feeds. The content of the RSS feed can then be routinely and automatically pushed to a different email address using the MailApp service. Or you could use Google Scripts to create an RSS to email service. You can use the below mentioned code to Parse Stack Exchange RSS Feeds:

function parseXML() {
  var feed = 'http://stackexchange.com/feeds';

  var xml = UrlFetchApp.fetch(feed).getContentText();
  var root = XmlService.parse(xml).getRootElement();
  var atom = XmlService.getNamespace('http://www.w3.org/2005/Atom');

  var entries = root.getChildren('entry', atom);

  for (var i = 0; i < entries.length; i++) {
    var title = entries[i].getChild('title', atom).getText();
    var categoryElements = entries[i].getChildren('category', atom);

    var updated = entries[i].getChild('updated', atom).getValue();
    var url = entries[i].getChild('id', atom).getValue();
    var summary = entries[i].getChild('summary', atom).getText();
    var user = entries[i].getChildren('author', atom)[0].getChild('name', atom).getValue();
    var userURL = entries[i].getChildren('author', atom)[0].getChild('uri', atom).getValue();

    var regexSubSite = /http:\/\/(.*?).stackexchange\.com/.exec(url);
    var site, siteURL;

    if (!regexSubSite) {
      // If it's not a "subsite"...
      site = /http:\/\/(.*)\.com/.exec(url);
      site = site ? site[1] : 'noneFound';
      siteURL = site ? 'http://www.' + site + '.com' : 'noneFound';
    } else {
      site = regexSubSite[1];
      siteURL = regexSubSite[0];
    }

    // url     - Question URL
    // title   - Question Title
    // user    - Question Author
    // userURL - Author Profile URL
    // site    - Stack Exchange Site Name
    // siteURL - SE Site URL
  }
}

Also read Create Trello Cards from a Google Form with Google Scripts Easy Guide!



from thetechxp https://ift.tt/kWFQOma
via IFTTT

Comments