5 ms·
This JavaScript seems to work. You can run it from the browser console or from node.js. (async function () { // see https://hn.algolia.com/api co
by gabrielsroka 4y ago
This JavaScript seems to work. You can run it from the browser console or from node.js.
(async function () {
// see https://hn.algolia.com/api
console.clear();
const posts = {};
var page = 0;
var oldDate;
while (true) {
console.log('fetching page', page);
const r = await fetch(`https://hn.algolia.com/api/v1/search_by_date?tags=story,author_whoishiring&page=${page++}`);
const res = await r.json();
if (res.message) {
console.log(res.message);
} else {
for (const h of res.hits) {
var match;
if (match = h.title.match(/Who wants to be hired\? \((.*)\)/i)) {
var date = match[1];
if (date != oldDate) {posts[date] = {}; oldDate = date;}
posts[date].wants = h.num_comments;
if (posts[date].hiring) posts[date].ratio = posts[date].wants / posts[date].hiring;
} else if (match = h.title.match(/Who is hiring\? \((.*)\)/i)) {
date = match[1];
if (date != oldDate) {posts[date] = {}; oldDate = date;}
posts[date].hiring = h.num_comments;
if (posts[date].wants) posts[date].ratio = posts[date].wants / posts[date].hiring;
}
}
}
if (page == res.nbPages) break;
}
console.table(posts);
})();