Skip to content

Feed of new articles events

Gregor Leban edited this page Nov 28, 2015 · 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()
recentQ = GetRecentArticles(maxArticleCount = 200)
while True:
    articleList = recentQ.getUpdates(er)
    print "%d articles were added since the last call" % len(articleList)
    
    # do whatever you need to with the articles in articleList        

    # wait a while before asking for new articles
    time.sleep(20)     

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.

##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:

from eventregistry import *
import time

er = EventRegistry()

recentQ = GetRecentEvents(maxEventCount = 200)

while True:
    ret = recentQ.getUpdates(er)
    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"]

    # sleep for 20 seconds before checking again for new events
    time.sleep(20)

Clone this wiki locally