Get a comment count from a wordpress blog post using Google Apps Script. Used in http://mashe.hawksey.info/2011/08/and-the-most-engaging-ouseful-info-post-is/
function getCommentCount(){ | |
for (var rowIdx=0; rowIdx < sheet.getLastRow(); rowIdx++){ | |
var rowNum = rowIdx+TITLE_ROW+1; | |
var url = sheet.getRange(rowNum,URL_COL).getValue(); | |
Utilities.sleep(500); | |
try { | |
var options = | |
{ | |
"method" : "get" | |
}; | |
var response = UrlFetchApp.fetch(url+"feed/", options); | |
if (response.getResponseCode() == 200) { | |
var responseStr = response.getContentText(); | |
var XMLdoc = Xml.parse(responseStr); // parse xml | |
var title = XMLdoc.rss.channel.title.getText().replace("Comments on: ",""); | |
if (XMLdoc.rss.channel.item == undefined){ | |
var commentCount = 0; | |
} else { | |
var commentCount = XMLdoc.rss.channel.item.length; | |
} | |
if (commentCount == undefined) | |
commentCount = 1; | |
sheet.getRange(rowNum, TITLE_COL).setValue(title); | |
sheet.getRange(rowNum, COM_COL).setValue(commentCount); | |
} | |
} catch(e) { | |
Logger.log(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment