Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Tool to list all questions with only 1 or 2 answers on travel.stackexchange.com

View travel-se-1-or-2-answers.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
<html>
<head>
<title>Travel StackExchange / jQuery / Stack Exchange API / YQL / CORS</title>
<script id="jqs" type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<style type="text/css">
.container {
width:100%;
}
.left {
width:75%;
float:left;
}
.right {
width:25%;
float:right;
}
.one, .one a {
color:red
}
.two {
color:blue
}
.warn {
background-color:yellow
}
.err {
background-color:red
}
</style>
 
<script type="text/javascript">
$(document).ready(function(){
var hit = 0;
var ajaxarray = new Array();
$.getJSON("http://api.travel.stackexchange.com/1.1/questions?jsonp=?",
{
pagesize: 0
},
function(data) {
if (data.error) {
$("<div/>").text("error getting number of pages").appendTo("#output");
} else {
var remainder = data.total % 100;
var pagecount = (data.total - remainder) / 100 + (remainder != 0);
$("#qt").text(data.total);
for (var page = 1; page <= pagecount; ++page) {
ajaxarray.push($.getJSON("http://api.travel.stackexchange.com/1.1/questions?jsonp=?",
{
order: "asc",
page: page,
pagesize: 100,
sort: "creation"
},
function(data) {
if (data.error) {
$("<div/>").text("error getting page " + page).appendTo("#output");
} else {
$.each(data.questions, function(i, q){
if (q.answer_count >= 1 && q.answer_count <= 2 && !("closed_date" in q)) {
// maintain this list in order using binary search
var ol = $("#list");
var needle = q.question_id;
var high = ol.children("li").length;
var low = 0;
var mid;
var id;
while (low < high) {
mid = parseInt((low + high) / 2)
id = $("ol#output li:nth-child(" + (mid+1) + ")").attr('id');
if (needle < id) {
high = mid;
} else {
low = mid + 1;
}
}
id = $("ol#output li:nth-child(" + (low+1) + ")").attr('id');
var li = $("<li id=\"" + q.question_id + "\" class=\"" + ["one", "two"][q.answer_count - 1] + "\">" +
"<a href=\"http:\/\/travel.stackexchange.com\/questions\/" + q.question_id + "\/\">" + q.title + "</a></li>");
if (typeof id == "undefined") {
li.appendTo("#list");
} else {
li.insertBefore("#" + id);
}
$("#hit").text(++hit);
}
});
}
}
));
}
$.when.apply($, ajaxarray).then(function() {
$("<span/>").text("ALL DONE").appendTo("#info");
});
}
}
);
});
</script>
</head>
<body>
<span id="info">Travel Stack Exchange little-answered questions tool. <span id="qt">?</span> questions in total, <span id="hit">?</span> have only 1 or 2 answers...</span>
 
<hr>
 
<div id="output"/>
<ol id="list"/>
 
</body>
</html>

This works fine in that it does get questions with only 1-2 answers. Documented as searching for 2-3 answer questions in description though.

Owner

Hmm what did Mark ask for again? 1 & 2 or 2 & 3?

1-2, afaik

Owner

OK changed the title and renamed the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.