What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 150 Stack Exchange communities.

I would like to sort the SO tags by the number of questions asked this week. Is this possible without using the API?

EDIT: I realize now that I shouldn't have asked for an answer strictly WITHOUT using the API. I would be happy also to receive answers showing how I might do it WITH the API.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is a Data Explorer query that shows you the tags sorted by number of questions in the past 7 days.

SELECT Count(*) as total,
FROM   tags AS t
       INNER JOIN posttags
               ON posttags.tagid = t.id
       INNER JOIN posts AS p
               ON p.id = posttags.postid
WHERE p.posttypeid = 1 AND DATEDIFF(DAY,creationdate,GETDATE()) <= 7
GROUP  BY t.id,

You can see the results here.

Theoretically, the following code should do the same using the API (which gives you fresher results), but practically this takes forever because of rate limiting and the sheer volume of questions.

You can see it in action here for the smaller timespan of yesterday's questions. Be warned: even with an authentication token, it takes a long ass time (up to 30-40 seconds).

Here is the code:

var date = new Date();
date.setDate(date.getDate() - 1);

var url = 'http://api.stackexchange.com/2.1/questions?filter=!nR5-WLw0-5&order=desc&pagesize=100&sort=activity&site=stackoverflow&fromdate=' + Math.round(date.getTime() / 1000) + '&callback=?';

var h3 = $('h3 span');
(function gather(cp, object) {
    if (typeof object === "undefined" || object.has_more) {
        $.getJSON(url, {
            page: ++cp,
            key: "awn3X8U)9erzSfhBhqSF4A(("
        }, function(data) {
            h3.html("(" + cp + " pages)")
            if (object) {
                data.items = data.items.concat(object.items);
            gather(cp, data);
    } else {

function display(data) {
    var data = data.items,
        tagcounts = {},
        tags = [];
    for (var i = 0; i < data.length; i++) {
        var q = data[i];
        for (var j = 0; j < q.tags.length; j++) {
            if (typeof tagcounts[q.tags[j]] !== "number") {
                tagcounts[q.tags[j]] = 0;
    for (i in tagcounts) {
        if (tagcounts.hasOwnProperty(i)) {
    tags.sort(function(a, b) {
        return tagcounts[b] - tagcounts[a];
    var total = 0;
    $.each(tags, function(i, v) {
        var li = $('<li/>');
        var a = $('<a/>').attr('href', 'http://stackoverflow.com/tags/' + this + '/info').text(this);
        $('#results').append(li.append(a).append(" : " + tagcounts[this]));
        total += tagcounts[this];

    var heading = $('<h3/>').html('Total: ' + total);
share|improve this answer
The results are probably older than what you can get from the API. –  Robert Harvey Jan 2 '13 at 23:47
@RobertHarvey True. Doing it with the API would involve filtering a bunch of arrays with respect to each other, and I'm too lazy. –  Asad Saeeduddin Jan 2 '13 at 23:49
@RobertHarvey Added an API version, if you're interested. –  Asad Saeeduddin Jan 3 '13 at 1:54
@Asad: That's great thanks. New question: How long will the query you've created there live? If I save the URL will it be available indefinitely? –  John Fitzpatrick Jan 3 '13 at 11:05
@JohnFitzpatrick Yes the URL is always available, but you could also go ahead and save the query itself. –  Asad Saeeduddin Jan 3 '13 at 17:42
@Asad: I did save it thanks. But I'm always losing things. I have my mittens tied to the end of a 6 foot string that runs through my jacket sleeves so I don't lose them again. Mom taught me that. –  John Fitzpatrick Jan 3 '13 at 19:19

You must log in to answer this question.

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