Skip to content

Commit

Permalink
Add support for fetching data on the history of a single wikimedia page
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom committed Nov 14, 2023
1 parent b6ee722 commit fe42d81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/wiki-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ module.exports.fetchWiki = async function fetchWiki(url) {
// based on https://stackoverflow.com/a/8573941
return fetchRSS(url + ".atom");
}
// TODO: handle case of a single wiki page
// handle case of Main_Page
// from there on, this assume we're dealing with a wikimedia instance
url = url.replace(/Main_Page$/, '');
if (url.match(/\/wiki\/.+$/)) { // a specific page of the wiki
const [base, page] = url.split('/wiki/');
return fetchRSS(`${base}/wiki/index.php?title=${page}&feed=atom&action=history&days=1000&limit=1000`);
}
return fetchRSS(url + '/api.php?action=feedrecentchanges&days=1000&limit=1000');
};

13 changes: 13 additions & 0 deletions test/wiki-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ describe('The Wiki Activity monitor', function () {
assert.equal(data[0].isoDate, '2023-11-10T13:24:37.000Z', 'RSS feed item wiki date correctly identified');
});

it('detects activity on a single wiki page', async function() {
const feed = await fs.readFile('test/mock-content/feed.rss', 'utf-8');
const u = new URL("https://example.test/wiki/Test_Page");
agent
.get(u.origin)
.intercept({path: `/wiki/index.php?title=Test_Page&feed=atom&action=history&days=1000&limit=1000`, method: "GET"})
.reply(200, feed);
const { items: data} = await fetchWiki(u.href);
assert.equal(data.length, 1, 'RSS Feed from wikimedia has one item');
assert.equal(data[0].isoDate, '2023-11-10T13:24:37.000Z', 'RSS feed item wiki date correctly identified');
});


it("returns an error when the feed doesn't exist", async function() {
const u = testUrl();
agent
Expand Down

0 comments on commit fe42d81

Please sign in to comment.