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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
articles = [];
var start = new Date("2022-02-24");
var end = new Date();
async function calculatePageviews() {
for (date = start; date < end; date.setTime(date.getTime() + 24 * 3600 * 1000)) {
// console.log(date);
await fetch(
'https://wikimedia.org/api/rest_v1/metrics/pageviews/top/uk.wikipedia.org/all-access/'
+ date.getFullYear()
+ '/'
+ ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1)
+ '/'
+ (date.getDate() < 10 ? '0' : '') + date.getDate()
).then(value => {
return value.json();
}).then(data => {
if (!data.items) {
return;
}
returnedArticles = data.items[0].articles;
returnedArticles.map(article => {
articles[article.article] = (articles[article.article] ?? 0) + article.views;
});
});
}
console.log(
Object.keys(articles)
.map(title => {
return {title: title, views: articles[title]};
})
.sort((a, b) => {
return b.views - a.views;
}));
}
calculatePageviews();