User:Base/Scripts/Fountain/FetchingArticles.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
var slugs = [
    'ukwiki-for-school-2021-geography',
    'ukwiki-for-school-2021-foreign-literature',
    'ukwiki-for-school-2021-mathematics',
    'ukwiki-for-school-2021-world-history',
    'ukwiki-for-school-2021-computer-science',
    // 'ukwiki-for-school-2021-ukrainian-literature',
    'ukwiki-for-school-2021-physics',
];

var articleData = [];

for (var slug of slugs) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "https://fountain.toolforge.org/api/editathons/" + slug, false);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.withCredentials = true;
    xhr.send();

    var parsedResponse = JSON.parse(xhr.response); // no idea why it doesn't happen automatically
    var articles = parsedResponse.articles;
    for (var article of articles) {
        console.log(article);
        var marks = article.marks[Object.keys(article.marks)[0]];
        console.log(marks);
        var mark = marks.marks[Object.keys(marks.marks)[0]];
        articleData.push(
            {
                slug: slug,
                id: article.id,
                title: article.name,
                user: article.user,
                mark: mark,
                juror: marks.user,
                comment: marks.comment
            }
        );
    }

}

console.log(articleData);