/
suggestive_chatbot.py
80 lines (69 loc) · 2.23 KB
/
suggestive_chatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import googleMapsApiModule
import logging
import logger_config
log = logging.getLogger(__name__)
log.info("Entered module: %s" % __name__)
@logger_config.logger
def directions_suggestion(origin_text, destination_text):
"""Get Directions."""
try:
bot_response = googleMapsApiModule.direction(origin_text, destination_text)
except Exception as e:
logging.debug(e)
return None
logging.debug(bot_response)
return bot_response
@logger_config.logger
def geocoding_suggestion(location_text):
"""Find a place."""
try:
bot_response = googleMapsApiModule.geocoding(location_text)
except Exception as e:
logging.debug(e)
return None
logging.debug(bot_response)
return bot_response
@logger_config.logger
def timezone_suggestion(location_text, tz_option="time"):
"""Get time / Get timezone."""
try:
timezone_name, time_in_tz = googleMapsApiModule.timezone(location_text)
except Exception as e:
logging.debug(e)
return None
if tz_option == "timezone":
logging.debug(timezone_name)
return timezone_name
if tz_option == "time":
logging.debug(time_in_tz)
return time_in_tz
@logger_config.logger
def elevation_suggestion(location_text, location_comp_text=None):
"""Find elevation of a place."""
try:
location_elev = googleMapsApiModule.elevation(location_text)
except Exception as e:
logging.debug(e)
return None
if location_comp_text:
try:
location_comp_elev = googleMapsApiModule.elevation(location_comp_text)
except Exception as e:
logging.debug(e)
return None
logging.debug(location_elev, location_comp_elev)
return (
str(float(location_elev[:-6]) - float(location_comp_elev[:-6])) + " metres"
)
logging.debug(location_elev)
return location_elev
@logger_config.logger
def mapsstatic_suggestion(location_text, **kwargs):
"""Map of someplace (**kwargs => zoom, size)."""
try:
bot_response = googleMapsApiModule.mapsstatic(location_text, **kwargs)
except Exception as e:
logging.debug(e)
return None
logging.debug(bot_response)
return bot_response