Skip to content

Feed of new articles events

Gregor Leban edited this page Sep 3, 2026 · 9 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, recentActivityArticlesMaxArticleCount = 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 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.

The GetRecentArticles constructor accepts the following parameters:

  • eventRegistry: an instance of the EventRegistry class
  • mandatorySourceLocation [default: False]: if True, return only articles from sources for which we know the geographic location
  • articleLang [default: None]: None, a string or a list of strings - return all articles or only articles in the specified language(s)
  • returnInfo: what details should be included in the returned articles. See details.
  • any additional keyword arguments (such as recentActivityArticlesMaxArticleCount in the example above) are sent along with the request

NOTE: the results are computed once a minute, so call the getUpdates() method exactly once per minute. Calling it more frequently will return the same results multiple times, calling it less frequently will miss some results.

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)
starttime = time.time()
while True:
    ret = recentQ.getUpdates()
    if "eventInfo" in ret 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 = list(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.

The GetRecentEvents constructor accepts the following parameters:

  • eventRegistry: an instance of the EventRegistry class
  • mandatoryLang [default: None]: if set (a string or a list of strings), return only events that are covered at least by the specified language(s)
  • mandatoryLocation [default: True]: if True, return only events that have a known geographic location
  • returnInfo: what details should be included in the returned events. See details.

Clone this wiki locally