Skip to content

Feed of new articles events

Anže Sršen edited this page Dec 12, 2017 · 1 revision

It is very easy in Event Registry to subscribe to a feed of new articles or events.

Feed of new articles

The class GetRecentArticles is able to provide you with new articles as they are imported into Event Registry. A simple example of use would be:

import { EventRegistry, GetRecentArticles, sleep} from "eventregistry";

async function getRecentUpdates(recentQ) {
    const articleList = await recentQ.getUpdates();
    console.info(`${articleList.length} articles were added since the last call`);
    //  do whatever you need to with the articles in articleList
    // wait exactly a minute until next batch of new content is ready
    await sleep(60 * 1000);
    await getRecentUpdates(recentQ);
}

const er = new EventRegistry({apiKey: "YOUR_API_KEY"});
const recentQ = new GetRecentArticles(er, {maxCount: 200});
getRecentUpdates(recentQ);

Each call to the recentQ.getUpdates() will provide you with a list of articles that were added since the last call to the method. Provided information about the articles matches the Article data model.

Feed of new/updated events

Similarly as for the articles, we can also ask Event Registry for a feed of new events. In this case, the list will also include the events that were just updated (for example with a new article about this event). An example code to get the list of new or updated events would be:

import { EventRegistry, GetRecentEvents, sleep} from "eventregistry";

async function getRecentUpdates(recentQ) {
    const ret = await recentQ.getUpdates();
    if (ret["eventInfo"]) {
        // how many events updated since last call (each event can be updated multiple times)
        console.info(`${ret["activity"].length} events updated since last call`);
        // get URIs of the events that are new/updated
        const uris = Object.keys(ret["eventInfo"]);
        // Use the details about events in ret["eventInfo"]
    }
    // wait exactly a minute until next batch of new content is ready
    await sleep(60 * 1000);
    await getRecentUpdates(recentQ);
}

const er = new EventRegistry({apiKey: "YOUR_API_KEY"});
const recentQ = new GetRecentEvents(er, {maxCount: 200});
getRecentUpdates(recentQ);

Provided information about the events in ret["eventInfo"] matches the Event data model.

Clone this wiki locally