25 from rapp_utilities
import RappUtilities
26 from rapp_exceptions
import RappError
28 from rapp_platform_ros_communications.msg
import NewsStoryMsg
30 from rapp_platform_ros_communications.srv
import (
32 NewsExplorerSrvResponse
45 if rospy.has_param(
'rapp_news_explorer_fetch_news_topic'):
47 rospy.get_param(
"rapp_news_explorer_fetch_news_topic")
50 RappUtilities.rapp_print(
'Fetch News topic not found!',
'ERROR')
52 fetch_service = rospy.Service(
66 response = NewsExplorerSrvResponse()
69 engine = self._engine_factory.select_news_engine(req.newsEngine)
70 except RappError
as err:
71 response.error = str(err)
74 results = engine.fetch_news(req)
75 except RappError
as err:
76 response.error = str(err)
89 response = NewsExplorerSrvResponse()
90 for result
in results:
92 msg.title = result[
'title']
93 msg.content = result[
'content']
94 msg.publisher = result[
'publisher']
95 msg.publishedDate = result[
'publishedDate']
96 msg.url = result[
'url']
97 response.stories.append(msg)
101 if __name__ ==
"__main__":
102 rospy.init_node(
'NewsExplorer')
104 RappUtilities.rapp_print(
"News Explorer node initialized")
Fetches news from various News sites' APIs.
def _create_service_response
The callback to fetch news.
_engine_factory
Factory that returns proper news engine.
def fetch_news_srv_callback
The callback to fetch news.
Creates and returns the class of the news engine requested.