Skip to content

EventRegistry class

gregorleban edited this page Sep 7, 2015 · 22 revisions

EventRegistry is the main class that you are going to need in order to send any kind of request to the Event Registry. You can create an instance of this class as follows:

from eventregistry import *
er = EventRegistry()

The constructor accepts several relevant parameters, that you can modify:

  • host [default: "http://eventregistry.org"]. The URL where the Event Registry is available. When testing some new features, you might need to specify a different URL.
  • logging [default: False]. Should the executed web requests be logged in the requests_log.txt file in the package directory?
  • minDelayBetweenRequests [default: 0.5]. What should be the minimum delay in seconds between two requests sent to Event Registry. Remember that each user has a daily request limit so don't spend the requests too fast.
  • repeatFailedRequestCount [default: -1]. In case a request fails (for example, timeout), how many times should it be repeated before giving up. Use -1 to repeat indefinitely.

Logging in

In case you are a registered user you might wish to log into Event Registry in order to be able to make more requests per day (see Daily restrictions). You can achieve this by calling the EventRegistry.login() method and passing in the username and password. Alternatively, you can also create a settings.json file in the eventregistry package directory. The content of the file should be a simple JSON object:

{
	"username": "YOUR_USERNAME",
	"password": "YOUR_PASSWORD"
}

If this file will be found when creating the EventRegistry instance it will be automatically used for logging you in. In case you have not registered yet, you can use the registration page.

Execute query method

EventRegistry.execQuery(query, convertToDict) This is the method that you will likely use the most since you will use it in order to execute any type of the query (e.g QueryEvents, QueryArticles, GetCounts, ...). If you set convertToDict = True (by default), the returned information will be converted into a Python dict. If False, the original string response will be returned as obtained from Event Registry.

Autosuggest methods

As mentioned in the terminology page, Event Registry operates with concepts, categories and news sources which all have their unique identifiers (URIs). When using the concepts/categories/news sources in search you will refer to them by their URI. As a user you will likely not know these URIs but will instead know the label or part of the label by which it is known. In order to find the URI that you need, Event Registry provides various autosuggest methods. The group of methods suggest*() provides a list of items that best match the input text, while the group of methods get*Uri() return only the URI of the best candidate based on the input text.

Suggest concepts

EventRegistry.suggestConcepts(prefix, 
    lang = "eng", labelLang = "eng", 
    sources = ["concepts"], 
    page = 0, count = 20)`

suggestConcepts method expects a prefix parameter that contains the label of a concept, for which you would like to identify the best candidate concepts. The prefix can be a complete or a partial label. Using the parameter lang, the user can specify in which language is the provided prefix. The value should use an ISO 639-3 language code.

Utility methods