21 from eventregistry
import *
36 NewsEngineBase.__init__(self)
39 key_path = os.path.join(os.environ[
'HOME'],
40 '.config/rapp_platform/api_keys/event_registry')
41 if os.path.isfile(key_path):
42 RappUtilities.rapp_print(
'Event Registry Login',
'DEBUG')
43 with open(key_path)
as key_fd:
48 RappUtilities.rapp_print(
'Using event registry without login',
'DEBUG')
64 error =
'Requested negative number of news stories.'
65 RappUtilities.rapp_print(error,
'ERROR')
66 raise RappError(error)
67 elif req.storyNum == 0:
68 warn =
'Requested zero news stories. Providing default number of 5'
69 RappUtilities.rapp_print(warn,
'DEBUG')
73 max_stories = req.storyNum
75 warn =
'Too many stories requested. Truncating to: ' + \
77 RappUtilities.rapp_print(warn,
'DEBUG')
80 max_stories = req.storyNum
if req.storyNum < self.
_max_stories else \
85 for keyword
in req.keywords:
86 q.addConcept(self._event_handler.getConceptUri(keyword))
87 q.addRequestedResult(RequestArticlesInfo(count=max_stories))
89 stories = self._event_handler.execQuery(q)
93 for story
in stories[
'articles'][
'results']:
95 st[
'title'] = story[
'title']
96 st[
'content'] = story[
'body']
97 st[
'publisher'] = story[
'source'][
'title']
98 st[
'publishedDate'] = story[
'date']
99 st[
'url'] = story[
'url']
100 final_stories.append(st)
EventRegistry news engine hndler.
Base class for news engines.
def fetch_news
Fetch the news.