Skip to content

Feed of new articles events

Gregor Leban edited this page Mar 20, 2019 · 8 revisions

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:

from eventregistry import *
import time

er = EventRegistry(apiKey = YOUR_API_KEY)
recentQ = GetRecentArticles(er, maxCount = 200)
starttime = time.time()
while True:
    articleList = recentQ.getUpdates()
    print "%d articles were added since the last call" % len(articleList)

    # do whatever you need to with the articles in articleList

    # wait exactly a minute until next batch of new content is ready
    time.sleep(60.0 - ((time.time() - starttime) % 60.0))

Each call to the recentQ.getUpdates(er) 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

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:

from eventregistry import *
import time

er = EventRegistry(apiKey = YOUR_API_KEY)
recentQ = GetRecentEvents(er, maxCount = 200)
starttime = time.time()
while True:
    ret = recentQ.getUpdates()
    if ret.has_key("eventInfo") and isinstance(ret["eventInfo"], dict):
        # how many events updated since last call (each event can be updated multiple times)
        print "%d events updated since last call" % len(ret["activity"])

        # get URIs of the events that are new/updated
        uris = ret["eventInfo"].keys()

        # use the details about events in ret["eventInfo"]

    # wait exactly a minute until next batch of new content is ready
    time.sleep(60.0 - ((time.time() - starttime) % 60.0))

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