RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
RappPlatformApi.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
5 # Copyright 2015 RAPP
6 
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 
11  #http://www.apache.org/licenses/LICENSE-2.0
12 
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 
19 # Authors: Konstantinos Panayiotou, Manos Tsardoulias
20 # contact: klpanagi@gmail.com, etsardou@iti.gr
21 
22 
23 ## @file RappCloud/RappPlatformApi.py
24 #
25 # @copyright Rapp Project EU 2015
26 # @author Konstantinos Panayiotou, Manos Tsardoulias
27 #
28 
29 from CloudMsgs import FaceDetection
30 from CloudMsgs import QrDetection
31 from CloudMsgs import HumanDetection
32 from CloudMsgs import HazardDetectionDoor
33 from CloudMsgs import HazardDetectionLight
34 from CloudMsgs import ObjectRecognitionCaffe
35 from CloudMsgs import SetNoiseProfile
36 from CloudMsgs import SpeechRecognitionSphinx
37 from CloudMsgs import SpeechRecognitionGoogle
38 from CloudMsgs import OntologySubclasses
39 from CloudMsgs import OntologySuperclasses
40 from CloudMsgs import OntologyIsSubsuperclass
41 from CloudMsgs import CognitiveExerciseSelect
42 from CloudMsgs import CognitiveGetHistory
43 from CloudMsgs import CognitiveGetScores
44 from CloudMsgs import CognitiveRecordPerformance
45 from CloudMsgs import EmailFetch
46 from CloudMsgs import EmailSend
47 from CloudMsgs import WeatherReportCurrent
48 from CloudMsgs import WeatherReportForecast
49 from CloudMsgs import PathPlanningPlan2D
50 from CloudMsgs import PathPlanningUploadMap
51 from CloudMsgs import TextToSpeech
52 from CloudMsgs import NewsExplore
53 from CloudMsgs import Geolocation
54 
55 from Service import RappPlatformService
56 
58  """ RAPP Platform simple API implementation """
59  def __init__(self):
60  self.svc_caller = RappPlatformService()
61 
62  def faceDetection(self, imageFilepath, fast = False):
63  """! Face detection API service call.
64 
65  @type imageFilepath: string
66  @param imageFilepath: Path to the image file.
67 
68  @type fast: bool
69  @param fast: Perform fast detection. If true, detection will take
70  less time but it will be less accurate.
71 
72  @rtype: dict
73  @return: Returns a dictionary of the service call response.
74  {'faces': [], 'error': ''}
75  """
76  msg = FaceDetection()
77  try:
78  msg.req.imageFilepath = imageFilepath
79  response = self.svc_caller.call(msg)
80  except Exception as e:
81  response = FaceDetection.Response(error=str(e))
82  return {
83  'faces': response.faces,
84  'error': response.error
85  }
86 
87  def qrDetection(self, imageFilepath):
88  """! QR code detection API service call.
89 
90  @type imageFilepath: string
91  @param imageFilepath: Path to the image file.
92 
93  @rtype: dict
94  @return: Returns a dictionary of the service call response.
95  {'qr_centers': [], 'qr_messages': [], 'error': ''}
96  """
97  msg = QrDetection()
98  try:
99  msg.req.imageFilepath = imageFilepath
100  response = self.svc_caller.call(msg)
101  except Exception as e:
102  response = QrDetection.Response(error=str(e))
103  return {
104  'qr_centers': response.qr_centers,
105  'qr_messages': response.qr_messages,
106  'error': response.error
107  }
108 
109  def humanDetection(self, imageFilepath):
110  """! Human detection API service call.
111 
112  @type imageFilepath: string
113  @param imageFilepath: Path to the image file.
114 
115  @rtype: dict
116  @return: Returns a dictionary of the service call response.
117  {'humans': [], 'error': ''}
118  """
119 
120  msg = HumanDetection()
121  try:
122  msg.req.imageFilepath = imageFilepath
123  response = self.svc_caller.call(msg)
124  except Exception as e:
125  response = HumanDetection.Response(error=str(e))
126  return {
127  'humans': response.humans,
128  'error': response.error
129  }
130 
131  def hazardDetectionDoor(self, imageFilepath):
132  """! Hazard detection door check API service call.
133 
134  @type imageFilepath: string
135  @param imageFilepath: Path to the image file.
136 
137  @rtype: dict
138  @return: Returns a dictionary of the service call response.
139  {'door_angle': 0.0, 'error': ''}
140  """
141  msg = HazardDetectionDoor()
142  try:
143  msg.req.imageFilepath = imageFilepath
144  response = self.svc_caller.call(msg)
145  except Exception as e:
146  response = HazardDetectionDoor.Response(error=str(e))
147  return {
148  'door_angle': response.door_angle,\
149  'error': response.error\
150  }
151 
152  def hazardDetectionLights(self, imageFilepath):
153  """! Hazard detection light check API service call.
154 
155  @type imageFilepath: string
156  @param imageFilepath: Path to the image file.
157 
158  @rtype: dict
159  @return: Returns a dictionary of the service call response.
160  {'light_level': 0, 'error': ''}
161  """
162  msg = HazardDetectionLight()
163  try:
164  msg.req.imageFilepath = imageFilepath
165  response = self.svc_caller.call(msg)
166  except Exception as e:
167  response = HazardDetectionLight.Response(error=str(e))
168  return {
169  'light_level': response.light_level,
170  'error': response.error
171  }
172 
173  def objectRecognitionCaffe(self, imageFilepath):
174  """! Object Recognition Caffe API service call.
175 
176  @type imageFilepath: string
177  @param imageFilepath: Path to the image file.
178 
179  @rtype: dict
180  @return: Returns a dictionary of the service call response.
181  {'object_class': '', 'error': ''}
182  """
183  msg = ObjectRecognitionCaffe()
184  try:
185  msg.req.imageFilepath = imageFilepath
186  response = self.svc_caller.call(msg)
187  except Exception as e:
188  response = ObjectRecognitionCaffe.Response(error=str(e))
189  return {
190  'object_class': response.object_class,
191  'error': response.error
192  }
193 
194  def setNoiseProfile(self, audiofile, audio_source):
195  """! Set Noise Profile API service call.
196 
197  @type audiofile: string
198  @param audiofile: Path to the audio file.
199 
200  @type audio_source: string
201  @param audio_source: Audio source format. e.g. 'nao_wav_1_ch'
202 
203  @rtype: dict
204  @return: Returns a dictionary of the service call response.
205  {'error': ''}
206  """
207  msg = SetNoiseProfile()
208  try:
209  msg.req.audiofile = audiofile
210  msg.req.audio_source = audio_source
211  response = self.svc_caller.call(msg)
212  except Exception as e:
213  response = SetNoiseProfile.Response(error=str(e))
214  return {
215  'error': response.error
216  }
217 
218  def speechRecognitionSphinx(self, audiofile, audio_source, language, words,
219  sentences=[], grammar=[]):
220  """! Speech recognition Sphinx API service call.
221 
222  @type audiofile: string
223  @param audiofile: Path to the audio file.
224 
225  @type audio_source: string
226  @param audio_source: Audio source format. e.g. 'nao_wav_1_ch'
227 
228  @type language: string
229  @param language: Language to use for speech recognition.
230 
231  @type words: list
232  @param words: To recognize words.
233 
234  @type sentences: list
235  @param sentences: Under consideration sentences. Same as
236  @ref words by default.
237 
238  @type grammar: list
239  @param grammar: Grammar to use. Defaults to none.
240 
241  @rtype: dict
242  @return: Returns a dictionary of the service call response.
243  {'words': [], 'error': ''}
244  """
245  msg = SpeechRecognitionSphinx()
246  try:
247  msg.req.audiofile = audiofile
248  msg.req.audio_source = audio_source
249  msg.req.language = language
250  msg.req.words = words
251  msg.req.sentences = sentences
252  if sentences == []:
253  msg.req.sentences = words
254  msg.req.grammar = grammar
255  response = self.svc_caller.call(msg)
256  except Exception as e:
257  response = SpeechRecognitionSphinx.Response(error=str(e))
258  return {
259  'words': response.words,
260  'error': response.error
261  }
262 
263  def speechRecognitionGoogle(self, audiofile, audio_source, language):
264  """! Speech recognition Google API service call.
265 
266  @type audiofile: string
267  @param audiofile: Path to the audio file.
268 
269  @type audio_source: string
270  @param audio_source: Audio source format. e.g. 'nao_wav_1_ch'
271 
272  @type language: string
273  @param language: Language to use for speech recognition.
274 
275  @rtype: dict
276  @return: Returns a dictionary of the service call response.
277  {'words': [], 'alternatives': [], 'error': ''}
278  """
279  msg = SpeechRecognitionGoogle()
280  try:
281  msg.req.audiofile = audiofile
282  msg.req.audio_source = audio_source
283  msg.req.language = language
284  response = self.svc_caller.call(msg)
285  except Exception as e:
286  response = SpeechRecognitionGoogle.Response(error=str(e))
287  return {
288  'words': response.words,
289  'alternatives': response.alternatives,
290  'error': response.error
291  }
292 
293  def ontologySubclasses(self, ontology_class, recursive=False):
294  """! Ontology subclasses-of API service call.
295 
296  @type ontology_class: string
297  @param ontology_class: The ontology class.
298 
299  @type recursive: bool
300  @param recursive: Recursive search. Defaults to False.
301 
302  @rtype: dict
303  @return: Returns a dictionary of the service call response.
304  {'results': [], 'error': ''}
305  """
306  msg = OntologySubclasses()
307  try:
308  msg.req.ontology_class = ontology_class
309  msg.req.recursive = recursive
310  response = self.svc_caller.call(msg)
311  except Exception as e:
312  response = OntologySubclasses.Response(error=str(e))
313  return {
314  'results': response.results,
315  'error': response.error
316  }
317 
318  def ontologySuperclasses(self, ontology_class, recursive=False):
319  """! Ontology superclasses-of API service call.
320 
321  @type ontology_class: string
322  @param ontology_class: The ontology class.
323 
324  @type recursive: bool
325  @param recursive: Recursive search. Defaults to False.
326 
327  @rtype: dict
328  @return: Returns a dictionary of the service call response.
329  {'results': [], 'error': ''}
330  """
331  msg = OntologySuperclasses()
332  try:
333  msg.req.ontology_class = ontology_class
334  msg.req.recursive = recursive
335  response = self.svc_caller.call(msg)
336  except Exception as e:
337  response = OntologySuperclasses.Response(error=str(e))
338  return {
339  'results': response.results,
340  'error': response.error
341  }
342 
343  def ontologyIsSubsuperclass(self, parent_class, child_class, recursive=False):
344  """! Ontology is-supsuperclass-of API service call.
345 
346  @type parent_class: string
347  @param parent_class: The ontology parent class name.
348 
349  @type child_class: string
350  @param child_class: The ontology child class name.
351 
352  @type recursive: bool
353  @param recursive: Recursive search. Defaults to False.
354 
355  @rtype: dict
356  @return: Returns a dictionary of the service call response.
357  {'result': False, 'error': ''}
358  """
359  msg = OntologyIsSubsuperclass()
360  try:
361  msg.req.parent_class = parent_class
362  msg.req.child_class = child_class
363  msg.req.recursive = recursive
364  response = self.svc_caller.call(msg)
365  except Exception as e:
366  response = OntologyIsSubsuperclass.Response(error=str(e))
367  return {
368  'result': response.result,
369  'error': response.error
370  }
371 
372  def cognitiveExerciseSelect(self, test_type='', test_subtype='',
373  test_diff=-1, test_index=-1):
374  """! Cognitive Exercise selection (chooser) API service call.
375 
376  @type test_type: string
377  @param test_type: Cognitive Exercise test type. Defaults to empty.
378 
379  @type test_subtype: string
380  @param test_subtype: Force exercise selection from this subtype.
381  Defaults to empty.
382 
383  @type test_diff: int
384  @param test_diff: Force exercise selection from this difficulty.
385  Defaults to empty.
386 
387  @type test_index: int
388  @param test_diff: Force exercise selection from this difficulty.
389  Defaults to empty.
390 
391  @rtype: dict
392  @return: Returns a dictionary of the service call response.
393  """
394  msg = CognitiveExerciseSelect()
395  try:
396  msg.req.test_type = test_type
397  msg.req.test_subtype = test_subtype
398  if test_diff != -1:
399  msg.req.test_diff = test_diff
400  if test_index != -1:
401  msg.req.test_index = test_index
402  response = self.svc_caller.call(msg)
403  except Exception as e:
404  response = CognitiveExerciseSelect.Response(error=str(e))
405  return {
406  'test_type': response.test_type,
407  'test_subtype': response.test_subtype,
408  'test_instance': response.test_instance,
409  'questions': response.questions,
410  'possib_ans': response.possib_ans,
411  'correct_ans': response.correct_ans,
412  'error': response.error
413  }
414 
415  def cognitiveGetHistory(self, test_type='', time_from=0, time_to=0):
416  """! Gognitive get history records API service call.
417 
418  @type test_type: string
419  @param test_type: Cognitive Exercise test type. Defaults to empty.
420 
421  @type time_from: int
422  @param time_from: Retrieve history records from this timestamp value.
423  Unix timestamp. Defaults to zero (0).
424 
425  @type time_to: int
426  @param time_from: Retrieve history records up to this timestamp value.
427  Unix timestamp. Defaults to zero (0).
428 
429  @rtype: dict
430  @return: Returns a dictionary of the service call response.
431  {'records': {}, 'error': ''}
432  """
433  msg = CognitiveGetHistory()
434  try:
435  msg.req.test_type = test_type
436  msg.req.time_from = time_from
437  msg.req.time_to = time_to
438  response = self.svc_caller.call(msg)
439  except Exception as e:
440  response = CognitiveGetHistory.Response(error=str(e))
441  return {
442  'records': response.records,
443  'error': response.error
444  }
445 
446  def cognitiveGetScores(self, test_type='' , time_to=0):
447  """! Gognitive get score records API service call.
448 
449  @type test_type: string
450  @param test_type: Cognitive Exercise test type. Defaults to empty.
451 
452  @type time_to: int
453  @param time_from: Retrieve score records up to this timestamp value.
454  Unix timestamp. Defaults to zero (0).
455 
456  @rtype: dict
457  @return: Returns a dictionary of the service call response.
458  {'test_classes': [], 'scores': [], 'error': ''}
459  """
460  msg = CognitiveGetScores()
461  try:
462  msg.req.test_type = test_type
463  msg.req.time_to = time_to
464  response = self.svc_caller.call(msg)
465  except Exception as e:
466  response = CognitiveGetScores.Response(error=str(e))
467  return {
468  'test_classes': response.test_classes,
469  'scores': response.scores,
470  'error': response.error
471  }
472 
473  def cognitiveRecordPerformance(self, test_instance, score):
474  """! Gognitive record performance of an exercise API service call.
475 
476  @type test_instance: string
477  @param test_instance: Performed cognitive exercise test instance.
478  The full cognitive test entry name as obtained from
479  CognitiveExerciseSelect API service call
480 
481  @rtype: dict
482  @return: Returns a dictionary of the service call response.
483  {'performance_entry': '', 'error': ''}
484  """
485  msg = CognitiveRecordPerformance()
486  try:
487  msg.req.test_instance = test_instance
488  msg.req.score = score
489  response = self.svc_caller.call(msg)
490  except Exception as e:
491  response = CognitiveRecordPerformance.Response(error=str(e))
492  return {
493  'performance_entry': response.performance_entry,
494  'error': response.error
495  }
496 
497  def emailFetch(self, email, password, server, port, date_from, date_to,
498  email_status='UNSEEN', num_emails=1):
499  """! Email fetch API service call.
500 
501  @type email: string
502  @param email: User's email username
503 
504  @type password: string
505  @param password: User's email password
506 
507  @type server: string
508  @param server: The email provider imap address.
509 
510  @type port: string
511  @param port: The email provider imap port.
512 
513  @type date_from: int
514  @param date_from: Fetch emails since this timestamp value.
515  Unix timestamp.
516 
517  @type date_to: int
518  @param date_to: Fetch emails up to this timestamp value.
519  Unix timestamp.
520 
521  @type email_status: string
522  @param email_status: Email status (ALL, UNSEEN). Defaults to 'UNSEEN'
523 
524  @type num_emails: int
525  @param num_emails: Maximum number of emails to fetch.
526 
527  @rtype: dict
528  @return: Returns a dictionary of the service call response.
529  {'emails': [], 'error': ''}
530  """
531  msg = EmailFetch()
532  try:
533  msg.req.email = email
534  msg.req.password = password
535  msg.req.server = server
536  msg.req.port = port
537  msg.req.date_from = date_from
538  msg.req.date_to = date_to
539  msg.req.email_status = email_status
540  msg.req.num_emails = num_emails
541  response = self.svc_caller.call(msg)
542  except Exception as e:
543  response = EmailFetch.Response(error=str(e))
544  return {
545  'emails': response.emails,
546  'error': response.error
547  }
548 
549  def emailSend(self, email, password, server, port, recipients, body,
550  subject, attach_file=''):
551  """! Email fetch API service call.
552 
553  @type email: string
554  @param email: User's email username
555 
556  @type password: string
557  @param password: User's email password
558 
559  @type server: string
560  @param server: The email provider imap address.
561 
562  @type port: string
563  @param port: The email provider imap port.
564 
565  @type recipients: list
566  @param recipients: List of recipients email addresses.
567 
568  @type body: string
569  @param body: The body of the email.
570 
571  @type subject: string
572  @param subject: The email subject.
573 
574  @type attach_file: string
575  @param attach_file: Attachment file (path). Attachment file can be a
576  .zip file containing multiple attachment files for the email to send
577 
578  @rtype: dict
579  @return: Returns a dictionary of the service call response.
580  {'error': ''}
581  """
582  msg = EmailSend()
583  try:
584  msg.req.email = email
585  msg.req.password = password
586  msg.req.server = server
587  msg.req.port = port
588  msg.req.recipients = recipients
589  msg.req.body = body
590  msg.req.subject = subject
591  msg.req.attach_file = attach_file
592  response = self.svc_caller.call(msg)
593  except Exception as e:
594  response = EmailSend.Response(error=str(e))
595  return {
596  'error': response.error
597  }
598 
599  def weatherReportCurrent(self, city, weather_reporter='forecast.io',
600  metric=0):
601  """! Weather report current API service call
602 
603  @type city: string
604  @param city: City location.
605 
606  @type weather_reporter: string
607  @param weather_reporter: The weather reporter API to use.
608  Defaults to 'forecast.io'
609 
610  @type metric: int
611  @param metric: Value units (0:Celcius, 1:Fahrenheit)
612  Defaults to 0 (Celcius)
613 
614  @rtype: dict
615  @return: Returns a dictionary of the service call response.
616  """
617  msg = WeatherReportCurrent()
618  try:
619  msg.req.city = city
620  msg.req.weather_reporter = weather_reporter
621  msg.req.metric = metric
622  response = self.svc_caller.call(msg)
623  except Exception as e:
624  response = WeatherReportCurrent.Response(error=str(e))
625  return {
626  'date': response.date,
627  'temperature': response.temperature,
628  'weather_description': response.weather_description,
629  'humidity': response.humidity,
630  'visibility': response.visibility,
631  'pressure': response.pressure,
632  'wind_speed': response.wind_speed,
633  'wind_temperature': response.wind_temperature,
634  'wind_direction': response.wind_direction,
635  'error': response.error
636  }
637 
638  def weatherReportForecast(self, city, weather_reporter='forecast.io',
639  metric=0):
640  """! Weather report forecast API service call
641 
642  @type city: string
643  @param city: City location.
644 
645  @type weather_reporter: string
646  @param weather_reporter: The weather reporter API to use.
647  Defaults to 'forecast.io'
648 
649  @type metric: int
650  @param metric: Value units (0:Celcius, 1:Fahrenheit)
651  Defaults to 0 (Celcius)
652 
653  @rtype: dict
654  @return: Returns a dictionary of the service call response.
655  """
656  msg = WeatherReportForecast()
657  try:
658  msg.req.city = city
659  msg.req.weather_reporter = weather_reporter
660  msg.req.metric = metric
661  response = self.svc_caller.call(msg)
662  except Exception as e:
663  response = WeatherReportForecast.Response(error=str(e))
664  return {
665  'forecast': response.forecast,
666  'error': response.error
667  }
668 
669  def pathPlanningPlan2D(self, map_name, robot_type, pose_start,
670  pose_goal, algorithm='dijkstra'):
671  """! Path planning plan path 2D API service call
672 
673  @type map_name: string
674  @param map_name: The map name.
675 
676  @type robot_type: string
677  @param robot_type: The robot type. e.g 'NAO'
678 
679  @type pose_start: dict
680  @param pose_start: Start pose of the robot.
681 
682  @type pose_goal: dict
683  @param pose_goal: Goal pose of the robot.
684 
685  @type algorithm: string
686  @param algorithm: Path planning algorithm to apply.
687  Defaults to 'dijkstra'
688 
689  @rtype: dict
690  @return: Returns a dictionary of the service call response.
691  {'plan_found': 0, 'path': [], 'error': ''}
692  """
693 
694  msg = PathPlanningPlan2D()
695  try:
696  msg.req.map_name = map_name
697  msg.req.robot_type = robot_type
698  msg.req.algorithm = algorithm
699  msg.req.pose_start = pose_start
700  msg.req.pose_goal = pose_goal
701  response = self.svc_caller.call(msg)
702  except Exception as e:
703  response = PathPlanningPlan2D.Response(error=str(e))
704  return {
705  'plan_found': response.plan_found,
706  'path': response.path,
707  'error': response.error
708  }
709 
710  def pathPlanningUploadMap(self, map_name, png_file, yaml_file):
711  """! Path planning upload map API service call
712 
713  @type map_name: string
714  @param map_name: The map name
715 
716  @type png_file: string
717  @param png_file: Path to the map png file
718 
719  @type yaml_file: string
720  @param yaml_file: Path to the map descriptor yaml file.
721 
722  @rtype: dict
723  @return: Returns a dictionary of the service call response.
724  {'error': ''}
725  """
726  msg = PathPlanningUploadMap()
727  try:
728  msg.req.map_name = map_name
729  msg.req.png_file = png_file
730  msg.req.yaml_file = yaml_file
731  response = self.svc_caller.call(msg)
732  except Exception as e:
733  response = PathPlanningUploadMap.Response(error=str(e))
734  return {
735  'error': response.error
736  }
737 
738  def textToSpeech(self, text, language, audio_file):
739  """! Text to Speech API service call
740 
741  @type text: string
742  @param text: Input text to translate to audio.
743 
744  @type language: string
745  @param language: Text language.
746 
747  @type audio_file: string
748  @param audio_file: File path to store the audio data.
749 
750  @rtype: dict
751  @return: Returns a dictionary of the service call response.
752  {'error': ''}
753  """
754  msg = TextToSpeech()
755  try:
756  msg.req.text = text
757  msg.req.language = language
758  response = self.svc_caller.call(msg)
759 
760  if response.error == u"":
761  response.store_audio(audio_file)
762  except Exception as e:
763  response = TextToSpeech.Response(error=str(e))
764  return {
765  'error': response.error
766  }
767 
768  def newsExplore(self, keywords, region='', topic='', news_engine='',
769  num_news=1, exclude_titles=[]):
770  """! News Explorer API service call
771 
772  @type keywords: list
773  @param keywords: Desired keywords.
774 
775  @type region: string
776  @param region: language/region
777 
778  @type topic: string
779  @param topic: Main topic. e.g. 'sports', 'politics', etc
780 
781  @type news_engine: string
782  @param news_engine: The news search engine to use. Optional
783 
784  @type num_news: string
785  @param num_news: Number of news stories to request.
786 
787  @type exclude_titles: list
788  @param exclude_titles: Exclude these titles
789 
790  @rtype: dict
791  @return: Returns a dictionary of the service call response.
792  {'news_stories': [], 'error': ''}
793  """
794  msg = NewsExplore()
795  try:
796  msg.req.news_engine = news_engine
797  msg.req.keywords = keywords
798  msg.req.exclude_titles = exclude_titles
799  msg.req.region = region
800  msg.req.topic = topic
801  msg.req.num_news = num_news
802  response = self.svc_caller.call(msg)
803  except Exception as e:
804  response = NewsExplore.Response(error=str(e))
805  return {
806  'news_stories': response.news_stories,
807  'error': response.error
808  }
809 
810  def geolocation(self, ipaddr, engine='ip-api'):
811  """! Geolocation API service call
812 
813  @type ipaddr: string
814  @param ipaddr: The machine's ipv4 address.
815 
816  @type engine: string
817  @param engine: Engine to use. Defaults to 'ip-api'.
818 
819  @rtype: dict
820  @return: Returns a dictionary of the service call response.
821  """
822  msg = Geolocation()
823  try:
824  msg.req.ipaddr = ipaddr
825  msg.req.engine = engine
826  response = self.svc_caller.call(msg)
827  except Exception as e:
828  response = Geolocation.Response(error=str(e))
829  return {
830  'city': response.city,
831  'country': response.country,
832  'country_code': response.country_code,
833  'latitude': response.latitude,
834  'longtitude': response.longtitude,
835  'region': response.region,
836  'timezone': response.timezone,
837  'zip': response.zip,
838  'error': response.error
839  }
def cognitiveRecordPerformance
Gognitive record performance of an exercise API service call.
def ontologySubclasses
Ontology subclasses-of API service call.
def cognitiveExerciseSelect
Cognitive Exercise selection (chooser) API service call.
def geolocation
Geolocation API service call.
def ontologySuperclasses
Ontology superclasses-of API service call.
def speechRecognitionGoogle
Speech recognition Google API service call.
def humanDetection
Human detection API service call.
def objectRecognitionCaffe
Object Recognition Caffe API service call.
def weatherReportCurrent
Weather report current API service call.
def hazardDetectionDoor
Hazard detection door check API service call.
def newsExplore
News Explorer API service call.
def cognitiveGetHistory
Gognitive get history records API service call.
def pathPlanningPlan2D
Path planning plan path 2D API service call.
def cognitiveGetScores
Gognitive get score records API service call.
def speechRecognitionSphinx
Speech recognition Sphinx API service call.
def emailSend
Email fetch API service call.
def ontologyIsSubsuperclass
Ontology is-supsuperclass-of API service call.
def hazardDetectionLights
Hazard detection light check API service call.
def pathPlanningUploadMap
Path planning upload map API service call.
def weatherReportForecast
Weather report forecast API service call.
def setNoiseProfile
Set Noise Profile API service call.
def faceDetection
Face detection API service call.
def textToSpeech
Text to Speech API service call.
def qrDetection
QR code detection API service call.
def emailFetch
Email fetch API service call.