5

We have been in public beta for a while. One of the many ways our site gets attention is via the Hot Network Questions(HNQ) feed and site bar on StackExchange.

There is a formula that will elect questions from our site into the HNQ feed. This gives certain questions more exposure in the StackExchange network and generates more traffic for the site for a period of time.

These questions serve as representation of what our site is. That should be true always for all of our question but perhaps more so during this HNQ period. Therefore I wanted to come up with a way for us to be aware of when these questions become elected to the HNQ in case it was not already obvious. If the question or current answers could use some touch up it would be in our best interest to address it.

Currently the only HNQ feed we can subscribe to only handles the first 30 questions of the entire SE network. I have a hosted script that reduces the feed to only our questions. It has the name Ember in chat. If you ever see a post from that feed check it to see if it could use some TLC.


How it works

I got the gist of the code given to me by Napoleon over on Movies.SE Chat. I updated the logic a bit both to suit our needs and make it a little more potable and fault tolerant. I also littered it with comments as I didn't understand how it worked at first.

function doGet() 
{
  // This function will take the hot network question feed and filter out all of the questions that are not part of 
  // a particular site as designated by the var filterOn
  var filterOn = "crafts"

  // RSS Url
  var rssFeedUrl = 'http://stackexchange.com/feeds'
  
  // Fetch URL content
  var feed = UrlFetchApp.fetch(rssFeedUrl).getContentText(); 

  // Creates a Document from the given XML, without validating the XML.
  var document = XmlService.parse(feed);
  
  // Gets the document's root Element node. 
  var root = document.getRootElement();
  
  // Creates a Namespace with the given prefix and URI.
  var atom = XmlService.getNamespace('http://www.w3.org/2005/Atom');
  
  // Get the children
  var entries = root.getChildren('entry', atom);
  
  // Cycle each entry and remove it if certain criteria are matched. 
  for (var entryIndex = 0; entryIndex < entries.length; entryIndex++) 
  { 
    // Capture the text if the ID.
    var id = entries[entryIndex].getChildText('id', atom);
    
    // Match the stack exchange sub site. 
    var regex = /http:\/\/(.*?).stackexchange\.com/.exec(id);
    
    // Check to see if it is not null and does not match crafts.
    if(regex == null || regex[1] != filterOn){
      // Remove the entry if it is null or doesnt match crafts
      entries[entryIndex].detach(); 
    }

  }
  
  // Create a new feed with the parsed information from the StackExchange one. 
  feed = XmlService.getCompactFormat().setLineSeparator('\n').setEncoding('UTF-8').setIndent(' ').format(document); 
  
  // Return the new feed object
  return ContentService.createTextOutput(feed).setMimeType(ContentService.MimeType.RSS); 
}

This script is hosted as a webapp on my Google account and given anonymous read access. I then added it as a feed in the chat.

In practice this has been working.

4
  • Hi Matt, is this script still alive?
    – Joachim Mod
    Sep 19, 2020 at 9:09
  • @Joachim I will check on the status of it. I presume it is but I will verify and let you know.
    – Matt
    Sep 21, 2020 at 19:21
  • @Joachim This was done a while ago so I forgot a little about how it works. As best as I can tell it is running again. It looks like it was removed from the feeds attached to the room. I added it again but I am not 100% sure if it works for someone other than me yet.
    – Matt
    Sep 22, 2020 at 0:42
  • Thanks, Matt! I'll let you know if I see anything weird. Or nothing at all.
    – Joachim Mod
    Sep 22, 2020 at 7:02

1 Answer 1

3

I don't see any problems with this. A well-chosen feed in the chat room helps attract attention to our site, and it's also nice to know ASAP when a question hits the HNQ list. Thanks for getting it set up!

2
  • What is the way to use this? Jul 4, 2016 at 8:20
  • 1
    It is a chat "bot" that is always running, so just being in the chat room is all you need to do. It will only say anything when there is a HNQ though.
    – Erica
    Jul 4, 2016 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .